-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #922 from ctripcorp/feature/keeper_fresh_rdb_dumper
keeper support freshRdbPsync
- Loading branch information
Showing
20 changed files
with
535 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...s/redis-core/src/main/java/com/ctrip/xpipe/redis/core/protocal/cmd/FreshRdbOnlyPsync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.ctrip.xpipe.redis.core.protocal.cmd; | ||
|
||
import com.ctrip.xpipe.api.pool.SimpleObjectPool; | ||
import com.ctrip.xpipe.netty.commands.NettyClient; | ||
import com.ctrip.xpipe.redis.core.store.ReplicationStore; | ||
import com.ctrip.xpipe.tuple.Pair; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
public class FreshRdbOnlyPsync extends RdbOnlyPsync { | ||
|
||
public FreshRdbOnlyPsync(SimpleObjectPool<NettyClient> clientPool, ReplicationStore store, ScheduledExecutorService scheduled) { | ||
super(clientPool, store, scheduled); | ||
} | ||
|
||
@Override | ||
protected Pair<String, Long> getRequestMasterInfo() { | ||
// psync ? -3 | ||
return new Pair<>("?", KEEPER_FRESH_RDB_SYNC_OFFSET); | ||
} | ||
|
||
} |
108 changes: 108 additions & 0 deletions
108
...dis-core/src/test/java/com/ctrip/xpipe/redis/core/protocal/cmd/FreshRdbOnlyPsyncTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.ctrip.xpipe.redis.core.protocal.cmd; | ||
|
||
import com.ctrip.xpipe.api.command.CommandFuture; | ||
import com.ctrip.xpipe.api.command.CommandFutureListener; | ||
import com.ctrip.xpipe.api.endpoint.Endpoint; | ||
import com.ctrip.xpipe.endpoint.DefaultEndPoint; | ||
import com.ctrip.xpipe.netty.NettyPoolUtil; | ||
import com.ctrip.xpipe.redis.core.AbstractRedisTest; | ||
import com.ctrip.xpipe.redis.core.protocal.PsyncObserver; | ||
import com.ctrip.xpipe.redis.core.protocal.protocal.EofType; | ||
import com.ctrip.xpipe.redis.core.redis.RunidGenerator; | ||
import com.ctrip.xpipe.redis.core.store.MetaStore; | ||
import com.ctrip.xpipe.redis.core.store.RdbStore; | ||
import com.ctrip.xpipe.redis.core.store.ReplicationStore; | ||
import com.ctrip.xpipe.redis.core.store.ReplicationStoreManager; | ||
import com.ctrip.xpipe.simpleserver.Server; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Function; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.Silent.class) | ||
public class FreshRdbOnlyPsyncTest extends AbstractRedisTest { | ||
|
||
@Mock | ||
private ReplicationStore replicationStore; | ||
|
||
@Mock | ||
private MetaStore metaStore; | ||
|
||
@Before | ||
public void beforeDefaultPsyncTest() throws Exception{ | ||
when(replicationStore.getMetaStore()).thenReturn(metaStore); | ||
when(replicationStore.getEndOffset()).thenReturn(-1L); | ||
|
||
} | ||
|
||
@Test | ||
public void testFreshRdbOnlyPsync() throws Exception { | ||
String replId = RunidGenerator.DEFAULT.generateRunid(); | ||
int offset = 100; | ||
Server redisServer = startServer(randomPort(), new Function<String, String>() { | ||
@Override | ||
public String apply(String s) { | ||
logger.info("[testFreshRdbOnlyPsync] {}", s); | ||
if (s.trim().equals("psync ? -3")) { | ||
return String.format("+FULLRESYNC %s %d\r\n", replId, offset); | ||
} else { | ||
return "+OK\r\n"; | ||
} | ||
} | ||
}); | ||
Endpoint redisEndpoint = new DefaultEndPoint("127.0.0.1", redisServer.getPort()); | ||
FreshRdbOnlyPsync psync = new FreshRdbOnlyPsync(NettyPoolUtil.createNettyPool(redisEndpoint), replicationStore, scheduled); | ||
|
||
CountDownLatch latch = new CountDownLatch(1); | ||
AtomicInteger masetrOffset = new AtomicInteger(0); | ||
psync.addPsyncObserver(new PsyncObserver() { | ||
@Override | ||
public void onFullSync(long masterRdbOffset) { | ||
masetrOffset.set((int)masterRdbOffset); | ||
latch.countDown(); | ||
} | ||
@Override | ||
public void reFullSync() { | ||
} | ||
@Override | ||
public void beginWriteRdb(EofType eofType, String replId, long masterRdbOffset) throws IOException { | ||
} | ||
@Override | ||
public void endWriteRdb() { | ||
} | ||
@Override | ||
public void onContinue(String requestReplId, String responseReplId) { | ||
} | ||
@Override | ||
public void onKeeperContinue(String replId, long beginOffset) { | ||
} | ||
@Override | ||
public void readAuxEnd(RdbStore rdbStore, Map<String, String> auxMap) { | ||
} | ||
}); | ||
psync.execute().addListener(new CommandFutureListener<Object>() { | ||
|
||
@Override | ||
public void operationComplete(CommandFuture<Object> commandFuture) throws Exception { | ||
if(!commandFuture.isSuccess()){ | ||
logger.error("[operationComplete]", commandFuture.cause()); | ||
} | ||
} | ||
}); | ||
|
||
latch.await(1000, TimeUnit.SECONDS); | ||
Assert.assertEquals(offset, masetrOffset.get()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
.../java/com/ctrip/xpipe/redis/keeper/exception/psync/KeeperTolerantClosePsyncException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.ctrip.xpipe.redis.keeper.exception.psync; | ||
|
||
import com.ctrip.xpipe.redis.keeper.monitor.PsyncFailReason; | ||
|
||
public class KeeperTolerantClosePsyncException extends PsyncRuntimeException { | ||
|
||
public KeeperTolerantClosePsyncException(PsyncRuntimeException e) { | ||
super("keeper tolerant:" + e.getMessage(), e); | ||
} | ||
|
||
@Override | ||
public PsyncFailReason toReason() { | ||
Throwable cause = getCause(); | ||
if (cause instanceof PsyncRuntimeException) return ((PsyncRuntimeException) cause).toReason(); | ||
else return super.toReason(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.