use of com.ctrip.xpipe.redis.core.store.ReplicationStore in project x-pipe by ctripcorp.
the class DefaultReplicationStoreManager method destroy.
@Override
public void destroy() throws Exception {
logger.info("[destroy]{}", this);
ReplicationStore currentReplicationStore = getCurrent();
if (currentReplicationStore != null) {
try {
currentReplicationStore.destroy();
} catch (Throwable th) {
logger.error("[destroy]", th);
}
}
FileUtils.recursiveDelete(this.baseDir);
}
use of com.ctrip.xpipe.redis.core.store.ReplicationStore in project x-pipe by ctripcorp.
the class DefaultReplicationStoreManager method gc.
protected synchronized void gc() throws IOException {
logger.debug("[gc]{}", this);
gcCount.incrementAndGet();
Properties meta = currentMeta(true);
final String currentDirName;
if (meta != null) {
currentDirName = meta.getProperty(LATEST_STORE_DIR);
File[] replicationStoreDirs = baseDir.listFiles(new FileFilter() {
@Override
public boolean accept(File path) {
return path.isDirectory() && !currentDirName.equals(path.getName());
}
});
if (replicationStoreDirs != null && replicationStoreDirs.length > 0) {
logger.info("[GC][old replicationstore]newest:{}", currentDirName);
for (File dir : replicationStoreDirs) {
if (System.currentTimeMillis() - dir.lastModified() > keeperConfig.getReplicationStoreMinTimeMilliToGcAfterCreate()) {
logger.info("[GC] directory {}", dir.getCanonicalPath());
FileUtils.recursiveDelete(dir);
} else {
logger.warn("[GC][directory is created too short, do not gc]{}, {}", dir, new Date(dir.lastModified()));
}
}
}
}
// gc current ReplicationStore
ReplicationStore replicationStore = getCurrent();
if (replicationStore != null) {
replicationStore.gc();
}
}
use of com.ctrip.xpipe.redis.core.store.ReplicationStore in project x-pipe by ctripcorp.
the class InfoHandler method replication.
private void replication(boolean isDefault, boolean isAll, String section, StringBuilder sb, RedisKeeperServer redisKeeperServer) {
if (isDefault || isAll || "replication".equalsIgnoreCase(section)) {
ReplicationStore replicationStore = redisKeeperServer.getReplicationStore();
long slaveReplOffset = replicationStore.getEndOffset();
KeeperRepl keeperRepl = redisKeeperServer.getKeeperRepl();
sb.append("# Replication" + RedisProtocol.CRLF);
sb.append("role:" + Server.SERVER_ROLE.SLAVE + RedisProtocol.CRLF);
sb.append(RedisProtocol.KEEPER_ROLE_PREFIX + ":" + redisKeeperServer.role() + RedisProtocol.CRLF);
sb.append("state:" + redisKeeperServer.getRedisKeeperServerState().keeperState() + RedisProtocol.CRLF);
RedisMaster redisMaster = redisKeeperServer.getRedisMaster();
String masterHost = redisMaster == null ? null : redisMaster.masterEndPoint().getHost();
Integer masterPort = redisMaster == null ? null : redisMaster.masterEndPoint().getPort();
if (masterHost != null) {
sb.append("master_host:" + masterHost + RedisProtocol.CRLF);
sb.append("master_port:" + masterPort + RedisProtocol.CRLF);
/**
* If not report master link status as up, then sentinal is found crashed
* when sentinel is doing slaveof new_master_ip new_master_port
*/
sb.append("master_link_status:up" + RedisProtocol.CRLF);
}
/**
* To make sure keeper is the least option to be the new master when master is down
*/
sb.append("slave_repl_offset:" + slaveReplOffset + RedisProtocol.CRLF);
sb.append("slave_priority:0" + RedisProtocol.CRLF);
Set<RedisSlave> slaves = redisKeeperServer.slaves();
sb.append("connected_slaves:" + slaves.size() + RedisProtocol.CRLF);
int slaveIndex = 0;
for (RedisSlave slave : slaves) {
sb.append(String.format("slave%d:%s" + RedisProtocol.CRLF, slaveIndex, slave.info()));
slaveIndex++;
}
long beginOffset = keeperRepl.getBeginOffset();
MetaStore metaStore = replicationStore.getMetaStore();
String replid = metaStore == null ? ReplicationStoreMeta.EMPTY_REPL_ID : metaStore.getReplId();
String replid2 = metaStore == null ? ReplicationStoreMeta.EMPTY_REPL_ID : metaStore.getReplId2();
long secondReplIdOffset = metaStore == null ? ReplicationStoreMeta.DEFAULT_SECOND_REPLID_OFFSET : metaStore.getSecondReplIdOffset();
if (replid == null) {
replid = ReplicationStoreMeta.EMPTY_REPL_ID;
}
if (replid2 == null) {
replid2 = ReplicationStoreMeta.EMPTY_REPL_ID;
}
sb.append("master_replid:" + replid + RedisProtocol.CRLF);
sb.append("master_replid2:" + replid2 + RedisProtocol.CRLF);
sb.append("master_repl_offset:" + keeperRepl.getEndOffset() + RedisProtocol.CRLF);
sb.append("second_repl_offset:" + secondReplIdOffset + RedisProtocol.CRLF);
sb.append("repl_backlog_active:1" + RedisProtocol.CRLF);
sb.append("repl_backlog_first_byte_offset:" + beginOffset + RedisProtocol.CRLF);
try {
long endOffset = keeperRepl.getEndOffset();
sb.append("master_repl_offset:" + endOffset + RedisProtocol.CRLF);
sb.append("repl_backlog_size:" + (endOffset - beginOffset + 1) + RedisProtocol.CRLF);
sb.append("repl_backlog_histlen:" + (endOffset - beginOffset + 1) + RedisProtocol.CRLF);
} catch (Throwable ex) {
sb.append("error_message:" + ex.getMessage() + RedisProtocol.CRLF);
logger.info("Cannot calculate end offset", ex);
}
}
}
use of com.ctrip.xpipe.redis.core.store.ReplicationStore in project x-pipe by ctripcorp.
the class RedisKeeperServerStateActive method masterChanged.
@SuppressWarnings("deprecation")
public RedisMeta masterChanged(long keeperOffset, DefaultEndPoint newMasterEndpoint, String newMasterRunid, long newMasterReplOffset) throws IOException {
ReplicationStore replicationStore = redisKeeperServer.getReplicationStore();
replicationStore.getMetaStore().masterChanged(keeperOffset, newMasterEndpoint, newMasterRunid, newMasterReplOffset);
RedisMeta redisMeta = new RedisMeta();
redisMeta.setIp(newMasterEndpoint.getHost());
redisMeta.setPort(newMasterEndpoint.getPort());
return redisMeta;
}
use of com.ctrip.xpipe.redis.core.store.ReplicationStore in project x-pipe by ctripcorp.
the class DefaultRedisKeeperServerConnectToFakeRedisTest method testReplicationData.
@Test
public void testReplicationData() throws Exception {
RedisKeeperServer redisKeeperServer = startRedisKeeperServerAndConnectToFakeRedis();
sleep(1500);
logger.info(remarkableMessage("[testReplicationData][read replication store]"));
ReplicationStore replicationStore = redisKeeperServer.getReplicationStore();
String rdbContent = readRdbFileTilEnd(replicationStore);
Assert.assertEquals(fakeRedisServer.getRdbContent(), rdbContent);
String commands = readCommandFileTilEnd(replicationStore, fakeRedisServer.currentCommands().length());
Assert.assertEquals(fakeRedisServer.currentCommands(), commands);
}
Aggregations