-
Notifications
You must be signed in to change notification settings - Fork 504
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 #784 from ctripcorp/feature/rebalance-keeper
Feature/rebalance keeper
- Loading branch information
Showing
43 changed files
with
844 additions
and
389 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
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
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
37 changes: 37 additions & 0 deletions
37
...ole/src/main/java/com/ctrip/xpipe/redis/console/keeper/Command/AbstractKeeperCommand.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,37 @@ | ||
package com.ctrip.xpipe.redis.console.keeper.Command; | ||
|
||
import com.ctrip.framework.xpipe.redis.ProxyRegistry; | ||
import com.ctrip.xpipe.api.endpoint.Endpoint; | ||
import com.ctrip.xpipe.api.pool.SimpleObjectPool; | ||
import com.ctrip.xpipe.command.AbstractCommand; | ||
import com.ctrip.xpipe.netty.commands.NettyClient; | ||
import com.ctrip.xpipe.pool.XpipeNettyClientKeyedObjectPool; | ||
import com.ctrip.xpipe.redis.core.protocal.cmd.AbstractRedisCommand; | ||
import com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand; | ||
import com.ctrip.xpipe.utils.VisibleForTesting; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
public abstract class AbstractKeeperCommand<V> extends AbstractCommand<V> { | ||
|
||
protected XpipeNettyClientKeyedObjectPool keyedObjectPool; | ||
|
||
protected ScheduledExecutorService scheduled; | ||
|
||
protected static final Logger logger = LoggerFactory.getLogger(AbstractKeeperCommand.class); | ||
|
||
private int commandTimeOut = Integer.parseInt(System.getProperty("KEY_REDISSESSION_COMMAND_TIMEOUT", String.valueOf(AbstractRedisCommand.DEFAULT_REDIS_COMMAND_TIME_OUT_MILLI))); | ||
|
||
protected AbstractKeeperCommand(XpipeNettyClientKeyedObjectPool keyedObjectPool, ScheduledExecutorService scheduled) { | ||
this.keyedObjectPool = keyedObjectPool; | ||
this.scheduled = scheduled; | ||
} | ||
|
||
protected InfoCommand generateInfoReplicationCommand(Endpoint key) { | ||
SimpleObjectPool<NettyClient> keyPool = keyedObjectPool.getKeyPool(key); | ||
return new InfoCommand(keyPool, InfoCommand.INFO_TYPE.REPLICATION.cmd(), scheduled, commandTimeOut); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
.../src/main/java/com/ctrip/xpipe/redis/console/keeper/Command/CheckKeeperActiveCommand.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,42 @@ | ||
package com.ctrip.xpipe.redis.console.keeper.Command; | ||
|
||
import com.ctrip.xpipe.api.endpoint.Endpoint; | ||
import com.ctrip.xpipe.pool.XpipeNettyClientKeyedObjectPool; | ||
import com.ctrip.xpipe.redis.core.protocal.cmd.InfoCommand; | ||
import com.ctrip.xpipe.redis.core.protocal.cmd.InfoResultExtractor; | ||
import com.ctrip.xpipe.utils.VisibleForTesting; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
public class CheckKeeperActiveCommand<T> extends AbstractKeeperCommand<T>{ | ||
|
||
private Endpoint keeper; | ||
|
||
private boolean expectedActive; | ||
|
||
public CheckKeeperActiveCommand(XpipeNettyClientKeyedObjectPool keyedObjectPool, ScheduledExecutorService scheduled, Endpoint keeper, boolean expectedActive) { | ||
super(keyedObjectPool, scheduled); | ||
this.keeper = keeper; | ||
this.expectedActive = expectedActive; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "CheckKeeperActiveCommand"; | ||
} | ||
|
||
@Override | ||
protected void doExecute() throws Throwable { | ||
InfoCommand infoCommand = generateInfoReplicationCommand(keeper); | ||
if (new InfoResultExtractor(infoCommand.execute().get()).isKeeperActive() == expectedActive) { | ||
this.future().setSuccess(); | ||
return; | ||
} | ||
this.future().setFailure(new Exception(String.format("keeper: %s is not %s", keeper, expectedActive))); | ||
} | ||
|
||
@Override | ||
protected void doReset() { | ||
|
||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...c/main/java/com/ctrip/xpipe/redis/console/keeper/Command/CheckKeeperConnectedCommand.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,40 @@ | ||
package com.ctrip.xpipe.redis.console.keeper.Command; | ||
|
||
import com.ctrip.xpipe.api.endpoint.Endpoint; | ||
import com.ctrip.xpipe.pool.XpipeNettyClientKeyedObjectPool; | ||
import com.ctrip.xpipe.redis.core.protocal.cmd.RoleCommand; | ||
import com.ctrip.xpipe.redis.core.protocal.pojo.SlaveRole; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
import static com.ctrip.xpipe.redis.core.protocal.MASTER_STATE.REDIS_REPL_CONNECTED; | ||
|
||
public class CheckKeeperConnectedCommand<T> extends AbstractKeeperCommand<T> { | ||
|
||
private Endpoint keeper; | ||
|
||
public CheckKeeperConnectedCommand(XpipeNettyClientKeyedObjectPool keyedObjectPool, ScheduledExecutorService scheduled, Endpoint keeper) { | ||
super(keyedObjectPool, scheduled); | ||
this.keeper = keeper; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "CheckKeeperConnectedCommand"; | ||
} | ||
|
||
@Override | ||
protected void doExecute() throws Throwable { | ||
SlaveRole role = (SlaveRole)new RoleCommand(keyedObjectPool.getKeyPool(keeper), scheduled).execute().get(); | ||
if (REDIS_REPL_CONNECTED == role.getMasterState()) { | ||
this.future().setSuccess(); | ||
return; | ||
} | ||
this.future().setFailure(new Exception(String.format("ping %s has no pong response", keeper))); | ||
} | ||
|
||
@Override | ||
protected void doReset() { | ||
|
||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...sole/src/main/java/com/ctrip/xpipe/redis/console/keeper/Command/FullSyncJudgeCommand.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,47 @@ | ||
package com.ctrip.xpipe.redis.console.keeper.Command; | ||
|
||
import com.ctrip.xpipe.api.endpoint.Endpoint; | ||
import com.ctrip.xpipe.pool.XpipeNettyClientKeyedObjectPool; | ||
import com.ctrip.xpipe.redis.core.protocal.cmd.InfoResultExtractor; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
public class FullSyncJudgeCommand<T> extends AbstractKeeperCommand<T> { | ||
|
||
private Endpoint activeInstance; | ||
|
||
private Endpoint backUpInstance; | ||
|
||
private long activeMasterReplOffset; | ||
|
||
public FullSyncJudgeCommand(XpipeNettyClientKeyedObjectPool keyedObjectPool, ScheduledExecutorService scheduled, Endpoint activeInstance, Endpoint backUpInstance, long activeMasterReplOffset) { | ||
super(keyedObjectPool, scheduled); | ||
this.activeInstance = activeInstance; | ||
this.backUpInstance = backUpInstance; | ||
this.activeMasterReplOffset = activeMasterReplOffset; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "FullSyncJudgeCommand"; | ||
} | ||
|
||
@Override | ||
protected void doExecute() throws Throwable { | ||
long backupMasterReplOffset; | ||
backupMasterReplOffset = new InfoResultExtractor(generateInfoReplicationCommand(backUpInstance).execute().get()).getMasterReplOffset(); | ||
if (backupMasterReplOffset > 0 && activeMasterReplOffset > 0 && backupMasterReplOffset > activeMasterReplOffset) { | ||
this.future().setSuccess(); | ||
return; | ||
} | ||
this.future().setFailure(new Exception(String.format("activeInstance: %s and backUpInstance %s is not full sync", activeInstance, backUpInstance))); | ||
} | ||
|
||
@Override | ||
protected void doReset() { | ||
|
||
} | ||
|
||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...ava/com/ctrip/xpipe/redis/console/keeper/Command/KeeperContainerReplOffsetGetCommand.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,32 @@ | ||
package com.ctrip.xpipe.redis.console.keeper.Command; | ||
|
||
import com.ctrip.xpipe.api.endpoint.Endpoint; | ||
import com.ctrip.xpipe.pool.XpipeNettyClientKeyedObjectPool; | ||
import com.ctrip.xpipe.redis.core.protocal.cmd.InfoResultExtractor; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
public class KeeperContainerReplOffsetGetCommand<V> extends AbstractKeeperCommand<Object>{ | ||
|
||
private Endpoint keeper; | ||
|
||
public KeeperContainerReplOffsetGetCommand(XpipeNettyClientKeyedObjectPool keyedObjectPool, ScheduledExecutorService scheduled, Endpoint keeper) { | ||
super(keyedObjectPool, scheduled); | ||
this.keeper = keeper; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "KeeperContainerReplOffsetGetCommand"; | ||
} | ||
|
||
@Override | ||
protected void doExecute() throws Throwable { | ||
this.future().setSuccess(new InfoResultExtractor(generateInfoReplicationCommand(keeper).execute().get()).getMasterReplOffset()); | ||
} | ||
|
||
@Override | ||
protected void doReset() { | ||
|
||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...onsole/src/main/java/com/ctrip/xpipe/redis/console/keeper/Command/KeeperResetCommand.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,37 @@ | ||
package com.ctrip.xpipe.redis.console.keeper.Command; | ||
|
||
import com.ctrip.xpipe.command.AbstractCommand; | ||
import com.ctrip.xpipe.redis.console.service.KeeperContainerService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class KeeperResetCommand<T> extends AbstractCommand<T> { | ||
|
||
private String activeKeeperIp; | ||
|
||
private long shardId; | ||
|
||
private KeeperContainerService keeperContainerService; | ||
|
||
public KeeperResetCommand(String activeKeeperIp, long shardId, KeeperContainerService keeperContainerService) { | ||
this.activeKeeperIp = activeKeeperIp; | ||
this.shardId = shardId; | ||
this.keeperContainerService = keeperContainerService; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "KeeperResetCommand"; | ||
} | ||
|
||
@Override | ||
protected void doExecute() throws Throwable { | ||
keeperContainerService.resetKeeper(activeKeeperIp, shardId); | ||
this.future().setSuccess(); | ||
} | ||
|
||
@Override | ||
protected void doReset() { | ||
|
||
} | ||
} |
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.