Skip to content

Commit

Permalink
Make sure to close the index input of SegmentInfosSnapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
Sachin Kale committed Apr 16, 2024
1 parent ab44a4e commit 9fcb9da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 7 additions & 5 deletions server/src/main/java/org/opensearch/index/shard/IndexShard.java
Original file line number Diff line number Diff line change
Expand Up @@ -5054,11 +5054,13 @@ public void syncSegmentsFromRemoteSegmentStore(boolean overrideLocal, final Runn
.filter(file -> file.startsWith(RemoteSegmentStoreDirectory.SEGMENT_INFOS_SNAPSHOT_PREFIX))
.collect(Collectors.toList());
assert segmentInfosSnapshotFilenames.size() == 1;
infosSnapshot = SegmentInfos.readCommit(
store.directory(),
store.directory().openChecksumInput(segmentInfosSnapshotFilenames.get(0), IOContext.READ),
remoteSegmentMetadata.getGeneration()
);
try (ChecksumIndexInput segmentInfosInput = store.directory().openChecksumInput(segmentInfosSnapshotFilenames.get(0), IOContext.READ)) {
infosSnapshot = SegmentInfos.readCommit(
store.directory(),
segmentInfosInput,
remoteSegmentMetadata.getGeneration()
);
}
} else {
infosSnapshot = store.buildSegmentInfos(
remoteSegmentMetadata.getSegmentInfosBytes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.lucene.index.IndexFormatTooOldException;
import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.ChecksumIndexInput;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.opensearch.OpenSearchCorruptionException;
Expand Down Expand Up @@ -301,11 +302,13 @@ private void finalizeReplication(CheckpointInfoResponse checkpointInfoResponse)
.filter(file -> file.startsWith(RemoteSegmentStoreDirectory.SEGMENT_INFOS_SNAPSHOT_PREFIX))
.collect(Collectors.toList());
assert segmentInfosSnapshotFilenames.size() == 1;
infos = SegmentInfos.readCommit(
store.directory(),
store.directory().openChecksumInput(segmentInfosSnapshotFilenames.get(0), IOContext.READ),
checkpointInfoResponse.getCheckpoint().getSegmentsGen()
);
try (ChecksumIndexInput segmentInfosInput = store.directory().openChecksumInput(segmentInfosSnapshotFilenames.get(0), IOContext.READ)) {
infos = SegmentInfos.readCommit(
store.directory(),
segmentInfosInput,
checkpointInfoResponse.getCheckpoint().getSegmentsGen()
);
}
store.deleteQuiet(segmentInfosSnapshotFilenames.get(0));
} else {
infos = store.buildSegmentInfos(segmentInfosBytes, checkpointInfoResponse.getCheckpoint().getSegmentsGen());
Expand Down

0 comments on commit 9fcb9da

Please sign in to comment.