use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class DefaultCurrentMetaManager method dcMetaChange.
private void dcMetaChange(DcMetaComparator comparator) {
for (ClusterMeta clusterMeta : comparator.getAdded()) {
if (currentClusterServer.hasKey(clusterMeta.getId())) {
addCluster(clusterMeta.getId());
} else {
logger.info("[dcMetaChange][add][not interested]{}", clusterMeta.getId());
}
}
for (ClusterMeta clusterMeta : comparator.getRemoved()) {
if (currentClusterServer.hasKey(clusterMeta.getId())) {
destroyCluster(clusterMeta);
} else {
logger.info("[dcMetaChange][destroy][not interested]{}", clusterMeta.getId());
}
}
for (@SuppressWarnings("rawtypes") MetaComparator changedComparator : comparator.getMofified()) {
ClusterMetaComparator clusterMetaComparator = (ClusterMetaComparator) changedComparator;
String clusterId = clusterMetaComparator.getCurrent().getId();
if (currentClusterServer.hasKey(clusterId)) {
handleClusterChanged(clusterMetaComparator);
} else {
logger.info("[dcMetaChange][change][not interested]{}", clusterId);
}
}
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class DefaultCurrentMetaManager method addCluster.
private void addCluster(String clusterId) {
ClusterMeta clusterMeta = dcMetaCache.getClusterMeta(clusterId);
logger.info("[addCluster]{}, {}", clusterId, clusterMeta);
currentMeta.addCluster(clusterMeta);
notifyObservers(new NodeAdded<ClusterMeta>(clusterMeta));
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class BackupDcClusterRedisStateAjust method doRun.
@Override
protected void doRun() throws Exception {
ClusterMeta clusterMeta = currentMetaManager.getClusterMeta(clusterId);
if (clusterMeta == null) {
logger.warn("[doRun][cluster null]{}", clusterId);
return;
}
for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
logger.debug("[doRun]{}, {}", clusterId, shardMeta.getId());
KeeperMeta keeperActive = currentMetaManager.getKeeperActive(clusterId, shardMeta.getId());
if (keeperActive == null) {
logger.debug("[doRun][keeper active null]{}, {}", clusterId, shardMeta.getId());
continue;
}
List<RedisMeta> redisesNeedChange = getRedisesNeedToChange(shardMeta, keeperActive);
if (redisesNeedChange.size() == 0) {
continue;
}
logger.info("[doRun][change state]{}, {}, {}", clusterId, keeperActive, redisesNeedChange);
new DefaultSlaveOfJob(redisesNeedChange, keeperActive.getIp(), keeperActive.getPort(), pool, scheduled, executors).execute().addListener(new CommandFutureListener<Void>() {
@Override
public void operationComplete(CommandFuture<Void> commandFuture) throws Exception {
if (!commandFuture.isSuccess()) {
logger.error("[operationComplete][fail]" + commandFuture.command(), commandFuture.cause());
}
}
});
}
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class DcMetaComparatorTest method testModified.
@Test
public void testModified() {
ClusterMeta clusterMeta = (ClusterMeta) future.getClusters().values().toArray()[0];
clusterMeta.addShard(differentShard(clusterMeta));
DcMetaComparator dcMetaComparator = new DcMetaComparator(current, future);
dcMetaComparator.compare();
Assert.assertEquals(0, dcMetaComparator.getRemoved().size());
Assert.assertEquals(0, dcMetaComparator.getAdded().size());
Assert.assertEquals(1, dcMetaComparator.getMofified().size());
ClusterMetaComparator comparator = (ClusterMetaComparator) dcMetaComparator.getMofified().toArray()[0];
Assert.assertEquals(clusterMeta.getId(), comparator.getCurrent().getId());
Assert.assertEquals(1, comparator.getAdded().size());
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class ClusterServersApiTest method testClusterChanged.
@Test
public void testClusterChanged() throws Exception {
createMetaServers(metaServerCount);
sleep(waitForMetaServerOkTime);
logger.info(remarkableMessage("[testClusterChanged][begin send cluster change message]"));
ClusterMeta clusterMeta = randomCluster();
for (TestMetaServer server : getServers()) {
String path = META_SERVER_SERVICE.CLUSTER_CHANGE.getRealPath(server.getAddress());
logger.info("[testClusterChanged]{}", path);
restTemplate.postForEntity(path, clusterMeta, String.class, clusterMeta.getId());
restTemplate.put(path, clusterMeta, String.class, clusterMeta.getId());
restTemplate.delete(path, clusterMeta.getId());
}
}
Aggregations