narendly commented on a change in pull request #1494:
URL: https://github.com/apache/helix/pull/1494#discussion_r514898152
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -2061,4 +2069,43 @@ public ZKHelixAdmin build() {
_zkAddress), false);
}
}
+
+ private Map<String, InstanceConfig> findTimeoutOfflineInstances(String
clusterName,
+ Long timeout) {
+ Map<String, InstanceConfig> instanceConfigMap = new HashMap<>();
+ // in case there is no customized timeout value, use the one defined in
cluster config
+ if (timeout == null) {
+ timeout =
_configAccessor.getClusterConfig(clusterName).getOfflineNodeTimeOutForPurge();
+ }
+ if (timeout < 0) {
+ return instanceConfigMap;
+ }
+
+ String path = PropertyPathBuilder.instanceConfig(clusterName);
+ BaseDataAccessor<ZNRecord> baseAccessor = new
ZkBaseDataAccessor<>(_zkClient);
+ List<ZNRecord> znRecords = baseAccessor.getChildren(path, null, 0, 0, 0);
+ for (ZNRecord record : znRecords) {
+ if (record != null) {
+ InstanceConfig instanceConfig = new InstanceConfig(record);
+ instanceConfigMap.put(instanceConfig.getInstanceName(),
instanceConfig);
+ }
+ }
+
+ path = PropertyPathBuilder.liveInstance(clusterName);
+ List<String> liveNodes = baseAccessor.getChildNames(path, 0);
+ instanceConfigMap.keySet().removeAll(liveNodes);
+
+ Set<String> toRemoveInstances = new HashSet<>();
+ for (String instanceName : instanceConfigMap.keySet()) {
+ String historyPath = PropertyPathBuilder.instanceHistory(clusterName,
instanceName);
+ ZNRecord znRecord = baseAccessor.get(historyPath, null, 0);
+ ParticipantHistory participantHistory = new ParticipantHistory(znRecord);
+ long lastOfflineTime = participantHistory.getLastOfflineTime();
+ if (lastOfflineTime == -1 || System.currentTimeMillis() -
lastOfflineTime < timeout) {
+ toRemoveInstances.add(instanceName);
+ }
+ }
+ instanceConfigMap.keySet().removeAll(toRemoveInstances);
+ return instanceConfigMap;
Review comment:
nit: is there a strong reason we're using a `BaseDataAccessor` instance
here? for helix-related i/o, it is better taste to use `HelixDataAccessor`
because you can avoid having to cast it to helix data model from znrecord.
that way, code will be cleaner and easier to read, shorter, and more concise.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]