Skip to content

Commit

Permalink
Fixing variable names
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Garg <gkharsh@amazon.com>
  • Loading branch information
Harsh Garg committed Aug 30, 2024
1 parent 637dccb commit 241ca48
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,30 @@ public Map<String, IndexSegments> getIndices() {
if (indicesSegments != null) {
return indicesSegments;
}

Arrays.sort(shards, Comparator.comparing(shardSegment -> shardSegment.getShardRouting().getIndexName()));
Map<String, IndexSegments> indicesSegments = new HashMap<>();
if (shards.length == 0) {
this.indicesSegments = indicesSegments;
return indicesSegments;
}

int lastIdx = 0;
Arrays.sort(shards, Comparator.comparing(shardSegment -> shardSegment.getShardRouting().getIndexName()));
int startIndexPos = 0;
String startIndexName = shards[startIndexPos].getShardRouting().getIndexName();
for (int i = 0; i < shards.length; i++) {
String lastIndexName = shards[lastIdx].getShardRouting().getIndexName();
String currentIndexName = shards[i].getShardRouting().getIndexName();
if (!currentIndexName.equals(lastIndexName)) {
indicesSegments.put(lastIndexName, new IndexSegments(lastIndexName, Arrays.copyOfRange(shards, lastIdx, i)));
lastIdx = i;
}
if (i == shards.length - 1) {
indicesSegments.put(currentIndexName, new IndexSegments(currentIndexName, Arrays.copyOfRange(shards, lastIdx, i + 1)));
if (!shards[i].getShardRouting().getIndexName().equals(startIndexName)) {
indicesSegments.put(startIndexName, new IndexSegments(startIndexName, Arrays.copyOfRange(shards, startIndexPos, i)));
startIndexPos = i;
startIndexName = shards[startIndexPos].getShardRouting().getIndexName();
}
}
// Add the last shardSegment from shards list which would have got missed in the loop above
indicesSegments.put(
shards[shards.length - 1].getShardRouting().getIndexName(),
new IndexSegments(
shards[shards.length - 1].getShardRouting().getIndexName(),
Arrays.copyOfRange(shards, startIndexPos, shards.length)
)
);

this.indicesSegments = indicesSegments;
return indicesSegments;
Expand Down

0 comments on commit 241ca48

Please sign in to comment.