diff --git a/server/src/main/java/org/opensearch/index/engine/Engine.java b/server/src/main/java/org/opensearch/index/engine/Engine.java index a9054e5ca4122..e036280e947ce 100644 --- a/server/src/main/java/org/opensearch/index/engine/Engine.java +++ b/server/src/main/java/org/opensearch/index/engine/Engine.java @@ -1122,9 +1122,10 @@ public abstract void forceMerge( /** * Fetch a snapshot of the latest SegmentInfos from the engine and ensure that segment files are retained in the directory * until closed. - * @return {@link SegmentInfosRef} - A ref to segmentInfos that must be closed for segment files to be deleted. + * @return {@link GatedCloseable} - A wrapper around a {@link SegmentInfos} instance that must be closed for segment files + * to be deleted. */ - public SegmentInfosRef getLatestSegmentInfosSafe() { + public GatedCloseable getLatestSegmentInfosSafe() { return null; }; diff --git a/server/src/main/java/org/opensearch/index/engine/InternalEngine.java b/server/src/main/java/org/opensearch/index/engine/InternalEngine.java index f6ea1c73271dc..a42a157fd071b 100644 --- a/server/src/main/java/org/opensearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/opensearch/index/engine/InternalEngine.java @@ -2269,7 +2269,7 @@ public GatedCloseable acquireLastIndexCommit(final boolean flushFir } @Override - public SegmentInfosRef getLatestSegmentInfosSafe() { + public GatedCloseable getLatestSegmentInfosSafe() { assert (engineConfig.isReadOnly() == false); final SegmentInfos segmentInfos = getLatestSegmentInfos(); try { @@ -2277,7 +2277,7 @@ public SegmentInfosRef getLatestSegmentInfosSafe() { } catch (IOException e) { throw new EngineException(shardId, e.getMessage(), e); } - return new Engine.SegmentInfosRef(segmentInfos, () -> indexWriter.decRefDeleter(segmentInfos)); + return new GatedCloseable<>(segmentInfos, () -> indexWriter.decRefDeleter(segmentInfos)); } @Override 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 87984477e57e2..7720103085669 100644 --- a/server/src/main/java/org/opensearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/opensearch/index/shard/IndexShard.java @@ -1498,10 +1498,10 @@ public GatedCloseable acquireLastIndexCommit(boolean flushFirst) th /** * Fetch a ref to the latest SegmentInfos held by the engine. This ensures the files will not be deleted until * the ref is closed. - * @return {@link Engine.SegmentInfosRef} + * @return a {@link GatedCloseable} wrapper around a {@link SegmentInfos} instance * @throws EngineException - When infos cannot be retrieved from the Engine. */ - public Engine.SegmentInfosRef getLatestSegmentInfosSafe() throws EngineException { + public GatedCloseable getLatestSegmentInfosSafe() throws EngineException { return getEngine().getLatestSegmentInfosSafe(); } diff --git a/server/src/main/java/org/opensearch/indices/replication/copy/CopyState.java b/server/src/main/java/org/opensearch/indices/replication/copy/CopyState.java index 8b99b74b75a81..7d57cf8188d16 100644 --- a/server/src/main/java/org/opensearch/indices/replication/copy/CopyState.java +++ b/server/src/main/java/org/opensearch/indices/replication/copy/CopyState.java @@ -11,8 +11,8 @@ import org.apache.lucene.index.SegmentInfos; import org.apache.lucene.store.ByteBuffersDataOutput; import org.apache.lucene.store.ByteBuffersIndexOutput; +import org.opensearch.common.concurrent.GatedCloseable; import org.opensearch.common.util.concurrent.AbstractRefCounted; -import org.opensearch.index.engine.Engine; import org.opensearch.index.shard.IndexShard; import org.opensearch.index.store.Store; @@ -21,7 +21,7 @@ public class CopyState extends AbstractRefCounted { - private final Engine.SegmentInfosRef segmentInfosRef; + private final GatedCloseable segmentInfosRef; private final ReplicationCheckpoint checkpoint; private final Store.MetadataSnapshot metadataSnapshot; private final byte[] infosBytes; @@ -29,7 +29,7 @@ public class CopyState extends AbstractRefCounted { CopyState(IndexShard shard) throws IOException { super("replication-nrt-state"); this.segmentInfosRef = shard.getLatestSegmentInfosSafe(); - final SegmentInfos segmentInfos = segmentInfosRef.getSegmentInfos(); + final SegmentInfos segmentInfos = segmentInfosRef.get(); this.checkpoint = new ReplicationCheckpoint( shard.shardId(), shard.getOperationPrimaryTerm(),