DomGarguilo commented on code in PR #5540: URL: https://github.com/apache/accumulo/pull/5540#discussion_r2082031386
########## core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java: ########## @@ -1220,42 +1220,33 @@ public Map<String,String> getTableProperties(final String tableName) } @Override - public void setLocalityGroups(String tableName, Map<String,Set<Text>> groups) + public void setLocalityGroups(String tableName, Map<String,Set<Text>> groupsToSet) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { // ensure locality groups do not overlap - LocalityGroupUtil.ensureNonOverlappingGroups(groups); + LocalityGroupUtil.ensureNonOverlappingGroups(groupsToSet); - for (Entry<String,Set<Text>> entry : groups.entrySet()) { - Set<Text> colFams = entry.getValue(); - String value = LocalityGroupUtil.encodeColumnFamilies(colFams); - setPropertyNoChecks(tableName, Property.TABLE_LOCALITY_GROUP_PREFIX + entry.getKey(), value); - } + final String localityGroupPrefix = Property.TABLE_LOCALITY_GROUP_PREFIX.getKey(); - try { - setPropertyNoChecks(tableName, Property.TABLE_LOCALITY_GROUPS.getKey(), - Joiner.on(",").join(groups.keySet())); - } catch (AccumuloException e) { - if (e.getCause() instanceof TableNotFoundException) { - throw (TableNotFoundException) e.getCause(); - } - throw e; - } + modifyProperties(tableName, properties -> { - // remove anything extraneous - String prefix = Property.TABLE_LOCALITY_GROUP_PREFIX.getKey(); - for (Entry<String,String> entry : getProperties(tableName)) { - String property = entry.getKey(); - if (property.startsWith(prefix)) { - // this property configures a locality group, find out which - // one: - String[] parts = property.split("\\."); - String group = parts[parts.length - 1]; + // add/update each locality group + groupsToSet.forEach((groupName, colFams) -> properties.put(localityGroupPrefix + groupName, + LocalityGroupUtil.encodeColumnFamilies(colFams))); + + // update the list of all locality groups + final String allGroups = Joiner.on(",").join(groupsToSet.keySet()); + properties.put(Property.TABLE_LOCALITY_GROUPS.getKey(), allGroups); - if (!groups.containsKey(group)) { - removePropertyNoChecks(tableName, property); + // remove any stale locality groups that were previously set + for (String key : new ArrayList<>(properties.keySet())) { Review Comment: Actually took another look and ended up using `removeIf()` here which avoids the need to create a new collection and generally cleans the code up more. -- 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: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org