Search in sources :

Example 1 with ExecutionLog

use of com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog 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 ExecutionLog

use of com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog in project x-pipe by ctripcorp.

the class DefaultPrimaryDcPrepareToChange method deprepare.

@Override
public MetaServerConsoleService.PreviousPrimaryDcMessage deprepare(String clusterId, String shardId) {
    logger.info("[deprepare]{}, {}", clusterId, shardId);
    MetaServerConsoleService.PreviousPrimaryDcMessage message = new MetaServerConsoleService.PreviousPrimaryDcMessage();
    ExecutionLog executionLog = new ExecutionLog(String.format("meta server:%s", currentClusterServer.getClusterInfo()));
    Pair<String, Integer> keeperMaster = currentMetaManager.getKeeperMaster(clusterId, shardId);
    message.setMasterAddr(new HostPort(keeperMaster.getKey(), keeperMaster.getValue()));
    executionLog.info("[deprepare]" + keeperMaster);
    makeMasterReadOnly(clusterId, shardId, keeperMaster, false, executionLog);
    addSentinel(clusterId, shardId, executionLog);
    message.setMessage(executionLog.getLog());
    return message;
}
Also used : ExecutionLog(com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog) MetaServerConsoleService(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService) HostPort(com.ctrip.xpipe.endpoint.HostPort)

Example 3 with ExecutionLog

use of com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog in project x-pipe by ctripcorp.

the class DefaultOffsetwaiterTest method beforeDefaultOffsetwaiterTest.

@Before
public void beforeDefaultOffsetwaiterTest() throws Exception {
    offsetwaiter = new DefaultOffsetwaiter();
    offsetwaiter.setKeyedObjectPool(getXpipeNettyClientKeyedObjectPool());
    offsetwaiter.setMetaServerConfig(new UnitTestServerConfig().setWaitforOffsetMilli(waitforOffsetMilli));
    offsetwaiter.setScheduled(scheduled);
    executionLog = new ExecutionLog(currentTestName());
    host = "127.0.0.1";
    port = randomPort();
}
Also used : ExecutionLog(com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog) DefaultOffsetwaiter(com.ctrip.xpipe.redis.meta.server.dcchange.impl.DefaultOffsetwaiter) UnitTestServerConfig(com.ctrip.xpipe.redis.meta.server.config.UnitTestServerConfig) Before(org.junit.Before)

Example 4 with ExecutionLog

use of com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog in project x-pipe by ctripcorp.

the class DefaultPrimaryDcPrepareToChange method prepare.

@Override
public MetaServerConsoleService.PreviousPrimaryDcMessage prepare(String clusterId, String shardId) {
    logger.info("[prepare]{}, {}", clusterId, shardId);
    MetaServerConsoleService.PreviousPrimaryDcMessage message = new MetaServerConsoleService.PreviousPrimaryDcMessage();
    ExecutionLog executionLog = new ExecutionLog(String.format("meta server:%s", currentClusterServer.getClusterInfo()));
    Pair<String, Integer> keeperMaster = currentMetaManager.getKeeperMaster(clusterId, shardId);
    message.setMasterAddr(new HostPort(keeperMaster.getKey(), keeperMaster.getValue()));
    executionLog.info("[prepare]" + keeperMaster);
    RedisInfo redisInfo = getInfoReplication(keeperMaster, executionLog);
    MasterInfo masterInfo = convert(redisInfo, executionLog);
    message.setMasterInfo(masterInfo);
    logger.info("[prepare]{}, {}, {}", keeperMaster, redisInfo, masterInfo);
    makeMasterReadOnly(clusterId, shardId, keeperMaster, true, executionLog);
    removeSentinel(clusterId, shardId, executionLog);
    message.setMessage(executionLog.getLog());
    return message;
}
Also used : MasterInfo(com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo) ExecutionLog(com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog) MetaServerConsoleService(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService) HostPort(com.ctrip.xpipe.endpoint.HostPort) RedisInfo(com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo)

Example 5 with ExecutionLog

use of com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog in project x-pipe by ctripcorp.

the class BecomePrimaryActionTest method test.

@Test
public void test() throws Exception {
    BecomePrimaryAction becomePrimaryAction = new BecomePrimaryAction(dcMetaCache, currentMetaManager, sentinelManager, offsetWaiter, new ExecutionLog(getTestName()), getXpipeNettyClientKeyedObjectPool(), newMasterChooser, scheduled, executors);
    PrimaryDcChangeMessage message = becomePrimaryAction.changePrimaryDc(getClusterId(), getShardId(), newPrimaryDc, new MasterInfo());
    logger.info("{}", message);
}
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) PrimaryDcChangeMessage(com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Aggregations

ExecutionLog (com.ctrip.xpipe.redis.meta.server.dcchange.ExecutionLog)7 MasterInfo (com.ctrip.xpipe.redis.core.protocal.pojo.MasterInfo)4 PrimaryDcChangeMessage (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService.PrimaryDcChangeMessage)3 Test (org.junit.Test)3 HostPort (com.ctrip.xpipe.endpoint.HostPort)2 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)2 MetaServerConsoleService (com.ctrip.xpipe.redis.core.metaserver.MetaServerConsoleService)2 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)2 BecomeBackupAction (com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomeBackupAction)2 BecomePrimaryAction (com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomePrimaryAction)2 Before (org.junit.Before)2 SentinelMeta (com.ctrip.xpipe.redis.core.entity.SentinelMeta)1 RedisInfo (com.ctrip.xpipe.redis.core.protocal.pojo.RedisInfo)1 UnitTestServerConfig (com.ctrip.xpipe.redis.meta.server.config.UnitTestServerConfig)1 DefaultOffsetwaiter (com.ctrip.xpipe.redis.meta.server.dcchange.impl.DefaultOffsetwaiter)1 DefaultSentinelManager (com.ctrip.xpipe.redis.meta.server.dcchange.impl.DefaultSentinelManager)1