Skip to content

Commit

Permalink
Removing the SegmentInfosRef class
Browse files Browse the repository at this point in the history
As with the now-deleted IndexCommitRef class, this wrapper class is not needed. It has been replaced with a GatedCloseable instance wrapping a SegmentInfos

Signed-off-by: Kartik Ganesh <[email protected]>
  • Loading branch information
kartg committed Mar 10, 2022
1 parent 1da0896 commit 20e3c64
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions server/src/main/java/org/opensearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<SegmentInfos> getLatestSegmentInfosSafe() {
return null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2269,15 +2269,15 @@ public GatedCloseable<IndexCommit> acquireLastIndexCommit(final boolean flushFir
}

@Override
public SegmentInfosRef getLatestSegmentInfosSafe() {
public GatedCloseable<SegmentInfos> getLatestSegmentInfosSafe() {
assert (engineConfig.isReadOnly() == false);
final SegmentInfos segmentInfos = getLatestSegmentInfos();
try {
indexWriter.incRefDeleter(segmentInfos);
} 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1498,10 +1498,10 @@ public GatedCloseable<IndexCommit> 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<SegmentInfos> getLatestSegmentInfosSafe() throws EngineException {
return getEngine().getLatestSegmentInfosSafe();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,15 +21,15 @@

public class CopyState extends AbstractRefCounted {

private final Engine.SegmentInfosRef segmentInfosRef;
private final GatedCloseable<SegmentInfos> segmentInfosRef;
private final ReplicationCheckpoint checkpoint;
private final Store.MetadataSnapshot metadataSnapshot;
private final byte[] infosBytes;

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(),
Expand Down

0 comments on commit 20e3c64

Please sign in to comment.