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

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


The following commit(s) were added to refs/heads/2.1 by this push:
     new 4c10226c76 Allow configurable name allocations (#3729)
4c10226c76 is described below

commit 4c10226c76bb71d59d31b44ca4fec392202473c0
Author: jeff <1583214+jschmid...@users.noreply.github.com>
AuthorDate: Mon Aug 28 14:32:46 2023 -0700

    Allow configurable name allocations (#3729)
    
    Update the UniqueNameAllocator to support a configurable filename range 
size. The default values match what was previously there so there is no 
behavior change unless you override the properties.
---
 .../org/apache/accumulo/core/conf/Property.java    |  9 ++++++
 .../server/tablets/UniqueNameAllocator.java        | 33 +++++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/conf/Property.java 
b/core/src/main/java/org/apache/accumulo/core/conf/Property.java
index 9c2e9532ee..77df51c5d8 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/Property.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/Property.java
@@ -228,6 +228,13 @@ public enum Property {
       "2.1.0"),
   GENERAL_RPC_TIMEOUT("general.rpc.timeout", "120s", PropertyType.TIMEDURATION,
       "Time to wait on I/O for simple, short RPC calls", "1.3.5"),
+  GENERAL_FILENAME_BASE_ALLOCATION("general.filename.base.allocation", "100", 
PropertyType.COUNT,
+      "The minimum number of filenames that will be allocated from Zookeeper 
at a time.", "2.1.3"),
+  GENERAL_FILENAME_JITTER_ALLOCATION("general.filename.jitter.allocation", 
"100",
+      PropertyType.COUNT,
+      "The size of the jitter that will be applied to the 
`general.filename.base.allocation` when allocating "
+          + "filenames from Zookeeper. This will result in an allocation 
between base and (base + jitter).  This property is ignored when its <= 0 and 
only base is used.",
+      "2.1.3"),
   @Experimental
   GENERAL_RPC_SERVER_TYPE("general.rpc.server.type", "", PropertyType.STRING,
       "Type of Thrift server to instantiate, see "
@@ -1830,6 +1837,8 @@ public enum Property {
         || key.startsWith(Property.MASTER_PREFIX.getKey())
         || key.startsWith(Property.GC_PREFIX.getKey())
         || key.startsWith(Property.GENERAL_ARBITRARY_PROP_PREFIX.getKey())
+        || key.equals(Property.GENERAL_FILENAME_BASE_ALLOCATION.getKey())
+        || key.equals(Property.GENERAL_FILENAME_JITTER_ALLOCATION.getKey())
         || key.startsWith(VFS_CONTEXT_CLASSPATH_PROPERTY.getKey())
         || key.startsWith(REPLICATION_PREFIX.getKey());
   }
diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/tablets/UniqueNameAllocator.java
 
b/server/base/src/main/java/org/apache/accumulo/server/tablets/UniqueNameAllocator.java
index 03eb9229bf..7c0f29c5ea 100644
--- 
a/server/base/src/main/java/org/apache/accumulo/server/tablets/UniqueNameAllocator.java
+++ 
b/server/base/src/main/java/org/apache/accumulo/server/tablets/UniqueNameAllocator.java
@@ -23,8 +23,11 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 import java.security.SecureRandom;
 
 import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.util.FastFormat;
 import org.apache.accumulo.server.ServerContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Allocates unique names for an accumulo instance. The names are unique for 
the lifetime of the
@@ -34,6 +37,11 @@ import org.apache.accumulo.server.ServerContext;
  */
 public class UniqueNameAllocator {
 
+  private static Logger log = 
LoggerFactory.getLogger(UniqueNameAllocator.class);
+
+  private static final int DEFAULT_BASE_ALLOCATION =
+      
Integer.parseInt(Property.GENERAL_FILENAME_BASE_ALLOCATION.getDefaultValue());
+
   private ServerContext context;
   private long next = 0;
   private long maxAllocated = 0;
@@ -48,7 +56,7 @@ public class UniqueNameAllocator {
   public synchronized String getNextName() {
 
     while (next >= maxAllocated) {
-      final int allocate = 100 + random.nextInt(100);
+      final int allocate = getAllocation();
 
       try {
         byte[] max = context.getZooReaderWriter().mutateExisting(nextNamePath, 
currentValue -> {
@@ -67,4 +75,27 @@ public class UniqueNameAllocator {
     return new String(FastFormat.toZeroPaddedString(next++, 7, 
Character.MAX_RADIX, new byte[0]),
         UTF_8);
   }
+
+  private int getAllocation() {
+    int baseAllocation =
+        
context.getConfiguration().getCount(Property.GENERAL_FILENAME_BASE_ALLOCATION);
+    int jitterAllocation =
+        
context.getConfiguration().getCount(Property.GENERAL_FILENAME_JITTER_ALLOCATION);
+
+    if (baseAllocation <= 0) {
+      log.warn("{} was set to {}, must be greater than 0. Using the default 
{}.",
+          Property.GENERAL_FILENAME_BASE_ALLOCATION.getKey(), baseAllocation,
+          DEFAULT_BASE_ALLOCATION);
+      baseAllocation = DEFAULT_BASE_ALLOCATION;
+    }
+
+    int totalAllocation = baseAllocation;
+    if (jitterAllocation > 0) {
+      totalAllocation += random.nextInt(jitterAllocation);
+    }
+
+    log.debug("Allocating {} filenames", totalAllocation);
+
+    return totalAllocation;
+  }
 }

Reply via email to