Skip to content

Commit

Permalink
Not overwrite the whole SystemResourceInfo config map (#8820)
Browse files Browse the repository at this point in the history
  • Loading branch information
mqliang committed Jun 3, 2022
1 parent 7620fae commit 7b9e16b
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,21 @@ private void updateInstanceConfigIfNeeded(ServerConf serverConf) {
}

// Update system resource info (CPU, memory, etc)
Map<String, String> systemResourceInfoMap = new SystemResourceInfo().toMap();
if (!systemResourceInfoMap.equals(znRecord.getMapField(Instance.SYSTEM_RESOURCE_INFO_KEY))) {
LOGGER.info("Updating instance: {} with system resource info: {}", _instanceId, systemResourceInfoMap);
znRecord.setMapField(Instance.SYSTEM_RESOURCE_INFO_KEY, systemResourceInfoMap);
Map<String, String> newSystemResourceInfoMap = new SystemResourceInfo().toMap();
Map<String, String> existingSystemResourceInfoMap =
znRecord.getMapField(CommonConstants.Helix.Instance.SYSTEM_RESOURCE_INFO_KEY);
if (!newSystemResourceInfoMap.equals(existingSystemResourceInfoMap)) {
LOGGER.info("Updating instance: {} with new system resource info: {}", _instanceId, newSystemResourceInfoMap);
if (existingSystemResourceInfoMap == null) {
existingSystemResourceInfoMap = newSystemResourceInfoMap;
} else {
// existingSystemResourceInfoMap may contains more KV pairs than newSystemResourceInfoMap,
// we need to preserve those KV pairs and only update the different values.
for (Map.Entry<String, String> entry : newSystemResourceInfoMap.entrySet()) {
existingSystemResourceInfoMap.put(entry.getKey(), entry.getValue());
}
}
znRecord.setMapField(Instance.SYSTEM_RESOURCE_INFO_KEY, existingSystemResourceInfoMap);
updated = true;
}

Expand Down

0 comments on commit 7b9e16b

Please sign in to comment.