diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/PropUtil.java b/server/base/src/main/java/org/apache/accumulo/server/util/PropUtil.java index d5776a58503..ccf79897010 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/PropUtil.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/PropUtil.java @@ -21,16 +21,26 @@ import java.io.IOException; import java.util.Collection; import java.util.Map; +import java.util.TreeMap; +import java.util.TreeSet; import org.apache.accumulo.core.classloader.ClassLoaderUtil; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.server.ServerContext; +import org.apache.accumulo.server.conf.store.NamespacePropKey; import org.apache.accumulo.server.conf.store.PropStoreKey; +import org.apache.accumulo.server.conf.store.SystemPropKey; +import org.apache.accumulo.server.conf.store.TablePropKey; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicyInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class PropUtil { + private static final Logger CONFIG_LOG = + LoggerFactory.getLogger("org.apache.accumulo.configuration"); + private PropUtil() {} /** @@ -44,11 +54,13 @@ public static void setProperties(final ServerContext context, final PropStoreKey final Map properties) throws IllegalArgumentException { PropUtil.validateProperties(context, propStoreKey, properties); context.getPropStore().putAll(propStoreKey, properties); + logSetProperties(propStoreKey, properties); } public static void removeProperties(final ServerContext context, final PropStoreKey propStoreKey, final Collection propertyNames) { context.getPropStore().removeProperties(propStoreKey, propertyNames); + logRemoveProperties(propStoreKey, propertyNames); } public static void replaceProperties(final ServerContext context, @@ -56,6 +68,7 @@ public static void replaceProperties(final ServerContext context, throws IllegalArgumentException { PropUtil.validateProperties(context, propStoreKey, properties); context.getPropStore().replaceAll(propStoreKey, version, properties); + logReplaceProperties(propStoreKey, version, properties); } protected static void validateProperties(final ServerContext context, @@ -102,4 +115,66 @@ protected static void validateProperties(final ServerContext context, } } } + + static void logSetProperties(final PropStoreKey propStoreKey, + final Map properties) { + if (properties.isEmpty()) { + return; + } + if (CONFIG_LOG.isInfoEnabled()) { + CONFIG_LOG.info("action=set; scope={}; target={}; properties={};", scope(propStoreKey), + target(propStoreKey), printableProperties(properties)); + } + } + + static void logRemoveProperties(final PropStoreKey propStoreKey, + final Collection propertyNames) { + if (CONFIG_LOG.isInfoEnabled()) { + CONFIG_LOG.info("action=remove; scope={}; target={}; properties={};", scope(propStoreKey), + target(propStoreKey), new TreeSet<>(propertyNames)); + } + } + + static void logReplaceProperties(final PropStoreKey propStoreKey, final long version, + final Map properties) { + if (properties.isEmpty()) { + return; + } + if (CONFIG_LOG.isInfoEnabled()) { + CONFIG_LOG.info("action=modify; scope={}; target={}; version={}; properties={};", + scope(propStoreKey), target(propStoreKey), version, printableProperties(properties)); + } + } + + private static Map printableProperties(Map properties) { + Map printable = new TreeMap<>(); + for (var prop : properties.entrySet()) { + final String key = prop.getKey(); + final String printableValue = Property.isSensitive(key) ? "" : prop.getValue(); + printable.put(key, printableValue); + } + return printable; + } + + private static String scope(PropStoreKey propStoreKey) { + if (propStoreKey instanceof SystemPropKey) { + return "system"; + } else if (propStoreKey instanceof NamespacePropKey) { + return "namespace"; + } else if (propStoreKey instanceof TablePropKey) { + return "table"; + } + return propStoreKey.getClass().getSimpleName(); + } + + private static String target(PropStoreKey propStoreKey) { + if (propStoreKey instanceof SystemPropKey) { + return "system"; + } else if (propStoreKey instanceof NamespacePropKey || propStoreKey instanceof TablePropKey) { + return propStoreKey.getId().canonical(); + } else { + return propStoreKey.getPath(); + } + } + } diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/SystemPropUtil.java b/server/base/src/main/java/org/apache/accumulo/server/util/SystemPropUtil.java index 1adc07a53cd..f2ea9df1e26 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/util/SystemPropUtil.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/SystemPropUtil.java @@ -37,8 +37,10 @@ public class SystemPropUtil { public static void setSystemProperty(ServerContext context, String property, String value) throws IllegalArgumentException { final SystemPropKey key = SystemPropKey.of(context); - context.getPropStore().putAll(key, - Map.of(validateSystemProperty(context, key, property, value), value)); + Map properties = + Map.of(validateSystemProperty(context, key, property, value), value); + context.getPropStore().putAll(key, properties); + PropUtil.logSetProperties(key, properties); } public static void modifyProperties(ServerContext context, long version, @@ -50,6 +52,7 @@ public static void modifyProperties(ServerContext context, long version, entry -> validateSystemProperty(context, key, entry.getKey(), entry.getValue()), Map.Entry::getValue)); context.getPropStore().replaceAll(key, version, checkedProperties); + PropUtil.logReplaceProperties(key, version, checkedProperties); } public static void removeSystemProperty(ServerContext context, String property) { @@ -65,7 +68,9 @@ public static void removeSystemProperty(ServerContext context, String property) private static void removePropWithoutDeprecationWarning(ServerContext context, String property) { logIfFixed(Property.getPropertyByKey(property), null); - context.getPropStore().removeProperties(SystemPropKey.of(context), List.of(property)); + SystemPropKey key = SystemPropKey.of(context); + context.getPropStore().removeProperties(key, List.of(property)); + PropUtil.logRemoveProperties(key, List.of(property)); } private static String validateSystemProperty(ServerContext context, SystemPropKey key,