kevinrr888 commented on code in PR #6040:
URL: https://github.com/apache/accumulo/pull/6040#discussion_r2669885821


##########
core/src/main/java/org/apache/accumulo/core/iteratorsImpl/IteratorConfigUtil.java:
##########
@@ -273,4 +294,169 @@ private static Class<SortedKeyValueIterator<Key,Value>> 
loadClass(boolean useAcc
     log.trace("Iterator class {} loaded from classpath", iterInfo.className);
     return clazz;
   }
+
+  public static void checkIteratorConflicts(Map<String,String> props, String 
property, String value)
+      throws AccumuloException, TableNotFoundException, 
IllegalArgumentException {
+    if (props.containsKey(property) && props.get(property).equals(value)) {
+      // setting a property that already exists (i.e., no change)
+      return;
+    }
+    if (IteratorConfigUtil.isNonOptionIterProp(property, value)) {
+      String[] iterPropParts = property.split("\\.");
+      IteratorScope scope = IteratorScope.valueOf(iterPropParts[2]);
+      String iterName = iterPropParts[3];
+      String[] priorityAndClass;
+      if ((priorityAndClass = value.split(",")).length == 2) {
+        // given a single property, the only way for the property to be 
equivalent to an existing
+        // iterator is if the existing iterator has no options (opts are set 
as separate props)
+        IteratorSetting givenIter = new 
IteratorSetting(Integer.parseInt(priorityAndClass[0]),
+            iterName, priorityAndClass[1]);
+        TableOperationsHelper.checkIteratorConflicts(props, givenIter, 
EnumSet.of(scope));
+      }
+    }
+  }
+
+  public static void checkIteratorConflicts(TableOperations tableOps, 
NamespaceOperationsHelper noh,
+      String namespace, String property, String value)
+      throws AccumuloException, AccumuloSecurityException, 
NamespaceNotFoundException {
+    var props = noh.getNamespaceProperties(namespace);
+    if (props.containsKey(property) && props.get(property).equals(value)) {
+      // setting a property that already exists (i.e., no change)
+      return;
+    }
+
+    // checking for conflicts in the namespace
+    if (IteratorConfigUtil.isNonOptionIterProp(property, value)) {
+      String[] iterPropParts = property.split("\\.");
+      IteratorScope scope = IteratorScope.valueOf(iterPropParts[2]);
+      String iterName = iterPropParts[3];
+      String[] priorityAndClass;
+      if ((priorityAndClass = value.split(",")).length == 2) {
+        // given a single property, the only way for the property to be 
equivalent to an existing
+        // iterator is if the existing iterator has no options (opts are set 
as separate props)
+        IteratorSetting givenIter = new 
IteratorSetting(Integer.parseInt(priorityAndClass[0]),
+            iterName, priorityAndClass[1]);
+        noh.checkIteratorConflicts(namespace, givenIter, EnumSet.of(scope));
+      }
+    }
+
+    // checking for conflicts for the tables in the namespace
+    checkIteratorConflictsWithTablesInNamespace(tableOps, namespace, property, 
value);
+  }
+
+  public static void 
checkIteratorConflictsWithTablesInNamespace(TableOperations tableOps,
+      String namespace, IteratorSetting is, EnumSet<IteratorScope> scopes)
+      throws AccumuloException {
+    var tablesInNamespace = tableOps.list().stream()
+        .filter(t -> t.startsWith(namespace + 
Namespace.SEPARATOR)).collect(Collectors.toSet());
+    try {
+      for (var table : tablesInNamespace) {
+        
IteratorConfigUtil.checkIteratorConflicts(tableOps.getTableProperties(table), 
is, scopes);
+      }
+    } catch (TableNotFoundException | IllegalArgumentException e) {
+      throw new AccumuloException(e);
+    }
+  }
+
+  public static void 
checkIteratorConflictsWithTablesInNamespace(TableOperations tableOps,
+      String namespace, String property, String value) throws 
AccumuloException {
+    var tablesInNamespace = tableOps.list().stream()
+        .filter(t -> t.startsWith(namespace + 
Namespace.SEPARATOR)).collect(Collectors.toSet());
+    try {
+      for (var table : tablesInNamespace) {
+        
IteratorConfigUtil.checkIteratorConflicts(tableOps.getTableProperties(table), 
property,
+            value);
+      }
+    } catch (TableNotFoundException | IllegalArgumentException e) {
+      throw new AccumuloException(e);
+    }
+  }
+
+  public static void checkIteratorConflicts(Map<String,String> props, 
IteratorSetting setting,
+      EnumSet<IteratorScope> scopes) throws AccumuloException {
+    for (IteratorScope scope : scopes) {
+      String scopeStr =
+          String.format("%s%s", Property.TABLE_ITERATOR_PREFIX, 
scope.name().toLowerCase());
+      String nameStr = String.format("%s.%s", scopeStr, setting.getName());
+      String optStr = String.format("%s.opt.", nameStr);
+      String valStr = String.format("%s,%s", setting.getPriority(), 
setting.getIteratorClass());
+      Map<String,String> optionConflicts = new TreeMap<>();
+      // skip if the setting is present in the map... not a conflict if 
exactly the same
+      if (props.containsKey(nameStr) && props.get(nameStr).equals(valStr)
+          && IteratorConfigUtil.containsSameIterOpts(props, setting, optStr)) {
+        continue;
+      }

Review Comment:
   this method is the same as before except the addition of "valStr" and this 
if check. 
   
   Moved here since same code was used for 
TableOperationsHelper.checkIteratorConflicts and 
NamespaceOperationsHelper.checkIteratorConflicts.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to