Source:
private boolean removeOldReplicaInfo(ReplicaId replicaId, InstanceConfig instanceConfig) { boolean removalResult = true; boolean replicaFound = false; String partitionName = replicaId.getPartitionId().toPathString(); Map<String, Map<String, String>> mountPathToDiskInfos = instanceConfig.getRecord().getMapFields(); Map<String, String> diskInfo = mountPathToDiskInfos.get(replicaId.getMountPath()); if (diskInfo != null) { String replicasStr = diskInfo.get(ClusterMapUtils.REPLICAS_STR); if (!replicasStr.isEmpty()) { String[] replicaInfos = replicasStr.split(ClusterMapUtils.REPLICAS_DELIM_STR); for (String replicaInfo : replicaInfos) { String[] infos = replicaInfo.split(ClusterMapUtils.REPLICAS_STR_SEPARATOR); if (infos[0].equals(partitionName)) { replicaFound = true; break; } } if (replicaFound) { StringBuilder newReplicasStrBuilder = new StringBuilder(); for (String replicaInfo : replicaInfos) { String[] infos = replicaInfo.split(ClusterMapUtils.REPLICAS_STR_SEPARATOR); if (!infos[0].equals(partitionName)) { newReplicasStrBuilder.append(replicaInfo).append(ClusterMapUtils.REPLICAS_DELIM_STR); } } diskInfo.put(ClusterMapUtils.REPLICAS_STR, newReplicasStrBuilder.toString()); mountPathToDiskInfos.put(replicaId.getMountPath(), diskInfo); instanceConfig.getRecord().setMapFields(mountPathToDiskInfos); logger.info("Updating config: in Helix by removing partition {}", instanceConfig, partitionName); removalResult = helixAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig); } } } if (!replicaFound) { logger.warn("Partition is not found on instance {}, skipping removing it from InstanceConfig in Helix.", partitionName, instanceName); } return removalResult; }

Target:
private boolean removeOldReplicaInfo(ReplicaId replicaId, InstanceConfig instanceConfig) { boolean removalResult = true; boolean replicaFound = false; String partitionName = replicaId.getPartitionId().toPathString(); Map<String, Map<String, String>> mountPathToDiskInfos = instanceConfig.getRecord().getMapFields(); Map<String, String> diskInfo = mountPathToDiskInfos.get(replicaId.getMountPath()); if (diskInfo != null) { String replicasStr = diskInfo.get(ClusterMapUtils.REPLICAS_STR); if (!replicasStr.isEmpty()) { List<String> replicaInfos = new ArrayList<>(Arrays.asList(replicasStr.split(ClusterMapUtils.REPLICAS_DELIM_STR))); replicaFound = replicaInfos.removeIf( info -> (info.split(ClusterMapUtils.REPLICAS_STR_SEPARATOR)[0]).equals(partitionName)); if (replicaFound) { StringBuilder newReplicasStrBuilder = new StringBuilder(); for (String replicaInfo : replicaInfos) { newReplicasStrBuilder.append(replicaInfo).append(ClusterMapUtils.REPLICAS_DELIM_STR); } diskInfo.put(ClusterMapUtils.REPLICAS_STR, newReplicasStrBuilder.toString()); mountPathToDiskInfos.put(replicaId.getMountPath(), diskInfo); instanceConfig.getRecord().setMapFields(mountPathToDiskInfos); logger.info("Updating config: in Helix by removing partition {}", instanceConfig, partitionName); removalResult = helixAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig); } } } if (!replicaFound) { logger.warn("Partition is not found on instance {}, skipping removing it from InstanceConfig in Helix.", partitionName, instanceName); } return removalResult; }