Skip to content

Commit 60ff86d

Browse files
authored
Ensure ordering of plugin initialization (#93882)
As Node collects and initializes various parts of the system from plugins, it does so by calling helper methods on PluginsService to iterate the loaded plugins and call the desired method. These methods rely on the internal list of plugins that were loaded, but the order of that list is not stable. This commit changes that list to be the order plugins were loaded in, so that initialization of services of dependent plugins can be relied on.
1 parent edc7a61 commit 60ff86d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

docs/changelog/93882.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 93882
2+
summary: Ensure ordering of plugin initialization
3+
area: Infra/Plugins
4+
type: bug
5+
issues:
6+
- 93851

server/src/main/java/org/elasticsearch/plugins/PluginsService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.Collections;
5151
import java.util.HashMap;
5252
import java.util.HashSet;
53+
import java.util.LinkedHashMap;
5354
import java.util.LinkedHashSet;
5455
import java.util.List;
5556
import java.util.Locale;
@@ -102,7 +103,8 @@ record LoadedPlugin(PluginDescriptor descriptor, Plugin instance, ClassLoader lo
102103
private final Path configPath;
103104

104105
/**
105-
* We keep around a list of plugins and modules
106+
* We keep around a list of plugins and modules. The order of
107+
* this list is that which the plugins and modules were loaded in.
106108
*/
107109
private final List<LoadedPlugin> plugins;
108110
private final PluginsAndModules info;
@@ -156,7 +158,7 @@ public PluginsService(Settings settings, Path configPath, Path modulesDirectory,
156158
}
157159
}
158160

159-
Map<String, LoadedPlugin> loadedPlugins = loadBundles(seenBundles);
161+
LinkedHashMap<String, LoadedPlugin> loadedPlugins = loadBundles(seenBundles);
160162

161163
var inspector = PluginIntrospector.getInstance();
162164
this.info = new PluginsAndModules(getRuntimeInfos(inspector, pluginsList, loadedPlugins), modulesList);
@@ -280,8 +282,8 @@ protected List<LoadedPlugin> plugins() {
280282
return this.plugins;
281283
}
282284

283-
private Map<String, LoadedPlugin> loadBundles(Set<PluginBundle> bundles) {
284-
Map<String, LoadedPlugin> loaded = new HashMap<>();
285+
private LinkedHashMap<String, LoadedPlugin> loadBundles(Set<PluginBundle> bundles) {
286+
LinkedHashMap<String, LoadedPlugin> loaded = new LinkedHashMap<>();
285287
Map<String, Set<URL>> transitiveUrls = new HashMap<>();
286288
List<PluginBundle> sortedBundles = PluginsUtils.sortBundles(bundles);
287289
Set<URL> systemLoaderURLs = JarHell.parseModulesAndClassPath();

0 commit comments

Comments
 (0)