use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.
the class KeeperSingleDcWaitForOffset method testMakeBackupActive.
@Test
public void testMakeBackupActive() throws Exception {
RedisKeeperServer redisKeeperServer = getRedisKeeperServer(backupKeeper);
Assert.assertEquals(PARTIAL_STATE.FULL, redisKeeperServer.getRedisMaster().partialState());
logger.info(remarkableMessage("make keeper active to wrong addr{}"), backupKeeper);
String ip = "localhost";
int port = randomPort();
setKeeperState(backupKeeper, KeeperState.ACTIVE, ip, port);
sleep(2000);
// make sure redis has more log
sendMessageToMaster(redisMaster, 1);
xslaveof(backupKeeper.getIp(), backupKeeper.getPort(), getRedisSlaves());
sleep(2000);
setKeeperState(backupKeeper, KeeperState.ACTIVE, redisMaster.getIp(), redisMaster.getPort());
sleep(2000);
Set<RedisSlave> slaves = redisKeeperServer.slaves();
Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisKeeperServer.getRedisMaster().partialState());
slaves.forEach(redisSlave -> Assert.assertEquals(PARTIAL_STATE.PARTIAL, redisSlave.partialState()));
Assert.assertEquals(slaves.size(), redisKeeperServer.getKeeperMonitor().getKeeperStats().getWaitOffsetSucceed());
Assert.assertEquals(0, redisKeeperServer.getKeeperMonitor().getKeeperStats().getWaitOffsetFail());
sendMessageToMasterAndTestSlaveRedis();
}
use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.
the class BadKeeperWrongCommands method giveWrongCommands.
@SuppressWarnings("unused")
@Test
public void giveWrongCommands() throws IOException {
String[] commands = createCommands();
RedisKeeperServer active = getRedisKeeperServer(activeKeeper);
RedisKeeperServer backup = getRedisKeeperServer(backupKeeper);
replicationStore = active.getReplicationStore();
Set<RedisSlave> slaves = active.slaves();
replicationStore.appendCommands(Unpooled.wrappedBuffer("*3\r\n$3\r\nset\r\n$1\r\na\r\n$5\r\n12 34\r\n\r\n".getBytes()));
logger.info(remarkableMessage("stop redis master"));
waitForAnyKey();
stopRedisMaster();
printSlaves(slaves);
logger.info(remarkableMessage("give part commands:" + commands[0].length()));
waitForAnyKey();
replicationStore.appendCommands(Unpooled.wrappedBuffer(commands[0].getBytes()));
logger.info(remarkableMessage("close client connection"));
waitForAnyKey();
for (RedisSlave slave : active.slaves()) {
slave.close();
}
System.out.println("give other commands");
waitForAnyKey();
for (int i = 1; i < commands.length; i++) {
replicationStore.appendCommands(Unpooled.wrappedBuffer(commands[i].getBytes()));
}
waitForAnyKeyToExit();
}
use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.
the class KeeperFailoverTest method testKeeperFailOver.
@Test
public void testKeeperFailOver() throws Exception {
RedisKeeperServer activeRedisKeeperServer = getRedisKeeperServerActive();
logger.info("[testKeeperFailOver][active]{}", activeRedisKeeperServer);
sleep(6000);
logger.info(remarkableMessage("[testKeeperFailOver][stop activeKeeper]"), activeRedisKeeperServer);
remove(activeRedisKeeperServer);
sleep(6000);
RedisKeeperServer activeNow = getRedisKeeperServerActive();
logger.info("[testKeeperFailOver][active new]{}", activeNow);
Assert.assertNotNull(activeNow);
Assert.assertNotEquals(activeRedisKeeperServer, activeNow);
Assert.assertEquals(PARTIAL_STATE.PARTIAL, activeNow.getRedisMaster().partialState());
for (RedisSlave slave : activeNow.slaves()) {
Assert.assertEquals(PARTIAL_STATE.PARTIAL, slave.partialState());
}
sendMessageToMasterAndTestSlaveRedis();
}
use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.
the class PsyncHandlerTest method beforePsyncHandlerTest.
@Before
public void beforePsyncHandlerTest() {
when(redisSlave.getRedisKeeperServer()).thenReturn(redisKeeperServer);
when(redisKeeperServer.getKeeperRepl()).thenReturn(keeperRepl);
when(redisKeeperServer.getKeeperMonitor()).thenReturn(new DefaultKeeperMonitor(redisKeeperServer));
when(redisKeeperServer.getKeeperConfig()).thenReturn(KeeperConfig);
when(keeperRepl.getBeginOffset()).thenReturn(begin);
when(keeperRepl.getEndOffset()).thenReturn(end);
when(keeperRepl.replId()).thenReturn(replId);
when(keeperRepl.replId2()).thenReturn(replId2);
when(keeperRepl.secondReplIdOffset()).thenReturn(secondReplOffset);
when(KeeperConfig.getReplicationStoreMaxCommandsToTransferBeforeCreateRdb()).thenReturn(maxToTransfer);
psyncHandler = new PsyncHandler() {
@Override
protected void doPartialSync(RedisSlave redisSlave, String replId, Long offset) {
function = PARTIAL;
}
@Override
protected void doFullSync(RedisSlave redisSlave) {
function = FULL;
}
@Override
protected void waitForoffset(String[] args, RedisSlave redisSlave, String replId, Long offsetRequest) {
function = WAIT;
}
};
}
use of com.ctrip.xpipe.redis.keeper.RedisSlave in project x-pipe by ctripcorp.
the class RedisPromotor method findSlave.
private RedisSlave findSlave(RedisKeeperServer keeper, String actualIp, int actualPort) {
Set<RedisSlave> slaves = keeper.slaves();
for (RedisSlave redisSlave : slaves) {
InetSocketAddress slaveAddr = (InetSocketAddress) redisSlave.channel().remoteAddress();
String expectedIp = slaveAddr.getAddress().getHostAddress();
int expectedPort = redisSlave.getSlaveListeningPort();
if (expectedIp.equals(actualIp) && expectedPort == actualPort) {
return redisSlave;
}
}
return null;
}
Aggregations