Search in sources :

Example 16 with Shard

use of com.newcosoft.cache.Shard in project disgear by yangbutao.

the class ZookeeperController method waitForCoreNodeName.

private void waitForCoreNodeName(CollectionDesc descriptor) {
    int retryCount = 320;
    log.info("look for our core node name");
    while (retryCount-- > 0) {
        Map<String, Shard> slicesMap = zkStateReader.getClusterState().getSlicesMap(descriptor.getCollectionName());
        if (slicesMap != null) {
            for (Shard slice : slicesMap.values()) {
                for (Replica replica : slice.getReplicas()) {
                    String baseUrl = replica.getStr(ZkStateReader.BASE_URL_PROP);
                    String core = replica.getStr(ZkStateReader.CORE_NAME_PROP);
                    String msgBaseUrl = getBaseUrl();
                    String msgCore = descriptor.getCollectionName();
                    if (baseUrl.equals(msgBaseUrl) && core.equals(msgCore)) {
                        descriptor.setCoreNodeName(replica.getName());
                        return;
                    }
                }
            }
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : Shard(com.newcosoft.cache.Shard) Replica(com.newcosoft.cache.Replica)

Example 17 with Shard

use of com.newcosoft.cache.Shard in project disgear by yangbutao.

the class ClusterState method collectionFromObjects.

private static CacheCollection collectionFromObjects(String name, Map<String, Object> objs) {
    Map<String, Object> props;
    Map<String, Shard> slices;
    Map<String, Object> sliceObjs = (Map<String, Object>) objs.get(CacheCollection.SHARDS);
    if (sliceObjs == null) {
        slices = makeShards(objs);
        props = Collections.emptyMap();
    } else {
        slices = makeShards(sliceObjs);
        props = new HashMap<String, Object>(objs);
        objs.remove(CacheCollection.SHARDS);
    }
    Router router = Router.DEFAULT;
    return new CacheCollection(name, slices, props, router);
}
Also used : Router(com.newcosoft.cache.Router) Shard(com.newcosoft.cache.Shard) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CacheCollection(com.newcosoft.cache.CacheCollection)

Aggregations

Shard (com.newcosoft.cache.Shard)17 Replica (com.newcosoft.cache.Replica)12 CacheCollection (com.newcosoft.cache.CacheCollection)9 HashMap (java.util.HashMap)5 Range (com.newcosoft.cache.Range)4 ClusterState (com.newcosoft.zookeeper.ClusterState)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Router (com.newcosoft.cache.Router)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 KeeperException (org.apache.zookeeper.KeeperException)1