This is an automated email from the ASF dual-hosted git repository.
domgarguilo 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 9562e6584c backport #6111 - consolidate iterator parsing code (#6124)
9562e6584c is described below
commit 9562e6584c72c291fb9d4c0f9cc44bf7369dc36b
Author: Dom G. <[email protected]>
AuthorDate: Thu Feb 12 13:50:35 2026 -0500
backport #6111 - consolidate iterator parsing code (#6124)
* Consolidate iterator parsing code (#6111)
---------
Co-authored-by: Keith Turner <[email protected]>
---
.../core/clientImpl/NamespaceOperationsHelper.java | 52 +++++++++------------
.../core/clientImpl/TableOperationsHelper.java | 54 +++++++++-------------
.../core/iteratorsImpl/IteratorProperty.java | 21 +++++----
3 files changed, 58 insertions(+), 69 deletions(-)
diff --git
a/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java
b/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java
index 07958dd0ed..cdab20c390 100644
---
a/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java
+++
b/core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceOperationsHelper.java
@@ -33,6 +33,7 @@ import
org.apache.accumulo.core.client.admin.NamespaceOperations;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
import org.apache.accumulo.core.iteratorsImpl.IteratorConfigUtil;
+import org.apache.accumulo.core.iteratorsImpl.IteratorProperty;
public abstract class NamespaceOperationsHelper implements NamespaceOperations
{
@@ -92,29 +93,25 @@ public abstract class NamespaceOperationsHelper implements
NamespaceOperations {
if (!exists(namespace)) {
throw new NamespaceNotFoundException(null, namespace, null);
}
- int priority = -1;
- String classname = null;
- Map<String,String> settings = new HashMap<>();
-
- String root =
- String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX,
scope.name().toLowerCase(), name);
- String opt = root + ".opt.";
- for (Entry<String,String> property : this.getProperties(namespace)) {
- if (property.getKey().equals(root)) {
- String[] parts = property.getValue().split(",");
- if (parts.length != 2) {
- throw new AccumuloException("Bad value for iterator setting: " +
property.getValue());
- }
- priority = Integer.parseInt(parts[0]);
- classname = parts[1];
- } else if (property.getKey().startsWith(opt)) {
- settings.put(property.getKey().substring(opt.length()),
property.getValue());
+ IteratorProperty base = null;
+ Map<String,String> options = new HashMap<>();
+ for (var prop : this.getConfiguration(namespace).entrySet()) {
+ IteratorProperty iterProp = IteratorProperty.parse(prop);
+ if (iterProp == null || iterProp.getScope() != scope ||
!iterProp.getName().equals(name)) {
+ continue;
+ }
+ if (iterProp.isOption()) {
+ options.put(iterProp.getOptionKey(), iterProp.getOptionValue());
+ } else {
+ base = iterProp;
}
}
- if (priority <= 0 || classname == null) {
+ if (base == null) {
return null;
}
- return new IteratorSetting(priority, name, classname, settings);
+ IteratorSetting setting = base.toSetting();
+ options.forEach(setting::addOption);
+ return setting;
}
@Override
@@ -124,18 +121,13 @@ public abstract class NamespaceOperationsHelper
implements NamespaceOperations {
throw new NamespaceNotFoundException(null, namespace, null);
}
Map<String,EnumSet<IteratorScope>> result = new TreeMap<>();
- for (Entry<String,String> property : this.getProperties(namespace)) {
- String name = property.getKey();
- String[] parts = name.split("\\.");
- if (parts.length == 4) {
- if (parts[0].equals("table") && parts[1].equals("iterator")) {
- IteratorScope scope = IteratorScope.valueOf(parts[2]);
- if (!result.containsKey(parts[3])) {
- result.put(parts[3], EnumSet.noneOf(IteratorScope.class));
- }
- result.get(parts[3]).add(scope);
- }
+ for (var prop : this.getConfiguration(namespace).entrySet()) {
+ IteratorProperty iterProp = IteratorProperty.parse(prop);
+ if (iterProp == null || iterProp.isOption()) {
+ continue;
}
+ result.computeIfAbsent(iterProp.getName(), k ->
EnumSet.noneOf(IteratorScope.class))
+ .add(iterProp.getScope());
}
return result;
}
diff --git
a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java
b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java
index 70a43b0e31..19464c6446 100644
---
a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java
+++
b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsHelper.java
@@ -36,6 +36,7 @@ import org.apache.accumulo.core.client.admin.TableOperations;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
import org.apache.accumulo.core.iteratorsImpl.IteratorConfigUtil;
+import org.apache.accumulo.core.iteratorsImpl.IteratorProperty;
public abstract class TableOperationsHelper implements TableOperations {
@@ -84,34 +85,30 @@ public abstract class TableOperationsHelper implements
TableOperations {
@Override
public IteratorSetting getIteratorSetting(String tableName, String name,
IteratorScope scope)
- throws AccumuloSecurityException, AccumuloException,
TableNotFoundException {
+ throws AccumuloException, TableNotFoundException {
EXISTING_TABLE_NAME.validate(tableName);
checkArgument(name != null, "name is null");
checkArgument(scope != null, "scope is null");
- int priority = -1;
- String classname = null;
- Map<String,String> settings = new HashMap<>();
-
- String root =
- String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX,
scope.name().toLowerCase(), name);
- String opt = root + ".opt.";
- for (Entry<String,String> property : this.getProperties(tableName)) {
- if (property.getKey().equals(root)) {
- String[] parts = property.getValue().split(",");
- if (parts.length != 2) {
- throw new AccumuloException("Bad value for iterator setting: " +
property.getValue());
- }
- priority = Integer.parseInt(parts[0]);
- classname = parts[1];
- } else if (property.getKey().startsWith(opt)) {
- settings.put(property.getKey().substring(opt.length()),
property.getValue());
+ IteratorProperty base = null;
+ Map<String,String> options = new HashMap<>();
+ for (var prop : this.getConfiguration(tableName).entrySet()) {
+ IteratorProperty iterProp = IteratorProperty.parse(prop);
+ if (iterProp == null || iterProp.getScope() != scope ||
!iterProp.getName().equals(name)) {
+ continue;
+ }
+ if (iterProp.isOption()) {
+ options.put(iterProp.getOptionKey(), iterProp.getOptionValue());
+ } else {
+ base = iterProp;
}
}
- if (priority <= 0 || classname == null) {
+ if (base == null) {
return null;
}
- return new IteratorSetting(priority, name, classname, settings);
+ IteratorSetting setting = base.toSetting();
+ options.forEach(setting::addOption);
+ return setting;
}
@Override
@@ -120,18 +117,13 @@ public abstract class TableOperationsHelper implements
TableOperations {
EXISTING_TABLE_NAME.validate(tableName);
Map<String,EnumSet<IteratorScope>> result = new TreeMap<>();
- for (Entry<String,String> property : this.getProperties(tableName)) {
- String name = property.getKey();
- String[] parts = name.split("\\.");
- if (parts.length == 4) {
- if (parts[0].equals("table") && parts[1].equals("iterator")) {
- IteratorScope scope = IteratorScope.valueOf(parts[2]);
- if (!result.containsKey(parts[3])) {
- result.put(parts[3], EnumSet.noneOf(IteratorScope.class));
- }
- result.get(parts[3]).add(scope);
- }
+ for (var prop : this.getConfiguration(tableName).entrySet()) {
+ IteratorProperty iterProp = IteratorProperty.parse(prop);
+ if (iterProp == null || iterProp.isOption()) {
+ continue;
}
+ result.computeIfAbsent(iterProp.getName(), k ->
EnumSet.noneOf(IteratorScope.class))
+ .add(iterProp.getScope());
}
return result;
}
diff --git
a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java
b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java
index 20120b4b6c..88ffdcd817 100644
---
a/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java
+++
b/core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorProperty.java
@@ -113,9 +113,7 @@ public class IteratorProperty {
}
private static void check(boolean b, String property, String value) {
- if (!b) {
- throw new IllegalArgumentException("Illegal iterator property: " +
property + "=" + value);
- }
+ Preconditions.checkArgument(b, "Illegal iterator property: %s=%s",
property, value);
}
@Override
@@ -140,19 +138,26 @@ public class IteratorProperty {
return null;
}
- String[] iterPropParts = property.split("\\.");
+ String[] iterPropParts = property.split("\\.", -1);
check(iterPropParts.length == 4 || iterPropParts.length == 6, property,
value);
IteratorUtil.IteratorScope scope =
IteratorUtil.IteratorScope.valueOf(iterPropParts[2]);
String iterName = iterPropParts[3];
+ check(!iterName.isEmpty(), property, value);
if (iterPropParts.length == 4) {
- String[] valTokens = value.split(",");
+ String[] valTokens = value.split(",", -1);
check(valTokens.length == 2, property, value);
- return new IteratorProperty(iterName, scope,
Integer.parseInt(valTokens[0]), valTokens[1],
- property, value);
+ String prioStr = valTokens[0];
+ String className = valTokens[1];
+ check(!className.isEmpty(), property, value);
+ int priority = Integer.parseInt(prioStr);
+ check(priority > 0, property, value);
+ return new IteratorProperty(iterName, scope, priority, className,
property, value);
} else if (iterPropParts.length == 6) {
check(iterPropParts[4].equals("opt"), property, value);
- return new IteratorProperty(iterName, scope, iterPropParts[5], value,
property, value);
+ String optionName = iterPropParts[5];
+ check(!optionName.isEmpty(), property, value);
+ return new IteratorProperty(iterName, scope, optionName, value,
property, value);
} else {
throw new IllegalArgumentException("Illegal iterator property: " +
property + "=" + value);
}