Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DomGarguilo We have precedent for having certain loggers that are not based on a class to be named uppercase. See LoggingMeterRegistryFactory's "org.apache.accumulo.METRICS". Perhaps this should be changed to "org.apache.accumulo.CONFIG" to follow that same convention?

Suggested change
LoggerFactory.getLogger("org.apache.accumulo.configuration");
LoggerFactory.getLogger("org.apache.accumulo.CONFIG");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea to me too. Changed in #6488


private PropUtil() {}

/**
Expand All @@ -44,18 +54,21 @@ public static void setProperties(final ServerContext context, final PropStoreKey
final Map<String,String> 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<String> propertyNames) {
context.getPropStore().removeProperties(propStoreKey, propertyNames);
logRemoveProperties(propStoreKey, propertyNames);
}

public static void replaceProperties(final ServerContext context,
final PropStoreKey<?> propStoreKey, final long version, final Map<String,String> properties)
throws IllegalArgumentException {
PropUtil.validateProperties(context, propStoreKey, properties);
context.getPropStore().replaceAll(propStoreKey, version, properties);
logReplaceProperties(propStoreKey, version, properties);
}

protected static void validateProperties(final ServerContext context,
Expand Down Expand Up @@ -102,4 +115,66 @@ protected static void validateProperties(final ServerContext context,
}
}
}

static void logSetProperties(final PropStoreKey<?> propStoreKey,
final Map<String,String> 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<String> 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<String,String> 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<String,String> printableProperties(Map<String,String> properties) {
Map<String,String> printable = new TreeMap<>();
for (var prop : properties.entrySet()) {
final String key = prop.getKey();
final String printableValue = Property.isSensitive(key) ? "<hidden>" : 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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String,String> 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,
Expand All @@ -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) {
Expand All @@ -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,
Expand Down