Search in sources :

Example 1 with PrimaryDcCheckMessage

use of com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage in project x-pipe by ctripcorp.

the class ClusterServersApiTest method testChangePrimaryDcCheck.

@Test
public void testChangePrimaryDcCheck() throws Exception {
    createMetaServers(metaServerCount);
    sleep(waitForMetaServerOkTime);
    logger.info(remarkableMessage("[testChangePrimaryDcCheck][begin send primary dc check message]"));
    for (TestMetaServer server : getServers()) {
        logger.info("[testChangePrimaryDcCheck]{}", server.getAddress());
        MetaServerConsoleService consoleService = new DefaultMetaServerConsoleService(server.getAddress());
        PrimaryDcCheckMessage message = consoleService.changePrimaryDcCheck(getClusterId(), getShardId(), "newPrimaryDc");
        logger.info("[testChangePrimaryDcCheck]{}, {}", server.getAddress(), message);
    }
}
Also used : TestMetaServer(com.ctrip.xpipe.redis.meta.server.TestMetaServer) PrimaryDcCheckMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage) MetaServerConsoleService(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService) DefaultMetaServerConsoleService(com.ctrip.xpipe.redis.core.metaserver.impl.DefaultMetaServerConsoleService) DefaultMetaServerConsoleService(com.ctrip.xpipe.redis.core.metaserver.impl.DefaultMetaServerConsoleService) Test(org.junit.Test)

Example 2 with PrimaryDcCheckMessage

use of com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage in project x-pipe by ctripcorp.

the class DefaultMetaServer method changePrimaryDcCheck.

@Override
public PrimaryDcCheckMessage changePrimaryDcCheck(String clusterId, String shardId, String newPrimaryDc, ForwardInfo forwardInfo) {
    logger.info("[changePrimaryDcCheck]{}, {}, {}, {}", clusterId, shardId, newPrimaryDc, forwardInfo);
    String currentPrimaryDc = dcMetaCache.getPrimaryDc(clusterId, shardId);
    String currentDc = dcMetaCache.getCurrentDc();
    if (newPrimaryDc.equalsIgnoreCase(currentPrimaryDc)) {
        return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.PRIMARY_DC_ALREADY_IS_NEW, String.format("%s already primary dc", newPrimaryDc));
    }
    if (currentDc.equalsIgnoreCase(newPrimaryDc)) {
        List<RedisMeta> redises = dcMetaCache.getShardRedises(clusterId, shardId);
        SimpleErrorMessage result = new AtLeastOneChecker(redises, keyedObjectPool, scheduled).check();
        if (result.getErrorType() == SIMPLE_RETURN_CODE.SUCCESS) {
            return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.SUCCESS);
        }
        return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.FAIL, "all redises dead:" + result.getErrorMessage());
    }
    return new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.SUCCESS, String.format("current dc :%s is not new primary: %s ", currentDc, newPrimaryDc));
}
Also used : PrimaryDcCheckMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage) AtLeastOneChecker(com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) SimpleErrorMessage(com.ctrip.xpipe.exception.SimpleErrorMessage)

Example 3 with PrimaryDcCheckMessage

use of com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage in project x-pipe by ctripcorp.

the class PrimaryDcCheckMessageTest method testEncodeDecode.

@Test
public void testEncodeDecode() {
    PrimaryDcCheckMessage message = new PrimaryDcCheckMessage(PRIMARY_DC_CHECK_RESULT.SUCCESS, "hello");
    String encode = Codec.DEFAULT.encode(message);
    logger.info("{}", encode);
    PrimaryDcCheckMessage decode = Codec.DEFAULT.decode(encode, PrimaryDcCheckMessage.class);
    logger.info("{}", decode);
}
Also used : PrimaryDcCheckMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage) AbstractRedisTest(com.ctrip.xpipe.redis.core.AbstractRedisTest) Test(org.junit.Test)

Aggregations

PrimaryDcCheckMessage (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcCheckMessage)3 Test (org.junit.Test)2 SimpleErrorMessage (com.ctrip.xpipe.exception.SimpleErrorMessage)1 AbstractRedisTest (com.ctrip.xpipe.redis.core.AbstractRedisTest)1 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)1 MetaServerConsoleService (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService)1 DefaultMetaServerConsoleService (com.ctrip.xpipe.redis.core.metaserver.impl.DefaultMetaServerConsoleService)1 TestMetaServer (com.ctrip.xpipe.redis.meta.server.TestMetaServer)1 AtLeastOneChecker (com.ctrip.xpipe.redis.meta.server.dcchange.impl.AtLeastOneChecker)1