Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3077,7 +3077,8 @@ public static ShardId selectSplitShard(int shardId, IndexMetadata sourceIndexMet
}
final int routingFactor = getRoutingFactor(numSourceShards, numTargetShards);
assertSplitMetadata(numSourceShards, numTargetShards, sourceIndexMetadata);
return new ShardId(sourceIndexMetadata.getIndex(), shardId / routingFactor);
return new ShardId(sourceIndexMetadata.getIndex(), Math.floorMod(shardId, sourceIndexMetadata.getNumberOfShards()));
// return new ShardId(sourceIndexMetadata.getIndex(), shardId / routingFactor);
}

/**
Expand Down Expand Up @@ -3167,9 +3168,13 @@ public static Set<ShardId> selectShrinkShards(int shardId, IndexMetadata sourceI
}
int routingFactor = getRoutingFactor(sourceIndexMetadata.getNumberOfShards(), numTargetShards);
Set<ShardId> shards = Sets.newHashSetWithExpectedSize(routingFactor);
for (int i = shardId * routingFactor; i < routingFactor * shardId + routingFactor; i++) {
for (int i = shardId; i < sourceIndexMetadata.getNumberOfShards(); i += numTargetShards) {
assert Math.floorMod(i, numTargetShards) == shardId;
shards.add(new ShardId(sourceIndexMetadata.getIndex(), i));
}
for (int i = shardId * routingFactor; i < routingFactor * shardId + routingFactor; i++) {
// shards.add(new ShardId(sourceIndexMetadata.getIndex(), i));
}
return shards;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ public static IndexRouting fromIndexMetadata(IndexMetadata metadata) {
}

protected final String indexName;
private final int numberOfShards;
private final int routingNumShards;
private final int routingFactor;
@Nullable
private final IndexReshardingMetadata indexReshardingMetadata;

private IndexRouting(IndexMetadata metadata) {
this.indexName = metadata.getIndex().getName();
this.numberOfShards = metadata.getNumberOfShards();
this.routingNumShards = metadata.getRoutingNumShards();
this.routingFactor = metadata.getRoutingFactor();
this.indexReshardingMetadata = metadata.getReshardingMetadata();
Expand Down Expand Up @@ -142,6 +144,14 @@ public void postProcess(IndexRequest indexRequest) {}
* shard id.
*/
protected final int hashToShardId(int hash) {
return Math.floorMod(hash, numberOfShards);
}

/**
* Convert a hash generated from an {@code (id, routing}) pair into a
* shard id using the old routingNumShards mechanism.
*/
protected final int hashToShardIdOld(int hash) {
return Math.floorMod(hash, routingNumShards) / routingFactor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public void testPartitionedIndex() {
}
}

@AwaitsFix(bugUrl = "I believe it is valid that these change but need to check.")
public void testPartitionedIndexShrunk() {
Map<String, Map<String, Integer>> routingIdToShard = new HashMap<>();

Expand Down