use of com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomePrimaryAction 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);
}
use of com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomePrimaryAction 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);
}
use of com.ctrip.xpipe.redis.meta.server.dcchange.impl.BecomePrimaryAction 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);
}
Aggregations