dlmarion commented on code in PR #5540:
URL: https://github.com/apache/accumulo/pull/5540#discussion_r2081545776
##########
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:
Is there a reason to convert `Set<String>` to `ArrayList<String>`?
##########
core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java:
##########
@@ -1862,15 +1853,14 @@ private void doTableFateOperation(String
tableOrNamespaceName,
}
}
- private void clearSamplerOptions(String tableName)
- throws AccumuloException, TableNotFoundException,
AccumuloSecurityException {
- EXISTING_TABLE_NAME.validate(tableName);
-
+ /**
+ * Removes all sampler option properties from the given properties map
+ */
+ private void clearSamplerOptions(Map<String,String> props) {
String prefix = Property.TABLE_SAMPLER_OPTS.getKey();
- for (Entry<String,String> entry : getProperties(tableName)) {
- String property = entry.getKey();
+ for (String property : new ArrayList<>(props.keySet())) {
Review Comment:
Is there a reason to convert `Set<String>` to `ArrayList<String>`?
##########
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);
Review Comment:
This is not referencing the `.getKey()` method of the property. Is this a
bug? If so, does it exist in earlier versions that need to be fixed (2.1, 3.0)?
--
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]