From 8c6e197f510c13511cb1c5b325340d3eedc45702 Mon Sep 17 00:00:00 2001 From: Howard Date: Thu, 1 Oct 2020 01:20:44 +0800 Subject: [PATCH] Remove allocation id from engine (#62680) We no longer need the allocation id in Engine. --- .../indices/IndexingMemoryControllerIT.java | 2 +- .../java/org/elasticsearch/index/engine/Engine.java | 2 -- .../elasticsearch/index/engine/EngineConfig.java | 13 +------------ .../org/elasticsearch/index/shard/IndexShard.java | 2 +- .../index/engine/InternalEngineTests.java | 3 +-- .../elasticsearch/index/shard/IndexShardTests.java | 2 +- .../index/shard/RefreshListenersTests.java | 1 - .../indices/IndexingMemoryControllerTests.java | 2 +- .../elasticsearch/index/engine/EngineTestCase.java | 9 ++++----- .../ccr/index/engine/FollowingEngineTests.java | 1 - 10 files changed, 10 insertions(+), 27 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/IndexingMemoryControllerIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/IndexingMemoryControllerIT.java index c9c4988d93f..c33a5aa056c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/IndexingMemoryControllerIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/IndexingMemoryControllerIT.java @@ -64,7 +64,7 @@ public class IndexingMemoryControllerIT extends ESSingleNodeTestCase { Settings settings = Settings.builder().put(config.getIndexSettings().getSettings()) .put("indices.memory.index_buffer_size", "10mb").build(); IndexSettings indexSettings = new IndexSettings(config.getIndexSettings().getIndexMetadata(), settings); - return new EngineConfig(config.getShardId(), config.getAllocationId(), config.getThreadPool(), + return new EngineConfig(config.getShardId(), config.getThreadPool(), indexSettings, config.getWarmer(), config.getStore(), config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), new CodecService(null, LogManager.getLogger(IndexingMemoryControllerIT.class)), config.getEventListener(), config.getQueryCache(), diff --git a/server/src/main/java/org/elasticsearch/index/engine/Engine.java b/server/src/main/java/org/elasticsearch/index/engine/Engine.java index 45f60695ea9..c9f9ecbe25e 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/Engine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/Engine.java @@ -117,7 +117,6 @@ public abstract class Engine implements Closeable { public static final String CAN_MATCH_SEARCH_SOURCE = "can_match"; protected final ShardId shardId; - protected final String allocationId; protected final Logger logger; protected final EngineConfig engineConfig; protected final Store store; @@ -147,7 +146,6 @@ public abstract class Engine implements Closeable { this.engineConfig = engineConfig; this.shardId = engineConfig.getShardId(); - this.allocationId = engineConfig.getAllocationId(); this.store = engineConfig.getStore(); // we use the engine class directly here to make sure all subclasses have the same logger name this.logger = Loggers.getLogger(Engine.class, diff --git a/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java b/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java index 7716cf93ffd..2cf762cdb2c 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java +++ b/server/src/main/java/org/elasticsearch/index/engine/EngineConfig.java @@ -55,7 +55,6 @@ import java.util.function.Supplier; */ public final class EngineConfig { private final ShardId shardId; - private final String allocationId; private final IndexSettings indexSettings; private final ByteSizeValue indexingBufferSize; private volatile boolean enableGcDeletes = true; @@ -131,7 +130,7 @@ public final class EngineConfig { /** * Creates a new {@link org.elasticsearch.index.engine.EngineConfig} */ - public EngineConfig(ShardId shardId, String allocationId, ThreadPool threadPool, + public EngineConfig(ShardId shardId, ThreadPool threadPool, IndexSettings indexSettings, Engine.Warmer warmer, Store store, MergePolicy mergePolicy, Analyzer analyzer, Similarity similarity, CodecService codecService, Engine.EventListener eventListener, @@ -144,7 +143,6 @@ public final class EngineConfig { LongSupplier primaryTermSupplier, TombstoneDocSupplier tombstoneDocSupplier) { this.shardId = shardId; - this.allocationId = allocationId; this.indexSettings = indexSettings; this.threadPool = threadPool; this.warmer = warmer == null ? (a) -> {} : warmer; @@ -286,15 +284,6 @@ public final class EngineConfig { */ public ShardId getShardId() { return shardId; } - /** - * Returns the allocation ID for the shard. - * - * @return the allocation ID - */ - public String getAllocationId() { - return allocationId; - } - /** * Returns the analyzer as the default analyzer in the engines {@link org.apache.lucene.index.IndexWriter} */ diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java index d62b63f694d..34891621a04 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -2780,7 +2780,7 @@ public class IndexShard extends AbstractIndexShardComponent implements IndicesCl this.warmer.warm(reader); } }; - return new EngineConfig(shardId, shardRouting.allocationId().getId(), + return new EngineConfig(shardId, threadPool, indexSettings, warmer, store, indexSettings.getMergePolicy(), mapperService != null ? mapperService.indexAnalyzer() : null, similarityService.similarity(mapperService), codecService, shardEventListener, diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index fabbdb641e8..a2483f13857 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -3193,7 +3193,6 @@ public class InternalEngineTests extends EngineTestCase { EngineConfig brokenConfig = new EngineConfig( shardId, - allocationId.getId(), threadPool, config.getIndexSettings(), null, @@ -6257,7 +6256,7 @@ public class InternalEngineTests extends EngineTestCase { EngineConfig config = engine.config(); final TranslogConfig translogConfig = new TranslogConfig(config.getTranslogConfig().getShardId(), createTempDir(), config.getTranslogConfig().getIndexSettings(), config.getTranslogConfig().getBigArrays()); - EngineConfig configWithWarmer = new EngineConfig(config.getShardId(), config.getAllocationId(), config.getThreadPool(), + EngineConfig configWithWarmer = new EngineConfig(config.getShardId(), config.getThreadPool(), config.getIndexSettings(), warmer, store, config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), new CodecService(null, logger), config.getEventListener(), config.getQueryCache(), config.getQueryCachingPolicy(), translogConfig, config.getFlushMergesAfter(), diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index 728c83f6b52..a08e75e9b08 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -4175,7 +4175,7 @@ public class IndexShardTests extends IndexShardTestCase { throw new AssertionError(e); } }; - EngineConfig configWithWarmer = new EngineConfig(config.getShardId(), config.getAllocationId(), config.getThreadPool(), + EngineConfig configWithWarmer = new EngineConfig(config.getShardId(), config.getThreadPool(), config.getIndexSettings(), warmer, config.getStore(), config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), new CodecService(null, logger), config.getEventListener(), config.getQueryCache(), config.getQueryCachingPolicy(), config.getTranslogConfig(), config.getFlushMergesAfter(), diff --git a/server/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java b/server/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java index 774499ba982..6469b2724bf 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/RefreshListenersTests.java @@ -128,7 +128,6 @@ public class RefreshListenersTests extends ESTestCase { store.associateIndexWithNewTranslog(translogUUID); EngineConfig config = new EngineConfig( shardId, - allocationId, threadPool, indexSettings, null, diff --git a/server/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java b/server/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java index 537a068a373..2a6fd2f3195 100644 --- a/server/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java +++ b/server/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java @@ -376,7 +376,7 @@ public class IndexingMemoryControllerTests extends IndexShardTestCase { EngineConfig configWithRefreshListener(EngineConfig config, ReferenceManager.RefreshListener listener) { final List internalRefreshListener = new ArrayList<>(config.getInternalRefreshListener());; internalRefreshListener.add(listener); - return new EngineConfig(config.getShardId(), config.getAllocationId(), config.getThreadPool(), + return new EngineConfig(config.getShardId(), config.getThreadPool(), config.getIndexSettings(), config.getWarmer(), config.getStore(), config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), new CodecService(null, logger), config.getEventListener(), config.getQueryCache(), config.getQueryCachingPolicy(), config.getTranslogConfig(), config.getFlushMergesAfter(), diff --git a/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java index 7813ec9af82..868ca1ccdcd 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java @@ -233,7 +233,7 @@ public abstract class EngineTestCase extends ESTestCase { } public EngineConfig copy(EngineConfig config, LongSupplier globalCheckpointSupplier) { - return new EngineConfig(config.getShardId(), config.getAllocationId(), config.getThreadPool(), config.getIndexSettings(), + return new EngineConfig(config.getShardId(), config.getThreadPool(), config.getIndexSettings(), config.getWarmer(), config.getStore(), config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), new CodecService(null, logger), config.getEventListener(), config.getQueryCache(), config.getQueryCachingPolicy(), config.getTranslogConfig(), config.getFlushMergesAfter(), @@ -243,7 +243,7 @@ public abstract class EngineTestCase extends ESTestCase { } public EngineConfig copy(EngineConfig config, Analyzer analyzer) { - return new EngineConfig(config.getShardId(), config.getAllocationId(), config.getThreadPool(), config.getIndexSettings(), + return new EngineConfig(config.getShardId(), config.getThreadPool(), config.getIndexSettings(), config.getWarmer(), config.getStore(), config.getMergePolicy(), analyzer, config.getSimilarity(), new CodecService(null, logger), config.getEventListener(), config.getQueryCache(), config.getQueryCachingPolicy(), config.getTranslogConfig(), config.getFlushMergesAfter(), @@ -253,7 +253,7 @@ public abstract class EngineTestCase extends ESTestCase { } public EngineConfig copy(EngineConfig config, MergePolicy mergePolicy) { - return new EngineConfig(config.getShardId(), config.getAllocationId(), config.getThreadPool(), config.getIndexSettings(), + return new EngineConfig(config.getShardId(), config.getThreadPool(), config.getIndexSettings(), config.getWarmer(), config.getStore(), mergePolicy, config.getAnalyzer(), config.getSimilarity(), new CodecService(null, logger), config.getEventListener(), config.getQueryCache(), config.getQueryCachingPolicy(), config.getTranslogConfig(), config.getFlushMergesAfter(), @@ -686,7 +686,6 @@ public abstract class EngineTestCase extends ESTestCase { } return new EngineConfig( shardId, - allocationId.getId(), threadPool, indexSettings, null, @@ -716,7 +715,7 @@ public abstract class EngineTestCase extends ESTestCase { Settings.builder().put(config.getIndexSettings().getSettings()) .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true).build()); TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettings, BigArrays.NON_RECYCLING_INSTANCE); - return new EngineConfig(config.getShardId(), config.getAllocationId(), config.getThreadPool(), + return new EngineConfig(config.getShardId(), config.getThreadPool(), indexSettings, config.getWarmer(), store, config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), new CodecService(null, logger), config.getEventListener(), config.getQueryCache(), config.getQueryCachingPolicy(), translogConfig, config.getFlushMergesAfter(), config.getExternalRefreshListener(), diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowingEngineTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowingEngineTests.java index 060554011d2..31182a0c7db 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowingEngineTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/index/engine/FollowingEngineTests.java @@ -246,7 +246,6 @@ public class FollowingEngineTests extends ESTestCase { final TranslogConfig translogConfig = new TranslogConfig(shardId, translogPath, indexSettings, BigArrays.NON_RECYCLING_INSTANCE); return new EngineConfig( shardId, - "allocation-id", threadPool, indexSettings, null,