Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-13822: Isolated Classloading from packages #957

Merged
merged 20 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
incorporating review comments
  • Loading branch information
noblepaul committed Oct 23, 2019
commit 51de93c65d75f85e1a89e4b8465e798de44c89fd
15 changes: 6 additions & 9 deletions solr/core/src/java/org/apache/solr/core/PluginBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
Expand Down Expand Up @@ -141,7 +142,10 @@ public PluginHolder<T> createPlugin(PluginInfo info) {
return new LazyPluginHolder<T>(meta, info, core, core.getResourceLoader(), false);
} else {
if (info.pkgName != null) {
noblepaul marked this conversation as resolved.
Show resolved Hide resolved
return getPackagePluginHolder(info);
PackagePluginHolder<T> holder = new PackagePluginHolder<>(info, core, meta);
return meta.clazz == UpdateRequestProcessorFactory.class ?
new PluginHolder(info, new LazyUpdateProcessorFactoryHolder(holder)) :
holder;
} else {
T inst = core.createInstance(info.className, (Class<T>) meta.clazz, meta.getCleanTag(), null, core.getResourceLoader(info.pkgName));
initInstance(inst, info);
Expand All @@ -150,13 +154,6 @@ public PluginHolder<T> createPlugin(PluginInfo info) {
}
}

private PluginHolder<T> getPackagePluginHolder(PluginInfo info) {
PackagePluginHolder<T> holder = new PackagePluginHolder<>(info, core, meta);
return meta.clazz == UpdateRequestProcessorFactory.class ?
new PluginHolder(info, new LazyUpdateProcessorFactoryHolder(holder)) :
holder;
}

/**
* make a plugin available in an alternate name. This is an internal API and not for public use
*
Expand Down Expand Up @@ -355,7 +352,7 @@ public static void closeQuietly(Object inst) {
* An indirect reference to a plugin. It just wraps a plugin instance.
* subclasses may choose to lazily load the plugin
*/
public static class PluginHolder<T> implements AutoCloseable {
public static class PluginHolder<T> implements Supplier<T>, AutoCloseable {
protected T inst;
protected final PluginInfo pluginInfo;
boolean registerAPI = false;
Expand Down
5 changes: 5 additions & 0 deletions solr/core/src/java/org/apache/solr/core/PluginInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public PluginInfo(String type, Map<String, String> attrs, NamedList initArgs, Li
this.children = children == null ? Collections.<PluginInfo>emptyList(): unmodifiableList(children);
isFromSolrConfig = false;
}

/** class names can be prefixed with package name e.g: my_package:my.pkg.Class
* This checks if it is a package name prefixed classname.
* the return value has first = package name & second = class name
*/
static Pair<String,String > parseClassName(String name) {
noblepaul marked this conversation as resolved.
Show resolved Hide resolved
String pkgName = null;
String className = name;
Expand Down
3 changes: 3 additions & 0 deletions solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ public SolrResourceLoader getResourceLoader() {
return resourceLoader;
}

/** Gets the SolrResourceLoader for a given package
* @param pkg The package name
*/
public SolrResourceLoader getResourceLoader(String pkg) {
noblepaul marked this conversation as resolved.
Show resolved Hide resolved
if (pkg == null) {
return resourceLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ private void handleGET() {
Object o = map.get(componentName);
noblepaul marked this conversation as resolved.
Show resolved Hide resolved
val.put(parts.get(1), makeMap(componentName, o));
if (req.getParams().getBool("meta", false)) {
// meta=true is asking for the package info of the plugin
// We go through all the listeners and see if there is one registered for this plugin
List<PackageListeners.Listener> listeners = req.getCore().getPackageListeners().getListeners();
for (PackageListeners.Listener listener :
listeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.solr.common.util.ReflectMapWriter;

/**Just a container class for POJOs used in Package APIs
*
*/
public class Package {
noblepaul marked this conversation as resolved.
Show resolved Hide resolved
public static class AddVersion implements ReflectMapWriter {
@JsonProperty(value = "package", required = true)
Expand Down