Skip to content

Commit 4e137e5

Browse files
committed
Merge branch 'master' into compile-with-jdk-9
* master: Set the elasticsearch-nio codebase for tests (#28067) Bump compat version for local depdendent test to 6.2.0 Pass `java.locale.providers=COMPAT` to Java 9 onwards (#28080) Allow shrinking of indices from a previous major (#28076) Remove deprecated exceptions (#28059) Add Writeable.Reader support to TransportResponseHandler (#28010) Plugins: Add plugin extension capabilities (#27881)
2 parents fab460e + be5da28 commit 4e137e5

File tree

52 files changed

+1116
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1116
-296
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ task verifyVersions {
139139
* after the backport of the backcompat code is complete.
140140
*/
141141
allprojects {
142-
ext.bwc_tests_enabled = true
142+
// TODO: re-enable after https://github.com/elastic/elasticsearch/pull/27881 is backported
143+
ext.bwc_tests_enabled = false
143144
}
144145

145146
task verifyBwcTestsEnabled {

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginPropertiesExtension.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class PluginPropertiesExtension {
3939
@Input
4040
String classname
4141

42+
/** Other plugins this plugin extends through SPI */
43+
@Input
44+
List<String> extendedPlugins = []
45+
4246
@Input
4347
boolean hasNativeController = false
4448

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginPropertiesTask.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class PluginPropertiesTask extends Copy {
8080
'elasticsearchVersion': stringSnap(VersionProperties.elasticsearch),
8181
'javaVersion': project.targetCompatibility as String,
8282
'classname': extension.classname,
83+
'extendedPlugins': extension.extendedPlugins.join(','),
8384
'hasNativeController': extension.hasNativeController,
8485
'requiresKeystore': extension.requiresKeystore
8586
]

buildSrc/src/main/resources/plugin-descriptor.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ java.version=${javaVersion}
4040
elasticsearch.version=${elasticsearchVersion}
4141
### optional elements for plugins:
4242
#
43+
# 'extended.plugins': other plugins this plugin extends through SPI
44+
extended.plugins=${extendedPlugins}
45+
#
4346
# 'has.native.controller': whether or not the plugin has a native controller
4447
has.native.controller=${hasNativeController}
4548
#

core/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ archivesBaseName = 'elasticsearch'
3838

3939
dependencies {
4040

41+
compileOnly project(':libs:plugin-classloader')
42+
testRuntime project(':libs:plugin-classloader')
43+
4144
// lucene
4245
compile "org.apache.lucene:lucene-core:${versions.lucene}"
4346
compile "org.apache.lucene:lucene-analyzers-common:${versions.lucene}"

core/src/main/java/org/elasticsearch/ElasticsearchException.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,7 @@ private enum ElasticsearchExceptionHandle {
769769
// 26 was BatchOperationException
770770
SNAPSHOT_CREATION_EXCEPTION(org.elasticsearch.snapshots.SnapshotCreationException.class,
771771
org.elasticsearch.snapshots.SnapshotCreationException::new, 27, UNKNOWN_VERSION_ADDED),
772-
DELETE_FAILED_ENGINE_EXCEPTION(org.elasticsearch.index.engine.DeleteFailedEngineException.class, // deprecated in 6.0, remove in 7.0
773-
org.elasticsearch.index.engine.DeleteFailedEngineException::new, 28, UNKNOWN_VERSION_ADDED),
772+
// 28 was DeleteFailedEngineException, deprecated in 6.0, removed in 7.0
774773
DOCUMENT_MISSING_EXCEPTION(org.elasticsearch.index.engine.DocumentMissingException.class,
775774
org.elasticsearch.index.engine.DocumentMissingException::new, 29, UNKNOWN_VERSION_ADDED),
776775
SNAPSHOT_EXCEPTION(org.elasticsearch.snapshots.SnapshotException.class,
@@ -866,8 +865,7 @@ private enum ElasticsearchExceptionHandle {
866865
org.elasticsearch.action.TimestampParsingException::new, 78, UNKNOWN_VERSION_ADDED),
867866
ROUTING_MISSING_EXCEPTION(org.elasticsearch.action.RoutingMissingException.class,
868867
org.elasticsearch.action.RoutingMissingException::new, 79, UNKNOWN_VERSION_ADDED),
869-
INDEX_FAILED_ENGINE_EXCEPTION(org.elasticsearch.index.engine.IndexFailedEngineException.class, // deprecated in 6.0, remove in 7.0
870-
org.elasticsearch.index.engine.IndexFailedEngineException::new, 80, UNKNOWN_VERSION_ADDED),
868+
// 80 was IndexFailedEngineException, deprecated in 6.0, removed in 7.0
871869
INDEX_SHARD_RESTORE_FAILED_EXCEPTION(org.elasticsearch.index.snapshots.IndexShardRestoreFailedException.class,
872870
org.elasticsearch.index.snapshots.IndexShardRestoreFailedException::new, 81, UNKNOWN_VERSION_ADDED),
873871
REPOSITORY_EXCEPTION(org.elasticsearch.repositories.RepositoryException.class,

core/src/main/java/org/elasticsearch/bootstrap/ESPolicy.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.security.ProtectionDomain;
3434
import java.util.Collections;
3535
import java.util.Map;
36+
import java.util.Set;
3637
import java.util.function.Predicate;
3738

3839
/** custom policy for union of static and dynamic permissions */
@@ -49,9 +50,9 @@ final class ESPolicy extends Policy {
4950
final PermissionCollection dynamic;
5051
final Map<String,Policy> plugins;
5152

52-
ESPolicy(PermissionCollection dynamic, Map<String,Policy> plugins, boolean filterBadDefaults) {
53-
this.template = Security.readPolicy(getClass().getResource(POLICY_RESOURCE), JarHell.parseClassPath());
54-
this.untrusted = Security.readPolicy(getClass().getResource(UNTRUSTED_RESOURCE), Collections.emptySet());
53+
ESPolicy(Map<String, URL> codebases, PermissionCollection dynamic, Map<String,Policy> plugins, boolean filterBadDefaults) {
54+
this.template = Security.readPolicy(getClass().getResource(POLICY_RESOURCE), codebases);
55+
this.untrusted = Security.readPolicy(getClass().getResource(UNTRUSTED_RESOURCE), Collections.emptyMap());
5556
if (filterBadDefaults) {
5657
this.system = new SystemPolicy(Policy.getPolicy());
5758
} else {

core/src/main/java/org/elasticsearch/bootstrap/Security.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@
4848
import java.util.Collections;
4949
import java.util.HashMap;
5050
import java.util.HashSet;
51+
import java.util.LinkedHashMap;
5152
import java.util.LinkedHashSet;
5253
import java.util.List;
5354
import java.util.Map;
5455
import java.util.Set;
56+
import java.util.function.Function;
57+
import java.util.stream.Collectors;
5558

5659
import static org.elasticsearch.bootstrap.FilePermissionUtils.addDirectoryPath;
5760
import static org.elasticsearch.bootstrap.FilePermissionUtils.addSingleFilePath;
@@ -116,7 +119,8 @@ private Security() {}
116119
static void configure(Environment environment, boolean filterBadDefaults) throws IOException, NoSuchAlgorithmException {
117120

118121
// enable security policy: union of template and environment-based paths, and possibly plugin permissions
119-
Policy.setPolicy(new ESPolicy(createPermissions(environment), getPluginPermissions(environment), filterBadDefaults));
122+
Map<String, URL> codebases = getCodebaseJarMap(JarHell.parseClassPath());
123+
Policy.setPolicy(new ESPolicy(codebases, createPermissions(environment), getPluginPermissions(environment), filterBadDefaults));
120124

121125
// enable security manager
122126
final String[] classesThatCanExit =
@@ -130,6 +134,27 @@ static void configure(Environment environment, boolean filterBadDefaults) throws
130134
selfTest();
131135
}
132136

137+
/**
138+
* Return a map from codebase name to codebase url of jar codebases used by ES core.
139+
*/
140+
@SuppressForbidden(reason = "find URL path")
141+
static Map<String, URL> getCodebaseJarMap(Set<URL> urls) {
142+
Map<String, URL> codebases = new LinkedHashMap<>(); // maintain order
143+
for (URL url : urls) {
144+
try {
145+
String fileName = PathUtils.get(url.toURI()).getFileName().toString();
146+
if (fileName.endsWith(".jar") == false) {
147+
// tests :(
148+
continue;
149+
}
150+
codebases.put(fileName, url);
151+
} catch (URISyntaxException e) {
152+
throw new RuntimeException(e);
153+
}
154+
}
155+
return codebases;
156+
}
157+
133158
/**
134159
* Sets properties (codebase URLs) for policy files.
135160
* we look for matching plugins and set URLs to fit
@@ -174,7 +199,7 @@ static Map<String,Policy> getPluginPermissions(Environment environment) throws I
174199
}
175200

176201
// parse the plugin's policy file into a set of permissions
177-
Policy policy = readPolicy(policyFile.toUri().toURL(), codebases);
202+
Policy policy = readPolicy(policyFile.toUri().toURL(), getCodebaseJarMap(codebases));
178203

179204
// consult this policy for each of the plugin's jars:
180205
for (URL url : codebases) {
@@ -197,21 +222,20 @@ static Map<String,Policy> getPluginPermissions(Environment environment) throws I
197222
* would map to full URL.
198223
*/
199224
@SuppressForbidden(reason = "accesses fully qualified URLs to configure security")
200-
static Policy readPolicy(URL policyFile, Set<URL> codebases) {
225+
static Policy readPolicy(URL policyFile, Map<String, URL> codebases) {
201226
try {
202227
List<String> propertiesSet = new ArrayList<>();
203228
try {
204229
// set codebase properties
205-
for (URL url : codebases) {
206-
String fileName = PathUtils.get(url.toURI()).getFileName().toString();
207-
if (fileName.endsWith(".jar") == false) {
208-
continue; // tests :(
209-
}
230+
for (Map.Entry<String,URL> codebase : codebases.entrySet()) {
231+
String name = codebase.getKey();
232+
URL url = codebase.getValue();
233+
210234
// We attempt to use a versionless identifier for each codebase. This assumes a specific version
211235
// format in the jar filename. While we cannot ensure all jars in all plugins use this format, nonconformity
212236
// only means policy grants would need to include the entire jar filename as they always have before.
213-
String property = "codebase." + fileName;
214-
String aliasProperty = "codebase." + fileName.replaceFirst("-\\d+\\.\\d+.*\\.jar", "");
237+
String property = "codebase." + name;
238+
String aliasProperty = "codebase." + name.replaceFirst("-\\d+\\.\\d+.*\\.jar", "");
215239
if (aliasProperty.equals(property) == false) {
216240
propertiesSet.add(aliasProperty);
217241
String previous = System.setProperty(aliasProperty, url.toString());

core/src/main/java/org/elasticsearch/index/engine/IndexFailedEngineException.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

core/src/main/java/org/elasticsearch/index/shard/StoreRecovery.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,22 @@ boolean recoverFromLocalShards(BiConsumer<String, MappingMetaData> mappingUpdate
145145
void addIndices(final RecoveryState.Index indexRecoveryStats, final Directory target, final Sort indexSort, final Directory[] sources,
146146
final long maxSeqNo, final long maxUnsafeAutoIdTimestamp, IndexMetaData indexMetaData, int shardId, boolean split,
147147
boolean hasNested) throws IOException {
148+
149+
// clean target directory (if previous recovery attempt failed) and create a fresh segment file with the proper lucene version
150+
Lucene.cleanLuceneIndex(target);
151+
assert sources.length > 0;
152+
final int luceneIndexCreatedVersionMajor = Lucene.readSegmentInfos(sources[0]).getIndexCreatedVersionMajor();
153+
new SegmentInfos(luceneIndexCreatedVersionMajor).commit(target);
154+
148155
final Directory hardLinkOrCopyTarget = new org.apache.lucene.store.HardlinkCopyDirectoryWrapper(target);
156+
149157
IndexWriterConfig iwc = new IndexWriterConfig(null)
150158
.setCommitOnClose(false)
151159
// we don't want merges to happen here - we call maybe merge on the engine
152160
// later once we stared it up otherwise we would need to wait for it here
153161
// we also don't specify a codec here and merges should use the engines for this index
154162
.setMergePolicy(NoMergePolicy.INSTANCE)
155-
.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
163+
.setOpenMode(IndexWriterConfig.OpenMode.APPEND);
156164
if (indexSort != null) {
157165
iwc.setIndexSort(indexSort);
158166
}

core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ private class ShardActiveResponseHandler implements TransportResponseHandler<Sha
238238
}
239239

240240
@Override
241-
public ShardActiveResponse newInstance() {
242-
return new ShardActiveResponse();
241+
public ShardActiveResponse read(StreamInput in) throws IOException {
242+
return new ShardActiveResponse(in);
243243
}
244244

245245
@Override
@@ -417,20 +417,15 @@ public void writeTo(StreamOutput out) throws IOException {
417417

418418
private static class ShardActiveResponse extends TransportResponse {
419419

420-
private boolean shardActive;
421-
private DiscoveryNode node;
422-
423-
ShardActiveResponse() {
424-
}
420+
private final boolean shardActive;
421+
private final DiscoveryNode node;
425422

426423
ShardActiveResponse(boolean shardActive, DiscoveryNode node) {
427424
this.shardActive = shardActive;
428425
this.node = node;
429426
}
430427

431-
@Override
432-
public void readFrom(StreamInput in) throws IOException {
433-
super.readFrom(in);
428+
ShardActiveResponse(StreamInput in) throws IOException {
434429
shardActive = in.readBoolean();
435430
node = new DiscoveryNode(in);
436431
}

core/src/main/java/org/elasticsearch/index/engine/DeleteFailedEngineException.java renamed to core/src/main/java/org/elasticsearch/plugins/ExtensiblePlugin.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,18 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.index.engine;
21-
22-
import org.elasticsearch.common.io.stream.StreamInput;
23-
import org.elasticsearch.index.shard.ShardId;
24-
25-
import java.io.IOException;
20+
package org.elasticsearch.plugins;
2621

2722
/**
28-
* Deprecated as not used in 6.0, should be removed in 7.0
29-
* Still exists for bwc in serializing/deserializing from
30-
* 5.x nodes
23+
* An extension point for {@link Plugin} implementations to be themselves extensible.
24+
*
25+
* This class provides a callback for extensible plugins to be informed of other plugins
26+
* which extend them.
3127
*/
32-
@Deprecated
33-
public class DeleteFailedEngineException extends EngineException {
34-
public DeleteFailedEngineException(StreamInput in) throws IOException{
35-
super(in);
36-
}
37-
}
28+
public interface ExtensiblePlugin {
29+
30+
/**
31+
* Reload any SPI implementations from the given classloader.
32+
*/
33+
default void reloadSPI(ClassLoader loader) {}
34+
}

0 commit comments

Comments
 (0)