-
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.
- Loading branch information
yifuzhou
committed
May 21, 2024
1 parent
a6c5302
commit 5a6ada8
Showing
27 changed files
with
454 additions
and
342 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
41 changes: 41 additions & 0 deletions
41
.../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,41 @@ | ||
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(); | ||
} | ||
this.future().setFailure(new Exception(String.format("keeper: %s is not %s", keeper, expectedActive))); | ||
} | ||
|
||
@Override | ||
protected void doReset() { | ||
|
||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...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,39 @@ | ||
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(); | ||
} | ||
this.future().setFailure(new Exception(String.format("ping %s has no pong response", keeper))); | ||
} | ||
|
||
@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
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<java.lang.Long>{ | ||
|
||
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() { | ||
|
||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...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,35 @@ | ||
package com.ctrip.xpipe.redis.console.keeper.Command; | ||
|
||
import com.ctrip.xpipe.command.AbstractCommand; | ||
import com.ctrip.xpipe.redis.console.service.KeeperContainerService; | ||
|
||
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.resetKeepers(activeKeeperIp, shardId); | ||
this.future().setSuccess(); | ||
} | ||
|
||
@Override | ||
protected void doReset() { | ||
|
||
} | ||
} |
Oops, something went wrong.