Search in sources :

Example 1 with KeeperActiveElectAlgorithm

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);
}
Also used : KeeperActiveElectAlgorithm(com.ctrip.xpipe.redis.meta.server.keeper.KeeperActiveElectAlgorithm) ArrayList(java.util.ArrayList) ChildData(org.apache.curator.framework.recipes.cache.ChildData) LinkedList(java.util.LinkedList) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Aggregations

KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)1 KeeperActiveElectAlgorithm (com.ctrip.xpipe.redis.meta.server.keeper.KeeperActiveElectAlgorithm)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ChildData (org.apache.curator.framework.recipes.cache.ChildData)1