use of com.newcosoft.cache.Shard in project disgear by yangbutao.
the class CacheClient method getWriteUrl.
public static String getWriteUrl(String key, String collection) {
ClusterState clusterState = ClusterStateCacheManager.INSTANCE.getClusterState();
Set<String> liveNodes = clusterState.getLiveNodes();
Shard shard = Router.DEFAULT.getTargetShard(key, clusterState.getCollection(collection));
Replica leader = shard.getLeader();
while (!liveNodes.contains(leader.getName())) {
try {
Thread.currentThread().sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
leader = shard.getLeader();
}
return leader.getStr("base_url");
}
use of com.newcosoft.cache.Shard in project disgear by yangbutao.
the class ClusterState method getLeader.
public Replica getLeader(String collection, String sliceName) {
CacheCollection coll = collectionStates.get(collection);
if (coll == null)
return null;
Shard slice = coll.getShard(sliceName);
if (slice == null)
return null;
return slice.getLeader();
}
use of com.newcosoft.cache.Shard in project disgear by yangbutao.
the class ClusterState method getShardId.
public String getShardId(String baseUrl, String coreName) {
// ") in " + collectionStates);
for (CacheCollection coll : collectionStates.values()) {
for (Shard slice : coll.getShards()) {
for (Replica replica : slice.getReplicas()) {
String rbaseUrl = replica.getStr(ZkStateReader.BASE_URL_PROP);
String rcore = replica.getStr(ZkStateReader.CORE_NAME_PROP);
if (baseUrl.equals(rbaseUrl) && coreName.equals(rcore)) {
return slice.getName();
}
}
}
}
return null;
}
use of com.newcosoft.cache.Shard in project disgear by yangbutao.
the class OverseerCollectionProcessor method deleteShard.
private void deleteShard(ClusterState clusterState, ZkNodeProps message) {
log.info("Delete shard invoked");
String collection = message.getStr(ZkStateReader.COLLECTION_PROP);
String sliceId = message.getStr(ZkStateReader.SHARD_ID_PROP);
Shard slice = clusterState.getSlice(collection, sliceId);
if (slice == null) {
if (clusterState.getCollections().contains(collection)) {
throw new RuntimeException("No shard with the specified name exists: " + slice);
} else {
throw new RuntimeException("No collection with the specified name exists: " + collection);
}
}
if (!(slice.getRange() == null || slice.getState().equals(Shard.INACTIVE))) {
throw new RuntimeException("The slice: " + slice.getName() + " is currently " + slice.getState() + ". Only INACTIVE (or custom-hashed) slices can be deleted.");
}
}
use of com.newcosoft.cache.Shard in project disgear by yangbutao.
the class ZookeeperController method publishAndWaitForDownStates.
public void publishAndWaitForDownStates() throws KeeperException, InterruptedException {
ClusterState clusterState = zkStateReader.getClusterState();
Set<String> collections = clusterState.getCollections();
List<String> updatedNodes = new ArrayList<String>();
for (String collectionName : collections) {
CacheCollection collection = clusterState.getCollection(collectionName);
Collection<Shard> slices = collection.getShards();
for (Shard slice : slices) {
Collection<Replica> replicas = slice.getReplicas();
for (Replica replica : replicas) {
if (replica.getNodeName().equals(getNodeName()) && !(replica.getStr(ZkStateReader.STATE_PROP).equals(ZkStateReader.DOWN))) {
ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, "state", ZkStateReader.STATE_PROP, ZkStateReader.DOWN, ZkStateReader.BASE_URL_PROP, getBaseUrl(), ZkStateReader.CORE_NAME_PROP, replica.getStr(ZkStateReader.CORE_NAME_PROP), ZkStateReader.ROLES_PROP, replica.getStr(ZkStateReader.ROLES_PROP), ZkStateReader.NODE_NAME_PROP, getNodeName(), ZkStateReader.SHARD_ID_PROP, replica.getStr(ZkStateReader.SHARD_ID_PROP), ZkStateReader.COLLECTION_PROP, collectionName, ZkStateReader.CORE_NODE_NAME_PROP, replica.getName());
updatedNodes.add(replica.getStr(ZkStateReader.CORE_NAME_PROP));
// put into overseer/queue��dealing by Overseer
overseerJobQueue.offer(ZkStateReader.toJSON(m));
}
}
}
}
// now wait till the updates are in our state
long now = System.currentTimeMillis();
long timeout = now + 1000 * 30;
boolean foundStates = false;
while (System.currentTimeMillis() < timeout) {
clusterState = zkStateReader.getClusterState();
collections = clusterState.getCollections();
for (String collectionName : collections) {
CacheCollection collection = clusterState.getCollection(collectionName);
Collection<Shard> slices = collection.getShards();
for (Shard slice : slices) {
Collection<Replica> replicas = slice.getReplicas();
for (Replica replica : replicas) {
if (replica.getStr(ZkStateReader.STATE_PROP).equals(ZkStateReader.DOWN)) {
updatedNodes.remove(replica.getStr(ZkStateReader.CORE_NAME_PROP));
}
}
}
}
if (updatedNodes.size() == 0) {
foundStates = true;
Thread.sleep(1000);
break;
}
Thread.sleep(1000);
}
if (!foundStates) {
log.warn("Timed out waiting to see all nodes published as DOWN in our cluster state.");
}
}
Aggregations