-
Notifications
You must be signed in to change notification settings - Fork 508
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 #760 from ctripcorp/bugfix/cluster-type-change
no recreating cluster after clusterType changed
- Loading branch information
Showing
11 changed files
with
148 additions
and
82 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
6 changes: 6 additions & 0 deletions
6
...c/main/java/com/ctrip/xpipe/redis/meta/server/crdt/master/MasterChooseCommandFactory.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
57 changes: 57 additions & 0 deletions
57
...va/com/ctrip/xpipe/redis/meta/server/crdt/master/command/RedundantMasterClearCommand.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,57 @@ | ||
package com.ctrip.xpipe.redis.meta.server.crdt.master.command; | ||
|
||
import com.ctrip.xpipe.command.AbstractCommand; | ||
import com.ctrip.xpipe.redis.meta.server.meta.CurrentMetaManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/22 | ||
*/ | ||
public class RedundantMasterClearCommand extends AbstractCommand<Set<String>> { | ||
|
||
private Long clusterId; | ||
|
||
private Long shardId; | ||
|
||
private Set<String> dcs; | ||
|
||
private CurrentMetaManager currentMetaManager; | ||
|
||
private static Logger logger = LoggerFactory.getLogger(RedundantMasterClearCommand.class); | ||
|
||
public RedundantMasterClearCommand(Long clusterId, Long shardId, Set<String> dcs, CurrentMetaManager currentMetaManager) { | ||
this.clusterId = clusterId; | ||
this.shardId = shardId; | ||
this.dcs = dcs; | ||
this.currentMetaManager = currentMetaManager; | ||
} | ||
|
||
@Override | ||
protected void doExecute() throws Throwable { | ||
Set<String> currentDcs = currentMetaManager.getUpstreamPeerDcs(clusterId, shardId); | ||
Set<String> redundantDcs = new HashSet<>(currentDcs); | ||
redundantDcs.removeAll(dcs); | ||
|
||
for (String dc: redundantDcs) { | ||
logger.info("[cluster_{},shard_{}] remove dc {}", clusterId, shardId, dc); | ||
currentMetaManager.removePeerMaster(dc, clusterId, shardId); | ||
} | ||
|
||
future().setSuccess(redundantDcs); | ||
} | ||
|
||
@Override | ||
protected void doReset() { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return String.format("%s[cluster_%d,shard_%d]", getClass().getSimpleName(), clusterId, shardId); | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
...om/ctrip/xpipe/redis/meta/server/crdt/master/command/RedundantMasterClearCommandTest.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,51 @@ | ||
package com.ctrip.xpipe.redis.meta.server.crdt.master.command; | ||
|
||
import com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest; | ||
import com.ctrip.xpipe.redis.meta.server.meta.CurrentMetaManager; | ||
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.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/22 | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class RedundantMasterClearCommandTest extends AbstractMetaServerTest { | ||
|
||
@Mock | ||
private CurrentMetaManager currentMetaManager; | ||
|
||
@Before | ||
public void setupRedundantMasterClearCommandTest() { | ||
when(currentMetaManager.getUpstreamPeerDcs(getClusterDbId(), getShardDbId())) | ||
.thenReturn(new HashSet<>(Arrays.asList("jq", "oy"))); | ||
} | ||
|
||
@Test | ||
public void testClearRedundant() throws Exception { | ||
RedundantMasterClearCommand command = new RedundantMasterClearCommand(getClusterDbId(), getShardDbId(), | ||
new HashSet<>(Arrays.asList("jq", "rb")), currentMetaManager); | ||
Assert.assertEquals(Collections.singleton("oy"), command.execute().get()); | ||
verify(currentMetaManager, times(1)).removePeerMaster("oy", getClusterDbId(), getShardDbId()); | ||
} | ||
|
||
@Test | ||
public void testNoRedundant() throws Exception { | ||
RedundantMasterClearCommand command = new RedundantMasterClearCommand(getClusterDbId(), getShardDbId(), | ||
new HashSet<>(Arrays.asList("jq", "oy")), currentMetaManager); | ||
Assert.assertEquals(Collections.emptySet(), command.execute().get()); | ||
verify(currentMetaManager, never()).removePeerMaster(anyString(), any(), any()); | ||
} | ||
|
||
} |
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