Skip to content
Draft
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 @@ -46,7 +46,7 @@ public static synchronized void initContextFactory(AccumuloConfiguration conf) {
// load the default implementation
LOG.info("Using default {}, which is subject to change in a future release",
ContextClassLoaderFactory.class.getName());
FACTORY = new URLContextClassLoaderFactory();
FACTORY = new DefaultContextClassLoaderFactory();

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.

I suggest simplifying this logic by explicitly putting the classloader in the default value of the property, and failing if the class cannot be loaded. This reduces confusion about the default behavior due to "hidden" default property values (i.e. empty value results in undocumented internal default).

Alternatively, get rid of the class and use a lambda here when the property is empty:

Suggested change
FACTORY = new DefaultContextClassLoaderFactory();
FACTORY = context -> ClassLoader.getSystemClassLoader();

} else {
// load user's selected implementation and provide it with the service environment
try {
Expand Down

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.

If an explicit implementation is kept for the default value of the property, then the name should not be "Default..." because that is the role, not the behavior. If the default changes, the name becomes misleading.

Instead, a name that reflects its behavior is better. Here are some AI-suggested names:

  • SystemClassLoaderFactory — concise and clear, if the SPI context already makes the role obvious.
  • SystemContextClassLoaderFactory — explicit about both the SPI and the classloader it returns.
  • ContextIndependentClassLoaderFactory — emphasizes that the context argument is ignored, but not which loader is returned.
  • FixedSystemClassLoaderFactory — conveys that it always returns the same system classloader.
  • ConstantSystemClassLoaderFactory — similarly emphasizes the fixed result.

Of these, I'd lean towards the first or second.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.accumulo.core.classloader;

import org.apache.accumulo.core.spi.common.ContextClassLoaderFactory;

public class DefaultContextClassLoaderFactory implements ContextClassLoaderFactory {

@Override
public ClassLoader getClassLoader(String context) throws ContextClassLoaderException {
return ClassLoader.getSystemClassLoader();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.accumulo.core.classloader;
package org.apache.accumulo.core.util.test;

import java.io.UncheckedIOException;
import java.net.MalformedURLException;
Expand All @@ -34,8 +34,8 @@
import com.github.benmanes.caffeine.cache.Cache;

/**
* The default implementation of ContextClassLoaderFactory. This classloader returns a
* URLClassLoader based on the given context value which is a CSV list of URLs. For example,
* A test implementation of ContextClassLoaderFactory. This classloader returns a URLClassLoader
* based on the given context value which is a CSV list of URLs. For example,
* file://path/one/jar1.jar,file://path/two/jar2.jar
*/
public class URLContextClassLoaderFactory implements ContextClassLoaderFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.accumulo.core.conf.ConfigurationCopy;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.spi.common.ContextClassLoaderFactory.ContextClassLoaderException;
import org.apache.accumulo.core.util.test.URLContextClassLoaderFactory;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -38,7 +39,7 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "paths not set by user input")
public class ContextClassLoaderFactoryTest extends WithTestNames {
public class URLContextClassLoaderFactoryTest extends WithTestNames {

@TempDir
private static Path tempFolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.util.test.URLContextClassLoaderFactory;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -74,6 +75,8 @@ public static void setupMiniCluster() throws Exception {
config.setZooKeeperPort(0);
HashMap<String,String> site = new HashMap<>();
site.put(Property.TSERV_WAL_MAX_SIZE.getKey(), "1G");
site.put(Property.GENERAL_CONTEXT_CLASSLOADER_FACTORY.getKey(),
URLContextClassLoaderFactory.class.getName());
config.setSiteConfig(site);
accumulo = new MiniAccumuloCluster(config);
accumulo.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.apache.accumulo.core.metrics.MetricsUtil;
import org.apache.accumulo.core.spi.metrics.LoggingMeterRegistryFactory;
import org.apache.accumulo.core.util.compaction.ExternalCompactionUtil;
import org.apache.accumulo.core.util.test.URLContextClassLoaderFactory;
import org.apache.accumulo.core.util.threads.Threads;
import org.apache.accumulo.minicluster.ServerType;
import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl;
Expand Down Expand Up @@ -101,6 +102,8 @@ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration coreS
cfg.setProperty(Property.COMPACTOR_FAILURE_BACKOFF_INTERVAL, "5s");
cfg.setProperty(Property.COMPACTOR_FAILURE_BACKOFF_RESET, "10m");
cfg.setProperty(Property.COMPACTOR_FAILURE_TERMINATION_THRESHOLD, "3");
cfg.setProperty(Property.GENERAL_CONTEXT_CLASSLOADER_FACTORY,
URLContextClassLoaderFactory.class.getName());
cfg.getClusterServerConfiguration().setNumDefaultCompactors(2);
cfg.getClusterServerConfiguration().addCompactorResourceGroup(GROUP1, 1);
// Tell the server processes to use a StatsDMeterRegistry and the simple logging registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.util.test.URLContextClassLoaderFactory;
import org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl;
import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
import org.apache.accumulo.test.harness.AccumuloClusterHarness;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -64,6 +67,12 @@ protected Duration defaultTimeout() {
return Duration.ofMinutes(2);
}

@Override
public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {
cfg.setProperty(Property.GENERAL_CONTEXT_CLASSLOADER_FACTORY,
URLContextClassLoaderFactory.class.getName());
}

@BeforeEach
public void checkCluster() throws Exception {
assumeTrue(getClusterType() == ClusterType.MINI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.apache.accumulo.core.spi.crypto.NoCryptoServiceFactory;
import org.apache.accumulo.core.util.format.Formatter;
import org.apache.accumulo.core.util.format.FormatterConfig;
import org.apache.accumulo.core.util.test.URLContextClassLoaderFactory;
import org.apache.accumulo.minicluster.ServerType;
import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
import org.apache.accumulo.test.ImportExportIT;
Expand Down Expand Up @@ -131,7 +132,8 @@ private static class ShellServerITConfigCallback implements MiniClusterConfigura
public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration coreSite) {
// Only one tserver to avoid race conditions on ZK propagation (auths and configuration)
cfg.getClusterServerConfiguration().setNumDefaultTabletServers(1);
// Set the min span to 0 so we will definitely get all the traces back. See ACCUMULO-4365
cfg.setProperty(Property.GENERAL_CONTEXT_CLASSLOADER_FACTORY,
URLContextClassLoaderFactory.class.getName());
Map<String,String> siteConf = cfg.getSiteConfig();
cfg.setSiteConfig(siteConf);
}
Expand Down
Loading