Search in sources :

Example 6 with DefaultEndPoint

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);
    }
}
Also used : AbstractSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand) InfoCommand(com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand) StringReader(java.io.StringReader) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) AbstractSlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand) SlaveOfCommand(com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand) IOException(java.io.IOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)

Example 7 with DefaultEndPoint

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;
}
Also used : DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint)

Example 8 with DefaultEndPoint

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());
            }
        }
    });
}
Also used : NettyClient(com.ctrip.xpipe.netty.commands.NettyClient) InetSocketAddress(java.net.InetSocketAddress) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) IOException(java.io.IOException) XpipeException(com.ctrip.xpipe.exception.XpipeException) DefaultPsync(com.ctrip.xpipe.redis.core.protocal.cmd.DefaultPsync) Before(org.junit.Before)

Example 9 with DefaultEndPoint

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());
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) DefaultEndPoint(com.ctrip.xpipe.endpoint.DefaultEndPoint) AbstractRedisKeeperTest(com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest) Test(org.junit.Test)

Aggregations

DefaultEndPoint (com.ctrip.xpipe.endpoint.DefaultEndPoint)9 AbstractRedisKeeperTest (com.ctrip.xpipe.redis.keeper.AbstractRedisKeeperTest)3 IOException (java.io.IOException)3 Before (org.junit.Before)3 Test (org.junit.Test)3 Endpoint (com.ctrip.xpipe.api.endpoint.Endpoint)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)2 InetSocketAddress (java.net.InetSocketAddress)2 XpipeException (com.ctrip.xpipe.exception.XpipeException)1 AbstractSlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.AbstractSlaveOfCommand)1 DefaultPsync (com.ctrip.xpipe.redis.core.protocal.cmd.DefaultPsync)1 InfoCommand (com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand)1 SlaveOfCommand (com.ctrip.xpipe.redis.core.protocal.cmd.SlaveOfCommand)1 LenEofType (com.ctrip.xpipe.redis.core.protocal.protocal.LenEofType)1 FakeRedisServer (com.ctrip.xpipe.redis.core.server.FakeRedisServer)1 MetaStore (com.ctrip.xpipe.redis.core.store.MetaStore)1 ReplicationStore (com.ctrip.xpipe.redis.core.store.ReplicationStore)1 RedisKeeperServer (com.ctrip.xpipe.redis.keeper.RedisKeeperServer)1 RedisSlavePromotionException (com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)1 Server (com.ctrip.xpipe.simpleserver.Server)1