Skip to content

Refactor acquireHistoryRetentionLock to Use Releasable instead of Closeable #130814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.IndexSettings;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void testRetentionLeasesSyncedOnAdd() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
// simulate a peer recovery which locks the soft deletes policy on the primary
final Closeable retentionLock = randomBoolean() ? primary.acquireHistoryRetentionLock() : () -> {};
final Releasable retentionLock = randomBoolean() ? primary.acquireHistoryRetentionLock() : () -> {};
currentRetentionLeases.put(id, primary.addRetentionLease(id, retainingSequenceNumber, source, listener));
latch.await();
retentionLock.close();
Expand Down Expand Up @@ -145,7 +146,7 @@ public void testRetentionLeaseSyncedOnRemove() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
// simulate a peer recovery which locks the soft deletes policy on the primary
final Closeable retentionLock = randomBoolean() ? primary.acquireHistoryRetentionLock() : () -> {};
final Releasable retentionLock = randomBoolean() ? primary.acquireHistoryRetentionLock() : () -> {};
currentRetentionLeases.put(id, primary.addRetentionLease(id, retainingSequenceNumber, source, listener));
latch.await();
retentionLock.close();
Expand All @@ -156,7 +157,7 @@ public void testRetentionLeaseSyncedOnRemove() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
primary.removeRetentionLease(id, countDownLatchListener(latch));
// simulate a peer recovery which locks the soft deletes policy on the primary
final Closeable retentionLock = randomBoolean() ? primary.acquireHistoryRetentionLock() : () -> {};
final Releasable retentionLock = randomBoolean() ? primary.acquireHistoryRetentionLock() : () -> {};
currentRetentionLeases.remove(id);
latch.await();
retentionLock.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ public boolean allowSearchIdleOptimization() {
/**
* Acquires a lock on Lucene soft-deleted documents to prevent them from being trimmed
*/
public abstract Closeable acquireHistoryRetentionLock();
public abstract Releasable acquireHistoryRetentionLock();

/**
* Counts the number of operations in the range of the given sequence numbers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3318,7 +3318,7 @@ public final long getMinRetainedSeqNo() {
}

@Override
public Closeable acquireHistoryRetentionLock() {
public Releasable acquireHistoryRetentionLock() {
return softDeletesPolicy.acquireRetentionLock();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.mapper.DocumentParser;
Expand Down Expand Up @@ -345,7 +346,7 @@ public void asyncEnsureGlobalCheckpointSynced(long globalCheckpoint, Consumer<Ex
public void syncTranslog() {}

@Override
public Closeable acquireHistoryRetentionLock() {
public Releasable acquireHistoryRetentionLock() {
return () -> {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2669,7 +2669,7 @@ public void onSettingsChanged() {
/**
* Acquires a lock on Lucene soft-deleted documents to prevent them from being trimmed
*/
public Closeable acquireHistoryRetentionLock() {
public Releasable acquireHistoryRetentionLock() {
return getEngine().acquireHistoryRetentionLock();
}

Expand Down Expand Up @@ -2900,13 +2900,11 @@ public RetentionLease addRetentionLease(
assert assertPrimaryMode();
verifyNotClosed();
ensureSoftDeletesEnabled();
try (Closeable ignore = acquireHistoryRetentionLock()) {
try (Releasable ignore = acquireHistoryRetentionLock()) {
final long actualRetainingSequenceNumber = retainingSequenceNumber == RETAIN_ALL
? getMinRetainedSeqNo()
: retainingSequenceNumber;
return replicationTracker.addRetentionLease(id, actualRetainingSequenceNumber, source, listener);
} catch (final IOException e) {
throw new AssertionError(e);
}
}

Expand All @@ -2923,13 +2921,11 @@ public RetentionLease renewRetentionLease(final String id, final long retainingS
assert assertPrimaryMode();
verifyNotClosed();
ensureSoftDeletesEnabled();
try (Closeable ignore = acquireHistoryRetentionLock()) {
try (Releasable ignore = acquireHistoryRetentionLock()) {
final long actualRetainingSequenceNumber = retainingSequenceNumber == RETAIN_ALL
? getMinRetainedSeqNo()
: retainingSequenceNumber;
return replicationTracker.renewRetentionLease(id, actualRetainingSequenceNumber, source);
} catch (final IOException e) {
throw new AssertionError(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void recoverToTarget(ActionListener<RecoveryResponse> listener) {
}

private void recoverToTarget(RetentionLease retentionLease, Consumer<Exception> onFailure) throws IOException {
final Closeable retentionLock = shard.acquireHistoryRetentionLock();
final Releasable retentionLock = shard.acquireHistoryRetentionLock();
resources.add(retentionLock);
final long startingSeqNo;
final boolean isSequenceNumberBasedRecovery = request.startingSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO
Expand Down Expand Up @@ -1234,7 +1234,7 @@ void finalizeRecovery(long targetLocalCheckpoint, long trimAboveSeqNo, ActionLis
);
/*
* if the recovery process fails after disabling primary mode on the source shard, both relocation source and
* target are failed (see {@link IndexShard#updateRoutingEntry}).
* target are failed (see {@link IndexShard#updateShardState}).
*/
}));
} else {
Expand Down