Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhat Sharma <[email protected]>
  • Loading branch information
Prabhat Sharma committed May 17, 2024
1 parent 15ebe3d commit c356f18
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,10 @@ public Builder putSplitSeedShardMetadata(int shardId, TreeSet<SplitShardMetadata
return this;
}

public Builder putSplitSeedShardMetadata(SplitShardMetadata splitShardMetadata) {
this.splitMetadata.putSplitSeedShardMetadata(splitShardMetadata);
return this;
}
public long version() {
return this.version;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public ClusterState applyShardSplitRequest(

SplitShardMetadata splitShardMetadata = curIndexMetadata.getSplitShardMetadata(sourceShardId.id());
splitShardMetadata.splitRange(request.getSplitInto(), maxUsedShardId);

indexMetadataBuilder.putSplitShardMetadata(splitShardMetadata);
indexMetadataBuilder.putSplitSeedShardMetadata(splitShardMetadata);
for(SplitShardMetadata range: splitShardMetadata.getEphemeralChildShardMetadata()) {
indexMetadataBuilder.putSplitShardMetadata(range);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public SplitMetadata() {
}

public SplitShardMetadata getSplitShardMetadata(int shardId) {
if(shardIdToRangeMap.containsKey(shardId)) {
return shardIdToRangeMap.get(shardId);
}
return new SplitShardMetadata(shardId, shardId);
return shardIdToRangeMap.getOrDefault(shardId, new SplitShardMetadata(shardId, shardId));
}

public void putSplitShardMetadata(SplitShardMetadata splitShardMetadata) {
Expand All @@ -52,6 +49,16 @@ public void putSplitSeedShardMetadata(int shardId, TreeSet<SplitShardMetadata> s
shardRanges.put(shardId, splitShardMetadata);
}

public void putSplitSeedShardMetadata(SplitShardMetadata splitShardMetadata) {
if (shardRanges.containsKey(splitShardMetadata.getPrimaryShardId())) {
shardRanges.get(splitShardMetadata.getPrimaryShardId()).add(splitShardMetadata);
} else {
TreeSet<SplitShardMetadata> splitSeedShardMetadata = new TreeSet<>();
splitSeedShardMetadata.add(splitShardMetadata);
shardRanges.put(splitShardMetadata.getPrimaryShardId(), splitSeedShardMetadata);
}
}

public SplitShardMetadata findShardRange(int shardId, int hash) {
return shardRanges.get(shardId).floor(new SplitShardMetadata(shardId, shardId, hash));
}
Expand All @@ -73,7 +80,7 @@ public void updateSplitMetadataForChildShards(int sourceShardId) {
for(SplitShardMetadata childRange: sourceShardRange.getEphemeralChildShardMetadata()) {
this.shardRanges.get(childRange.getPrimaryShardId()).add(childRange);
}
// Clear child shard ranges Todo: Ephemeral explaination
// Clear child shard ranges
sourceShardRange.getEphemeralChildShardMetadata().clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private static int calculateShardIdOfChild(IndexMetadata indexMetadata, String e
}
SplitShardMetadata shardRange = indexMetadata.findShardRange(shardId, rangeHash);

assert(shardRange == null || !shardRange.contains(rangeHash));
assert(shardRange != null || !shardRange.contains(rangeHash));

if(canIncludeChildShardIds.test(shardId) && shardRange.getEphemeralChildShardMetadata().size() > 0) {
return shardRange.findChildShardRange(rangeHash).getShardId();
Expand Down

0 comments on commit c356f18

Please sign in to comment.