use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class DefaultSlaveOfCommand method doExecute.
@Override
protected void doExecute() throws CommandExecutionException {
SimpleObjectPool<NettyClient> clientPool = getClientPool();
UntilSuccess slaveOf = new UntilSuccess();
slaveOf.add(new XSlaveofCommand(clientPool, ip, port, scheduled));
slaveOf.add(new SlaveOfCommand(clientPool, ip, port, scheduled));
SequenceCommandChain chain = new SequenceCommandChain(false);
chain.add(slaveOf);
chain.add(new ConfigRewrite(clientPool, scheduled));
chain.execute().addListener(new CommandFutureListener<Object>() {
@Override
public void operationComplete(CommandFuture<Object> commandFuture) throws Exception {
if (commandFuture.isSuccess()) {
future().setSuccess(RedisClientProtocol.OK);
} else {
future().setFailure(commandFuture.cause());
}
}
});
}
use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class AbstractFakeRedisTest method sendInmemoryPsync.
protected InMemoryPsync sendInmemoryPsync(String ip, int port, String runid, long offset) throws Exception {
SequenceCommandChain chain = new SequenceCommandChain(false);
SimpleObjectPool<NettyClient> pool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress(ip, port));
NettyClient nettyClient = null;
try {
nettyClient = pool.borrowObject();
SimpleObjectPool<NettyClient> clientPool = new FixedObjectPool<NettyClient>(nettyClient);
chain.add(new Replconf(clientPool, ReplConfType.CAPA, scheduled, CAPA.EOF.toString()));
InMemoryPsync psync = new InMemoryPsync(clientPool, runid, offset, scheduled);
chain.add(psync);
psync.addPsyncObserver(new PsyncObserver() {
private long masterRdbOffset = 0;
@Override
public void reFullSync() {
}
@Override
public void onFullSync() {
}
@Override
public void onContinue(String requestReplId, String responseReplId) {
}
@Override
public void endWriteRdb() {
new Replconf(clientPool, ReplConfType.ACK, scheduled, String.valueOf(masterRdbOffset)).execute();
}
@Override
public void beginWriteRdb(EofType eofType, long masterRdbOffset) throws IOException {
this.masterRdbOffset = masterRdbOffset;
}
});
chain.execute();
return psync;
} finally {
if (nettyClient != null) {
pool.returnObject(nettyClient);
}
}
}
use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class AbstractNewMasterChooser method serverRole.
protected SERVER_ROLE serverRole(RedisMeta redisMeta) {
try {
SimpleObjectPool<NettyClient> clientPool = keyedObjectPool.getKeyPool(new InetSocketAddress(redisMeta.getIp(), redisMeta.getPort()));
Role role = new RoleCommand(clientPool, CHECK_NEW_MASTER_TIMEOUT_SECONDS * 1000, true, scheduled).execute().get(CHECK_NEW_MASTER_TIMEOUT_SECONDS, TimeUnit.SECONDS);
return role.getServerRole();
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.error("[isMaster]" + redisMeta, e);
}
return SERVER_ROLE.UNKNOWN;
}
use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class DefaultPsyncTest method beforeDefaultPsyncTest.
@Before
public void beforeDefaultPsyncTest() throws Exception {
FakeRedisServer fakeRedisServer = startFakeRedisServer();
Endpoint masterEndPoint = new DefaultEndPoint("localhost", fakeRedisServer.getPort());
SimpleObjectPool<NettyClient> pool = NettyPoolUtil.createNettyPool(new InetSocketAddress("localhost", fakeRedisServer.getPort()));
when(replicationStoreManager.createIfNotExist()).thenReturn(replicationStore);
when(replicationStore.getMetaStore()).thenReturn(metaStore);
when(metaStore.getReplId()).thenReturn("?");
when(replicationStore.getEndOffset()).thenReturn(-1L);
defaultPsync = new DefaultPsync(pool, masterEndPoint, replicationStoreManager, scheduled);
}
use of com.ctrip.xpipe.netty.commands.NettyClient in project x-pipe by ctripcorp.
the class RedisCommandTest method testTimeoutNext.
@Test
public void testTimeoutNext() throws Exception {
Server server = startEchoPrefixServer(String.valueOf((char) RedisClientProtocol.PLUS_BYTE));
SimpleObjectPool<NettyClient> keyPool = getXpipeNettyClientKeyedObjectPool().getKeyPool(new InetSocketAddress("127.0.0.1", server.getPort()));
int sleepTime = timeoutMilli + 50;
String str1 = String.format("sleep %d %s\r\n", sleepTime, randomString(10));
String str2 = randomString(10) + "\r\n";
try {
new TestCommand(str1, timeoutMilli, keyPool, scheduled).execute().get();
Assert.fail();
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof CommandTimeoutException);
}
sleep(sleepTime * 2);
new TestCommand(str2, sleepTime, keyPool, scheduled).execute().get();
}
Aggregations