Skip to content

Remove hppc from deletion policy #86072

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

Merged
merged 4 commits into from
Apr 21, 2022
Merged
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 @@ -8,8 +8,6 @@

package org.elasticsearch.index.engine;

import com.carrotsearch.hppc.ObjectIntHashMap;

import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.index.IndexDeletionPolicy;
Expand All @@ -21,6 +19,7 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -38,7 +37,7 @@ public class CombinedDeletionPolicy extends IndexDeletionPolicy {
private final TranslogDeletionPolicy translogDeletionPolicy;
private final SoftDeletesPolicy softDeletesPolicy;
private final LongSupplier globalCheckpointSupplier;
private final ObjectIntHashMap<IndexCommit> snapshottedCommits; // Number of snapshots held against each commit point.
private final Map<IndexCommit, Integer> snapshottedCommits; // Number of snapshots held against each commit point.
private volatile IndexCommit safeCommit; // the most recent safe commit point - its max_seqno at most the persisted global checkpoint.
private volatile long maxSeqNoOfNextSafeCommit;
private volatile IndexCommit lastCommit; // the most recent commit point
Expand All @@ -54,7 +53,7 @@ public class CombinedDeletionPolicy extends IndexDeletionPolicy {
this.translogDeletionPolicy = translogDeletionPolicy;
this.softDeletesPolicy = softDeletesPolicy;
this.globalCheckpointSupplier = globalCheckpointSupplier;
this.snapshottedCommits = new ObjectIntHashMap<>();
this.snapshottedCommits = new HashMap<>();
}

@Override
Expand Down Expand Up @@ -146,7 +145,7 @@ synchronized IndexCommit acquireIndexCommit(boolean acquiringSafeCommit) {
assert safeCommit != null : "Safe commit is not initialized yet";
assert lastCommit != null : "Last commit is not initialized yet";
final IndexCommit snapshotting = acquiringSafeCommit ? safeCommit : lastCommit;
snapshottedCommits.addTo(snapshotting, 1); // increase refCount
snapshottedCommits.merge(snapshotting, 1, Integer::sum); // increase refCount
return new SnapshotIndexCommit(snapshotting);
}

Expand All @@ -164,13 +163,17 @@ synchronized boolean releaseCommit(final IndexCommit snapshotCommit) {
+ "], releasing commit ["
+ releasingCommit
+ "]";
final int refCount = snapshottedCommits.addTo(releasingCommit, -1); // release refCount
assert refCount >= 0 : "Number of snapshots can not be negative [" + refCount + "]";
if (refCount == 0) {
snapshottedCommits.remove(releasingCommit);
}
// release refCount
final Integer refCount = snapshottedCommits.compute(releasingCommit, (key, count) -> {
if (count == 1) {
return null;
}
return count - 1;
});

assert refCount == null || refCount > 0 : "Number of snapshots can not be negative [" + refCount + "]";
// The commit can be clean up only if no pending snapshot and it is neither the safe commit nor last commit.
return refCount == 0 && releasingCommit.equals(safeCommit) == false && releasingCommit.equals(lastCommit) == false;
return refCount == null && releasingCommit.equals(safeCommit) == false && releasingCommit.equals(lastCommit) == false;
}

/**
Expand Down