Search in sources :

Example 1 with PrimaryDcChangeMessage

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

the class KeeperMultiDcChangePrimary method testChangePrimary.

@Test
public void testChangePrimary() throws Exception {
    String primaryDc = getPrimaryDc();
    String backupDc = getBackupDc();
    // change backup to primary
    when(dcMetaCache.getShardRedises(getClusterId(), getShardId())).thenReturn(getDcRedises(backupDc, getClusterId(), getShardId()));
    when(currentMetaManager.getSurviveKeepers(getClusterId(), getShardId())).thenReturn(getDcKeepers(backupDc, getClusterId(), getShardId()));
    logger.info(remarkableMessage("[make dc primary]change dc primary to:" + backupDc));
    BecomePrimaryAction becomePrimaryAction = new BecomePrimaryAction(dcMetaCache, currentMetaManager, sentinelManager, offsetWaiter, new ExecutionLog(currentTestName()), getXpipeNettyClientKeyedObjectPool(), newMasterChooser, scheduled, executors);
    PrimaryDcChangeMessage message = becomePrimaryAction.changePrimaryDc(getClusterId(), getShardId(), backupDc, new MasterInfo());
    logger.info("{}", message);
    sleep(2000);
    logger.info(remarkableMessage("[make dc backup]change dc primary to:" + backupDc));
    when(dcMetaCache.getPrimaryDc(getClusterId(), getShardId())).thenReturn(backupDc);
    when(multiDcService.getActiveKeeper(backupDc, getClusterId(), getShardId())).thenReturn(getDcKeepers(backupDc, getClusterId(), getShardId()).get(0));
    when(dcMetaCache.getShardRedises(getClusterId(), getShardId())).thenReturn(getDcRedises(primaryDc, getClusterId(), getShardId()));
    when(currentMetaManager.getKeeperActive(getClusterId(), getShardId())).thenReturn(getKeeperActive(primaryDc));
    when(currentMetaManager.getSurviveKeepers(getClusterId(), getShardId())).thenReturn(getDcKeepers(primaryDc, getClusterId(), getShardId()));
    BecomeBackupAction becomeBackupAction = new BecomeBackupAction(dcMetaCache, currentMetaManager, sentinelManager, new ExecutionLog(currentTestName()), getXpipeNettyClientKeyedObjectPool(), multiDcService, scheduled, executors);
    message = becomeBackupAction.changePrimaryDc(getClusterId(), getShardId(), backupDc, new MasterInfo());
    logger.info("{}", message);
    sleep(2000);
    RedisMeta newRedisMaster = newMasterChooser.getLastChoosenMaster();
    List<RedisMeta> allRedises = getRedises(primaryDc);
    allRedises.addAll(getRedises(backupDc));
    allRedises.remove(newRedisMaster);
    logger.info("{}\n{}", newRedisMaster, allRedises);
    sendMesssageToMasterAndTest(newRedisMaster, allRedises);
}
Also used : MasterInfo(com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo) ExecutionLog(com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog) BecomePrimaryAction(com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomePrimaryAction) BecomeBackupAction(com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomeBackupAction) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) PrimaryDcChangeMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage) Test(org.junit.Test)

Example 2 with PrimaryDcChangeMessage

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

the class DefaultChangePrimaryDcAction method changePrimaryDc.

@Override
public PrimaryDcChangeMessage changePrimaryDc(String clusterId, String shardId, String newPrimaryDc, MasterInfo masterInfo) {
    if (!currentMetaManager.hasCluster(clusterId)) {
        logger.info("[changePrimaryDc][not interested in this cluster]");
        return new PrimaryDcChangeMessage(PRIMARY_DC_CHANGE_RESULT.SUCCESS, "not interested in this cluster:" + clusterId);
    }
    ChangePrimaryDcAction changePrimaryDcAction = null;
    ExecutionLog executionLog = new ExecutionLog(String.format("meta server:%s", currentClusterServer.getClusterInfo()));
    if (newPrimaryDc.equalsIgnoreCase(dcMetaCache.getCurrentDc())) {
        logger.info("[doChangePrimaryDc][become primary]{}, {}", clusterId, shardId, newPrimaryDc);
        changePrimaryDcAction = new BecomePrimaryAction(dcMetaCache, currentMetaManager, sentinelManager, offsetWaiter, executionLog, keyedObjectPool, createNewMasterChooser(), scheduled, executors);
    } else {
        logger.info("[doChangePrimaryDc][become backup]{}, {}", clusterId, shardId, newPrimaryDc);
        changePrimaryDcAction = new BecomeBackupAction(dcMetaCache, currentMetaManager, sentinelManager, executionLog, keyedObjectPool, multiDcService, scheduled, executors);
    }
    return changePrimaryDcAction.changePrimaryDc(clusterId, shardId, newPrimaryDc, masterInfo);
}
Also used : BecomePrimaryAction(com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomePrimaryAction) BecomeBackupAction(com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomeBackupAction) PrimaryDcChangeMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage)

Example 3 with PrimaryDcChangeMessage

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

the class BecomeBackupAction method doChangePrimaryDc.

@Override
protected PrimaryDcChangeMessage doChangePrimaryDc(String clusterId, String shardId, String newPrimaryDc, MasterInfo masterInfo) {
    doChangeMetaCache(clusterId, shardId, newPrimaryDc);
    changeSentinel(clusterId, shardId, null);
    Pair<String, Integer> newMaster = chooseNewMaster(clusterId, shardId);
    if (newMaster == null) {
        executionLog.error("[doChangePrimaryDc][new master null]");
        return new PrimaryDcChangeMessage(PRIMARY_DC_CHANGE_RESULT.FAIL, executionLog.getLog());
    }
    executionLog.info(String.format("[chooseNewMaster]%s:%d", newMaster.getKey(), newMaster.getValue()));
    makeKeepersOk(clusterId, shardId, newMaster);
    List<RedisMeta> slaves = getAllSlaves(newMaster, dcMetaCache.getShardRedises(clusterId, shardId));
    KeeperMeta activeKeeper = currentMetaManager.getKeeperActive(clusterId, shardId);
    makeRedisesOk(new Pair<>(activeKeeper.getIp(), activeKeeper.getPort()), slaves);
    return new PrimaryDcChangeMessage(PRIMARY_DC_CHANGE_RESULT.SUCCESS, executionLog.getLog());
}
Also used : RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) PrimaryDcChangeMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 4 with PrimaryDcChangeMessage

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

the class BecomePrimaryAction method doChangePrimaryDc.

protected PrimaryDcChangeMessage doChangePrimaryDc(String clusterId, String shardId, String newPrimaryDc, MasterInfo masterInfo) {
    doChangeMetaCache(clusterId, shardId, newPrimaryDc);
    executionLog.info(String.format("[chooseNewMaster][begin]"));
    Pair<String, Integer> newMaster = chooseNewMaster(clusterId, shardId);
    executionLog.info(String.format("[chooseNewMaster]%s:%d", newMaster.getKey(), newMaster.getValue()));
    // wait for slave to achieve master offset
    offsetWaiter.tryWaitfor(new HostPort(newMaster.getKey(), newMaster.getValue()), masterInfo, executionLog);
    List<RedisMeta> slaves = getAllSlaves(newMaster, dcMetaCache.getShardRedises(clusterId, shardId));
    makeRedisesOk(newMaster, slaves);
    makeKeepersOk(clusterId, shardId, newMaster);
    changeSentinel(clusterId, shardId, newMaster);
    return new PrimaryDcChangeMessage(executionLog.getLog(), newMaster.getKey(), newMaster.getValue());
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) PrimaryDcChangeMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage)

Example 5 with PrimaryDcChangeMessage

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

the class ClusterServersApiTest method testDoChangePrimaryDc.

@Test
public void testDoChangePrimaryDc() throws Exception {
    createMetaServers(metaServerCount);
    sleep(waitForMetaServerOkTime);
    logger.info(remarkableMessage("[testDoChangePrimaryDc][begin send change primary dc message]"));
    for (TestMetaServer server : getServers()) {
        logger.info(remarkableMessage("[testDoChangePrimaryDc][jq]"));
        MetaServerConsoleService.PrimaryDcChangeRequest request = new MetaServerConsoleService.PrimaryDcChangeRequest();
        request.setMasterInfo(new MasterInfo(RunidGenerator.DEFAULT.generateRunid(), 100L));
        MetaServerConsoleService consoleService = new DefaultMetaServerConsoleService(server.getAddress());
        PrimaryDcChangeMessage message = consoleService.doChangePrimaryDc(getClusterId(), getShardId(), "jq", request);
        logger.info("{}", message);
        logger.info(remarkableMessage("[testDoChangePrimaryDc][oy]"));
        message = consoleService.doChangePrimaryDc(getClusterId(), getShardId(), "oy", request);
        logger.info("{}", message);
    }
}
Also used : MasterInfo(com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo) TestMetaServer(com.ctrip.xpipe.redis.meta.server.TestMetaServer) 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) PrimaryDcChangeMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage) Test(org.junit.Test)

Aggregations

PrimaryDcChangeMessage (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage)7 MasterInfo (com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo)4 Test (org.junit.Test)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)3 ExecutionLog (com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog)3 BecomeBackupAction (com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomeBackupAction)3 BecomePrimaryAction (com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomePrimaryAction)3 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)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