Skip to content

Commit

Permalink
Compute shard generations differently for V2 as it was coming out to …
Browse files Browse the repository at this point in the history
…be null

Signed-off-by: Gaurav Bafna <gbbafna@amazon.com>
  • Loading branch information
gbbafna committed Oct 16, 2024
1 parent f36691d commit 833f327
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, final Cl
}

Check warning on line 998 in server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/snapshots/SnapshotsService.java#L994-L998

Added lines #L994 - L998 were not covered by tests
);
metadataListener.whenComplete(meta -> {
ShardGenerations shardGenerations = buildGenerations(newEntry, meta);
ShardGenerations shardGenerations = buildGenerationsV2(newEntry, meta);

Check warning on line 1001 in server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/snapshots/SnapshotsService.java#L1000-L1001

Added lines #L1000 - L1001 were not covered by tests
repository.finalizeSnapshot(
shardGenerations,
repositoryData.getGenId(),
Expand Down Expand Up @@ -1552,6 +1552,17 @@ private static ShardGenerations buildGenerations(SnapshotsInProgress.Entry snaps
return builder.build();
}

private static ShardGenerations buildGenerationsV2(SnapshotsInProgress.Entry snapshot, Metadata metadata) {
ShardGenerations.Builder builder = ShardGenerations.builder();
snapshot.indices().forEach(indexId -> {
int shardCount = metadata.index(indexId.getName()).getNumberOfShards();

Check warning on line 1558 in server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/snapshots/SnapshotsService.java#L1556-L1558

Added lines #L1556 - L1558 were not covered by tests
for (int i = 0; i < shardCount; i++) {
builder.put(indexId, i, null);

Check warning on line 1560 in server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/snapshots/SnapshotsService.java#L1560

Added line #L1560 was not covered by tests
}
});
return builder.build();

Check warning on line 1563 in server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/snapshots/SnapshotsService.java#L1562-L1563

Added lines #L1562 - L1563 were not covered by tests
}

private static Metadata metadataForSnapshot(
Metadata metadata,
boolean includeGlobalState,
Expand Down

0 comments on commit 833f327

Please sign in to comment.