From a2cb249c83e9251dbd3b9c6d37aee19877544218 Mon Sep 17 00:00:00 2001 From: Sachin Kale Date: Thu, 11 Apr 2024 11:27:49 +0530 Subject: [PATCH] Make sure to close the index input of SegmentInfosSnapshot Signed-off-by: Sachin Kale --- .../java/org/opensearch/index/shard/IndexShard.java | 12 +++++++----- .../replication/SegmentReplicationTarget.java | 13 ++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/shard/IndexShard.java b/server/src/main/java/org/opensearch/index/shard/IndexShard.java index 7a32730873bfc..d0edb75e9cec3 100644 --- a/server/src/main/java/org/opensearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/opensearch/index/shard/IndexShard.java @@ -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(), diff --git a/server/src/main/java/org/opensearch/indices/replication/SegmentReplicationTarget.java b/server/src/main/java/org/opensearch/indices/replication/SegmentReplicationTarget.java index 3d5f97dbfb098..3bbc124aae3a7 100644 --- a/server/src/main/java/org/opensearch/indices/replication/SegmentReplicationTarget.java +++ b/server/src/main/java/org/opensearch/indices/replication/SegmentReplicationTarget.java @@ -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; @@ -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());