use of com.ctrip.xpipe.endpoint.DefaultEndPoint in project x-pipe by ctripcorp.
the class RedisPromotor method redisModified.
private void redisModified(RedisSlave redisSlave, SimpleObjectPool<NettyClient> clientPool) throws Exception {
try {
logger.info("[redisModified]{}", redisSlave);
AbstractSlaveOfCommand slaveOfCmd = new SlaveOfCommand(clientPool, scheduled);
slaveOfCmd.execute().sync();
InfoCommand infoServerCmd = new InfoCommand(clientPool, "server", scheduled);
String info = infoServerCmd.execute().get();
String masterId = null;
List<String> lines = IOUtils.readLines(new StringReader(info));
for (String line : lines) {
if (line.startsWith("run_id:")) {
masterId = line.substring("run_id:".length());
}
}
InfoCommand infoLastMasterCmd = new InfoCommand(clientPool, "lastmaster", scheduled);
String infoLastMaster = infoLastMasterCmd.execute().get();
long keeperOffset = 0, newMasterOffset = 0;
try {
String[] parts = infoLastMaster.split("\\s");
keeperOffset = Long.parseLong(parts[1]);
newMasterOffset = Long.parseLong(parts[2]);
redisKeeperServer.getRedisKeeperServerState().setPromotionState(PROMOTION_STATE.SLAVE_PROMTED, new SlavePromotionInfo(keeperOffset, new DefaultEndPoint(promoteServerIp, promoteServerPort), masterId, newMasterOffset));
} catch (Exception e) {
logger.error("[onComplete]" + promoteServerIp + ":" + promoteServerPort, e);
}
} catch (IOException e1) {
logger.error("promoteSlaveToMaster", e1);
}
}
use of com.ctrip.xpipe.endpoint.DefaultEndPoint in project x-pipe by ctripcorp.
the class ReplicationStoreMetaTest method createRandomMeta.
private ReplicationStoreMeta createRandomMeta() {
ReplicationStoreMeta meta = new ReplicationStoreMeta();
meta.setBeginOffset(2L);
meta.setCmdFilePrefix("cmd");
meta.setKeeperRunid(randomString(10));
meta.setMasterAddress(new DefaultEndPoint("redis://localhost:7777"));
meta.setReplId(randomString(40));
meta.setReplId2(randomString(40));
meta.setSecondReplIdOffset((long) randomInt());
meta.setRdbFile(randomString(10));
meta.setRdbFileSize(1000L);
meta.setKeeperState(KeeperState.ACTIVE);
return meta;
}
use of com.ctrip.xpipe.endpoint.DefaultEndPoint in project x-pipe by ctripcorp.
the class PsyncTest method beforePsyncTest.
@Before
public void beforePsyncTest() throws Exception {
masterOffset = (long) randomInt(0, Integer.MAX_VALUE - 1);
replicationStoreManager = createReplicationStoreManager();
LifecycleHelper.initializeIfPossible(replicationStoreManager);
replicationStore = (DefaultReplicationStore) replicationStoreManager.create();
SimpleObjectPool<NettyClient> clientPool = NettyPoolUtil.createNettyPool(new InetSocketAddress("127.0.0.1", 1234));
psync = new DefaultPsync(clientPool, new DefaultEndPoint("127.0.0.1", 1234), replicationStoreManager, scheduled);
psync.future().addListener(new CommandFutureListener<Object>() {
@Override
public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
if (!commandFuture.isSuccess()) {
logger.error("[operationComplete]", commandFuture.cause());
}
}
});
}
use of com.ctrip.xpipe.endpoint.DefaultEndPoint in project x-pipe by ctripcorp.
the class DefaultRedisMasterReplicationTest method testStopReceivingDataWhenNotStarted.
@Test
public void testStopReceivingDataWhenNotStarted() throws Exception {
when(redisMaster.masterEndPoint()).thenReturn(new DefaultEndPoint("localhost", randomPort()));
defaultRedisMasterReplication.initialize();
try {
defaultRedisMasterReplication.handleResponse(mock(Channel.class), Unpooled.wrappedBuffer(randomString().getBytes()));
Assert.fail();
} catch (RedisMasterReplicationStateException e) {
logger.info("{}", e.getMessage());
}
defaultRedisMasterReplication.start();
Channel channel = mock(Channel.class);
when(channel.closeFuture()).thenReturn(mock(ChannelFuture.class));
defaultRedisMasterReplication.masterConnected(channel);
defaultRedisMasterReplication.handleResponse(channel, Unpooled.wrappedBuffer(randomString().getBytes()));
defaultRedisMasterReplication.stop();
try {
defaultRedisMasterReplication.handleResponse(mock(Channel.class), Unpooled.wrappedBuffer(randomString().getBytes()));
Assert.fail();
} catch (RedisMasterReplicationStateException e) {
logger.info("{}", e.getMessage());
}
defaultRedisMasterReplication.dispose();
try {
defaultRedisMasterReplication.handleResponse(mock(Channel.class), Unpooled.wrappedBuffer(randomString().getBytes()));
Assert.fail();
} catch (RedisMasterReplicationStateException e) {
logger.info("{}", e.getMessage());
}
}
Aggregations