use of com.ctrip.xpipe.redis.meta.server.keeper.KeeperActiveElectAlgorithm in project x-pipe by ctripcorp.
the class DefaultKeeperElectorManager method updateShardLeader.
protected void updateShardLeader(String leaderLatchPath, List<ChildData> childrenData, String clusterId, String shardId) {
List<String> childrenPaths = new LinkedList<>();
childrenData.forEach(childData -> childrenPaths.add(childData.getPath()));
logger.info("[updateShardLeader]{}, {}, {}", clusterId, shardId, childrenPaths);
List<String> sortedChildren = LockInternals.getSortedChildren("latch-", sorter, childrenPaths);
List<KeeperMeta> survivalKeepers = new ArrayList<>(childrenData.size());
for (String path : sortedChildren) {
for (ChildData childData : childrenData) {
if (path.equals(childData.getPath())) {
String data = new String(childData.getData());
KeeperMeta keeper = JsonCodec.INSTANCE.decode(data, KeeperMeta.class);
survivalKeepers.add(keeper);
break;
}
}
}
if (survivalKeepers.size() != childrenData.size()) {
throw new IllegalStateException(String.format("[children data not equal with survival keepers]%s, %s", childrenData, survivalKeepers));
}
KeeperActiveElectAlgorithm klea = keeperActiveElectAlgorithmManager.get(clusterId, shardId);
KeeperMeta activeKeeper = klea.select(clusterId, shardId, survivalKeepers);
currentMetaManager.setSurviveKeepers(clusterId, shardId, survivalKeepers, activeKeeper);
}
Aggregations