Search in sources :

Example 26 with ClusterMeta

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);
        }
    }
}
Also used : ClusterMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ClusterMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator) MetaComparator(com.ctrip.xpipe.redis.core.meta.MetaComparator) DcMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator)

Example 27 with ClusterMeta

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));
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta)

Example 28 with 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());
                }
            }
        });
    }
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) DefaultSlaveOfJob(com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 29 with ClusterMeta

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());
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) Test(org.junit.Test)

Example 30 with ClusterMeta

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());
    }
}
Also used : TestMetaServer(com.ctrip.xpipe.redis.meta.server.TestMetaServer) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) Test(org.junit.Test)

Aggregations

ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)41 Test (org.junit.Test)25 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)13 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)10 DirtiesContext (org.springframework.test.annotation.DirtiesContext)10 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)8 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)5 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)4 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)3 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)3 AbstractMetaServerClusterTest (com.ctrip.xpipe.redis.meta.server.cluster.AbstractMetaServerClusterTest)3 IOException (java.io.IOException)2 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 NodeAdded (com.ctrip.xpipe.observer.NodeAdded)1 NodeDeleted (com.ctrip.xpipe.observer.NodeDeleted)1 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)1 DataNotFoundException (com.ctrip.xpipe.redis.console.exception.DataNotFoundException)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1