This is an automated email from the ASF dual-hosted git repository.

dlmarion pushed a commit to branch elasticity
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/elasticity by this push:
     new 9d46575487 Added caching for CompactionServiceId (#4325)
9d46575487 is described below

commit 9d46575487fa2546edfcd55d14f7e91dff626041
Author: Arbaaz Khan <bazzy...@yahoo.com>
AuthorDate: Thu Jun 6 16:27:02 2024 -0400

    Added caching for CompactionServiceId (#4325)
---
 .../core/spi/compaction/CompactionServiceId.java       | 18 +++++++++++++++++-
 .../org/apache/accumulo/core/util/cache/Caches.java    |  1 +
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git 
a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionServiceId.java
 
b/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionServiceId.java
index f216384dd3..322cffbb16 100644
--- 
a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionServiceId.java
+++ 
b/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionServiceId.java
@@ -18,7 +18,12 @@
  */
 package org.apache.accumulo.core.spi.compaction;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.accumulo.core.data.AbstractId;
+import org.apache.accumulo.core.util.cache.Caches;
+
+import com.github.benmanes.caffeine.cache.Cache;
 
 /**
  * A unique identifier for a compaction service
@@ -28,11 +33,22 @@ import org.apache.accumulo.core.data.AbstractId;
 public class CompactionServiceId extends AbstractId<CompactionServiceId> {
   private static final long serialVersionUID = 1L;
 
+  static final Cache<String,CompactionServiceId> cache =
+      
Caches.getInstance().createNewBuilder(Caches.CacheName.COMPACTION_SERVICE_ID, 
false)
+          .weakValues().expireAfterAccess(1, TimeUnit.DAYS).build();
+
   private CompactionServiceId(String canonical) {
     super(canonical);
   }
 
+  /**
+   * Get a CompactionServiceID object for the provided canonical string. This 
is guaranteed to be
+   * non-null.
+   *
+   * @param canonical compaction service ID string
+   * @return CompactionServiceId object
+   */
   public static CompactionServiceId of(String canonical) {
-    return new CompactionServiceId(canonical);
+    return cache.get(canonical, CompactionServiceId::new);
   }
 }
diff --git a/core/src/main/java/org/apache/accumulo/core/util/cache/Caches.java 
b/core/src/main/java/org/apache/accumulo/core/util/cache/Caches.java
index 531061a872..3927f4d0c0 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/cache/Caches.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/cache/Caches.java
@@ -41,6 +41,7 @@ public class Caches implements MetricsProducer {
     COMPACTION_CONFIGS,
     COMPACTION_DIR_CACHE,
     COMPACTION_DISPATCHERS,
+    COMPACTION_SERVICE_ID,
     COMPACTOR_GROUP_ID,
     COMPRESSION_ALGORITHM,
     CRYPT_PASSWORDS,

Reply via email to