-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Calculate routing num shards correctly during reshard #125601
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
Changes from 18 commits
671c348
7ae62e7
31281e5
ff98f8e
37d61fd
b29a437
eacb67a
0a15de3
86f66bc
41a70ba
44c9c4f
c8382c2
e77399d
2946f37
c21b9f5
33a8b45
a2de378
8d10925
fa25099
4886ff3
47ab570
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2000,17 +2000,13 @@ public Builder numberOfShards(int numberOfShards) { | |
| * Builder to create IndexMetadata that has an increased shard count (used for re-shard). | ||
| * The new shard count must be a multiple of the original shardcount. | ||
| * We do not support shrinking the shard count. | ||
| * @param shardCount updated shardCount | ||
| * | ||
| * TODO: Check if this.version needs to be incremented | ||
| * @param targetShardCount target shard count after resharding | ||
| */ | ||
| public Builder reshardAddShards(int shardCount) { | ||
| // Assert routingNumShards is null ? | ||
| // Assert numberOfShards > 0 | ||
| if (shardCount % numberOfShards() != 0) { | ||
| public Builder reshardAddShards(int targetShardCount, final int sourceNumShards) { | ||
|
||
| if (targetShardCount % numberOfShards() != 0) { | ||
| throw new IllegalArgumentException( | ||
| "New shard count [" | ||
| + shardCount | ||
| + targetShardCount | ||
| + "] should be a multiple" | ||
| + " of current shard count [" | ||
| + numberOfShards() | ||
|
|
@@ -2019,13 +2015,12 @@ public Builder reshardAddShards(int shardCount) { | |
| + "]" | ||
| ); | ||
| } | ||
| IndexVersion indexVersionCreated = indexCreatedVersion(settings); | ||
| settings = Settings.builder().put(settings).put(SETTING_NUMBER_OF_SHARDS, shardCount).build(); | ||
| var newPrimaryTerms = new long[shardCount]; | ||
| settings = Settings.builder().put(settings).put(SETTING_NUMBER_OF_SHARDS, targetShardCount).build(); | ||
| var newPrimaryTerms = new long[targetShardCount]; | ||
| Arrays.fill(newPrimaryTerms, this.primaryTerms.length, newPrimaryTerms.length, SequenceNumbers.UNASSIGNED_PRIMARY_TERM); | ||
| System.arraycopy(primaryTerms, 0, newPrimaryTerms, 0, this.primaryTerms.length); | ||
| primaryTerms = newPrimaryTerms; | ||
| routingNumShards = MetadataCreateIndexService.calculateNumRoutingShards(shardCount, indexVersionCreated); | ||
| routingNumShards = MetadataCreateIndexService.getIndexNumberOfRoutingShards(settings, sourceNumShards, this.routingNumShards); | ||
| return this; | ||
| } | ||
|
|
||
|
|
@@ -3034,7 +3029,7 @@ public static ShardId selectCloneShard(int shardId, IndexMetadata sourceIndexMet | |
| return new ShardId(sourceIndexMetadata.getIndex(), shardId); | ||
| } | ||
|
|
||
| private static void assertSplitMetadata(int numSourceShards, int numTargetShards, IndexMetadata sourceIndexMetadata) { | ||
| public static void assertSplitMetadata(int numSourceShards, int numTargetShards, IndexMetadata sourceIndexMetadata) { | ||
| if (numSourceShards > numTargetShards) { | ||
| throw new IllegalArgumentException( | ||
| "the number of source shards [" | ||
|
|
||
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.
isn't
sourceNumShardsextractable fromthis.settings? Passing it in opens the door to the same kind of inconsistency I was worried about before when we were passing in the whole metadata.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.
You are right. I think I might have finally got it right this time !
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.
Thanks! Sorry about all the iteration.