-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Simulate shard moves using cluster_concurrent_rebalance=2 #93977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
idegtiarenko
merged 8 commits into
elastic:main
from
idegtiarenko:concurrent_recoveries
Feb 23, 2023
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c2a47d8
Simulate moves using cluster_concurrent_rebalance=1
idegtiarenko 67d1b16
Update docs/changelog/93977.yaml
idegtiarenko 9884c33
add a message
idegtiarenko a9c737e
rename the test
idegtiarenko b85afb0
fix shard allocator for test
idegtiarenko e5e5858
Merge branch 'main' into concurrent_recoveries
idegtiarenko fdc35cc
set to 1
idegtiarenko eb39af1
Merge branch 'main' into concurrent_recoveries
idegtiarenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
pr: 93977 | ||
summary: Simulate moves using cluster_concurrent_rebalance=1 | ||
area: Allocation | ||
type: enhancement | ||
issues: [] |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -12,16 +12,27 @@ | |
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.ESAllocationTestCase; | ||
import org.elasticsearch.cluster.TestShardRoutingRoleStrategies; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.metadata.Metadata; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
import org.elasticsearch.cluster.routing.AllocationId; | ||
import org.elasticsearch.cluster.routing.IndexRoutingTable; | ||
import org.elasticsearch.cluster.routing.RoutingNodes; | ||
import org.elasticsearch.cluster.routing.RoutingTable; | ||
import org.elasticsearch.cluster.routing.ShardRoutingState; | ||
import org.elasticsearch.cluster.routing.TestShardRouting; | ||
import org.elasticsearch.cluster.routing.allocation.allocator.DesiredBalanceShardsAllocator; | ||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider; | ||
import org.elasticsearch.common.UUIDs; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.shard.ShardId; | ||
|
||
import java.util.Set; | ||
import java.util.function.IntFunction; | ||
|
||
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; | ||
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; | ||
|
@@ -440,4 +451,79 @@ public void testBalanceAllNodesStartedAddIndex() { | |
assertThat(routingNodes.node("node2").shardsWithState("test1", STARTED).count(), equalTo(2L)); | ||
assertThat(routingNodes.node("node3").shardsWithState("test1", STARTED).count(), equalTo(2L)); | ||
} | ||
|
||
/** | ||
* {@see https://github.com/elastic/elasticsearch/issues/87279} | ||
*/ | ||
public void testRebalanceShouldNotPerformUnnecessaryMovesWithMultipleConcurrentRebalances() { | ||
final var settings = Settings.builder() | ||
.put("cluster.routing.allocation.cluster_concurrent_rebalance", randomIntBetween(3, 9)) | ||
.build(); | ||
final var allocationService = createAllocationService(settings); | ||
assumeTrue( | ||
"Only fixed in DesiredBalanceShardsAllocator", | ||
allocationService.shardsAllocator instanceof DesiredBalanceShardsAllocator | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nicer to change it so that |
||
|
||
final var discoveryNodesBuilder = DiscoveryNodes.builder(); | ||
for (int nodeIndex = 0; nodeIndex < 3; nodeIndex++) { | ||
discoveryNodesBuilder.add(newNode("node-" + nodeIndex)); | ||
} | ||
|
||
final var metadataBuilder = Metadata.builder(); | ||
final var routingTableBuilder = RoutingTable.builder(); | ||
|
||
addIndex(metadataBuilder, routingTableBuilder, "index-0", 4, shardId -> "node-" + (shardId / 2)); | ||
addIndex(metadataBuilder, routingTableBuilder, "index-1", 4, shardId -> "node-" + (shardId / 2)); | ||
addIndex(metadataBuilder, routingTableBuilder, "index-2", 1, shardId -> "node-2"); | ||
|
||
final var clusterState = ClusterState.builder(ClusterName.DEFAULT) | ||
.nodes(discoveryNodesBuilder) | ||
.metadata(metadataBuilder) | ||
.routingTable(routingTableBuilder) | ||
.build(); | ||
|
||
final var reroutedState = applyStartedShardsUntilNoChange(clusterState, allocationService); | ||
// node-0 and node-1 has 4 shards each. node-2 has only [index-2][0]. It should not be moved to achieve even balance. | ||
assertThat(reroutedState.getRoutingTable().index("index-2").shard(0).primaryShard().currentNodeId(), equalTo("node-2")); | ||
} | ||
|
||
private static void addIndex( | ||
Metadata.Builder metadataBuilder, | ||
RoutingTable.Builder routingTableBuilder, | ||
String indexName, | ||
int numberOfShards, | ||
IntFunction<String> assignmentFunction | ||
) { | ||
final var inSyncIds = randomList(numberOfShards, numberOfShards, () -> UUIDs.randomBase64UUID(random())); | ||
final var indexMetadataBuilder = IndexMetadata.builder(indexName) | ||
.settings( | ||
Settings.builder() | ||
.put("index.number_of_shards", numberOfShards) | ||
.put("index.number_of_replicas", 0) | ||
.put("index.version.created", Version.CURRENT) | ||
.build() | ||
); | ||
for (int shardId = 0; shardId < numberOfShards; shardId++) { | ||
indexMetadataBuilder.putInSyncAllocationIds(shardId, Set.of(inSyncIds.get(shardId))); | ||
} | ||
metadataBuilder.put(indexMetadataBuilder); | ||
final var indexId = metadataBuilder.get(indexName).getIndex(); | ||
final var indexRoutingTableBuilder = IndexRoutingTable.builder(indexId); | ||
|
||
for (int shardId = 0; shardId < numberOfShards; shardId++) { | ||
indexRoutingTableBuilder.addShard( | ||
TestShardRouting.newShardRouting( | ||
new ShardId(indexId, shardId), | ||
assignmentFunction.apply(shardId), | ||
null, | ||
true, | ||
ShardRoutingState.STARTED, | ||
AllocationId.newInitializing(inSyncIds.get(shardId)) | ||
) | ||
); | ||
} | ||
|
||
routingTableBuilder.add(indexRoutingTableBuilder); | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use
2
here just for consistency with the past default behaviour? I think I've seen odd things happening at1
sometimes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance you could describe or link some of them?
May be we could add some tests for them and assess the better value