Skip to content

Commit

Permalink
Remove the code that removes resources and partitions in the helix tool
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlin-linkedin committed Oct 11, 2023
1 parent df393bd commit c1eb156
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,7 @@ private void addUpdateResources(String dcName, Map<String, Set<String>> partitio
TreeMap<Integer, Set<String>> resourceIdToInstances = dcToResourceIdToInstances.get(dcName);
Map<String, Set<Integer>> instanceNameToResources = dcToInstanceToResourceIds.get(dcName);
Map<Integer, IdealState> resourceIdToIdealState = dcToResourceIdToIdealState.get(dcName);
Map<String, Integer> partitionToResourceId = dcToPartitionToResourceId.get(dcName);
// maxResource may vary from one dc to another (special partition class allows partitions to exist in one dc only)
int maxResource = -1;
for (int resourceId : new ArrayList<>(resourceIdToIdealState.keySet())) {
Expand All @@ -1995,7 +1996,16 @@ private void addUpdateResources(String dcName, Map<String, Set<String>> partitio
Set<String> instanceSetInHelix = resourceIs.getInstanceSet(partitionName);
Set<String> instanceSetInStatic = partitionsToInstancesInDc.remove(partitionName);
if (instanceSetInStatic == null || instanceSetInStatic.isEmpty()) {
resourceIdToInstances.remove(resourceId);
info(
"[{}] No instance set in static clustermap for partition {}, but will not remove this partition from resource. To remove partition, please use helix API",
dcName.toUpperCase(), partitionName);
expectMoreInHelixDuringValidate = true;
partitionsNotForceRemovedByDc.computeIfAbsent(dcName, k -> ConcurrentHashMap.newKeySet()).add(partitionName);
if (partitionToResourceId.get(partitionName) == resourceId) {
info("[{}] Remove partition to resource id for partition {} and resource id{}", dcName.toUpperCase(),
partitionName, resourceId);
partitionToResourceId.remove(partitionName);
}
} else if (!instanceSetInStatic.equals(instanceSetInHelix)) {
// we change the IdealState only when the operation is meant to bootstrap cluster or indeed update IdealState
if (EnumSet.of(HelixAdminOperation.UpdateIdealState, HelixAdminOperation.BootstrapCluster)
Expand Down Expand Up @@ -2074,10 +2084,11 @@ private void addUpdateResources(String dcName, Map<String, Set<String>> partitio
resourceIs.setNumPartitions(resourceIs.getPartitionSet().size());
if (resourceModified) {
if (resourceIs.getPartitionSet().isEmpty()) {
info("[{}] Resource {} has no partition, {}", dcName.toUpperCase(), resourceId,
dryRun ? "no action as dry run" : "dropping");
info("[{}] Resource {} has no partition, to remove this resource, please use helix API", dcName.toUpperCase(),
resourceId);
resourceIdToIdealState.remove(resourceId);
resourceIdToInstances.remove(resourceId);
expectMoreInHelixDuringValidate = true;
} else {
if (!dryRun) {
dcAdmin.setResourceIdealState(clusterName, String.valueOf(resourceId), resourceIs);
Expand Down Expand Up @@ -2728,7 +2739,7 @@ private void verifyDataNodeAndDiskEquivalencyInDc(Datacenter dc, String clusterN
* @return
*/
Map<Integer, IdealState> getIdealStateForAllResource(HelixAdmin admin, String dcName) {
Map<Integer, IdealState> allIdealStates = new HashMap<>();
Map<Integer, IdealState> allIdealStates = new TreeMap<>();
for (String resourceName : admin.getResourcesInCluster(clusterName)) {
if (!resourceName.matches("\\d+")) {
info("[{}] Ignoring resource {} as it is not part of the cluster map", dcName.toUpperCase(), resourceName);
Expand Down

0 comments on commit c1eb156

Please sign in to comment.