From c4084274a7fa8d682627b86ad1acb065a6a67c0c Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 20 Apr 2022 05:55:40 -0700 Subject: [PATCH 1/2] Remove hppc from deletion policy The CombinedDeletionPolicy keeps ref counts for each index snapshot using an hppc primitive map. This commit converts it to use a standard HashMap. relates #84735 --- .../index/engine/CombinedDeletionPolicy.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java b/server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java index ebc8d70192f37..565bc32dc15ff 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java +++ b/server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java @@ -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; @@ -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; @@ -38,7 +37,7 @@ public class CombinedDeletionPolicy extends IndexDeletionPolicy { private final TranslogDeletionPolicy translogDeletionPolicy; private final SoftDeletesPolicy softDeletesPolicy; private final LongSupplier globalCheckpointSupplier; - private final ObjectIntHashMap snapshottedCommits; // Number of snapshots held against each commit point. + private final Map 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 @@ -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 @@ -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); } @@ -164,7 +163,7 @@ synchronized boolean releaseCommit(final IndexCommit snapshotCommit) { + "], releasing commit [" + releasingCommit + "]"; - final int refCount = snapshottedCommits.addTo(releasingCommit, -1); // release refCount + final int refCount = snapshottedCommits.merge(releasingCommit, -1, Integer::sum); // release refCount assert refCount >= 0 : "Number of snapshots can not be negative [" + refCount + "]"; if (refCount == 0) { snapshottedCommits.remove(releasingCommit); From bc4d29226e861060b63609fe8f4ad6f8904067c2 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 21 Apr 2022 08:35:36 -0700 Subject: [PATCH 2/2] address feedback --- .../index/engine/CombinedDeletionPolicy.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java b/server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java index 565bc32dc15ff..7d5094bcde6a0 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java +++ b/server/src/main/java/org/elasticsearch/index/engine/CombinedDeletionPolicy.java @@ -163,13 +163,17 @@ synchronized boolean releaseCommit(final IndexCommit snapshotCommit) { + "], releasing commit [" + releasingCommit + "]"; - final int refCount = snapshottedCommits.merge(releasingCommit, -1, Integer::sum); // 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; } /**