From 64ee3944601622a79b1b1b449192381e51a73fa6 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 15 Jul 2015 14:08:27 +0200 Subject: [PATCH] There is no need to check if the primary shards of the history indices are started, since we don't load watch records any more during the Watcher startup process. Original commit: elastic/x-pack-elasticsearch@e6bfb37477ec23c4ee6d88adfd937746d39a04ca --- .../watcher/execution/ExecutionService.java | 2 +- .../watcher/history/HistoryStore.java | 28 +------------------ .../watcher/history/HistoryStoreTests.java | 5 +--- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/watcher/src/main/java/org/elasticsearch/watcher/execution/ExecutionService.java b/watcher/src/main/java/org/elasticsearch/watcher/execution/ExecutionService.java index a2a02608ef8..375a40e35ac 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/execution/ExecutionService.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/execution/ExecutionService.java @@ -94,7 +94,7 @@ public class ExecutionService extends AbstractComponent { } public boolean validate(ClusterState state) { - return historyStore.validate(state) && triggeredWatchStore.validate(state); + return triggeredWatchStore.validate(state); } public void stop() { diff --git a/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java b/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java index bfc913e243b..ac37f09128c 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java @@ -7,10 +7,6 @@ package org.elasticsearch.watcher.history; import com.google.common.collect.ImmutableSet; import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -40,7 +36,6 @@ public class HistoryStore extends AbstractComponent { private static final ImmutableSet forbiddenIndexSettings = ImmutableSet.of("index.mapper.dynamic"); private final ClientProxy client; - private final IndexNameExpressionResolver indexNameExpressionResolver; private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); private final Lock putUpdateLock = readWriteLock.readLock(); @@ -48,36 +43,15 @@ public class HistoryStore extends AbstractComponent { private final AtomicBoolean started = new AtomicBoolean(false); @Inject - public HistoryStore(Settings settings, ClientProxy client, IndexNameExpressionResolver indexNameExpressionResolver) { + public HistoryStore(Settings settings, ClientProxy client) { super(settings); this.client = client; - this.indexNameExpressionResolver = indexNameExpressionResolver; } public void start() { started.set(true); } - public boolean validate(ClusterState state) { - String[] indices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.lenientExpandOpen(), INDEX_PREFIX + "*"); - if (indices.length == 0) { - logger.debug("no history indices exist, so we can load"); - return true; - } - - for (String index : indices) { - IndexMetaData indexMetaData = state.getMetaData().index(index); - if (indexMetaData != null) { - if (!state.routingTable().index(index).allPrimaryShardsActive()) { - logger.debug("not all primary shards of the [{}] index are started, so we cannot load watcher records", index); - return false; - } - } - } - - return true; - } - public void stop() { stopLock.lock(); //This will block while put or update actions are underway try { diff --git a/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java b/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java index ae279a7fb5c..c760fa1f2e2 100644 --- a/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java +++ b/watcher/src/test/java/org/elasticsearch/watcher/history/HistoryStoreTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.watcher.history; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESTestCase; @@ -31,13 +30,11 @@ public class HistoryStoreTests extends ESTestCase { private HistoryStore historyStore; private ClientProxy clientProxy; - private IndexNameExpressionResolver indexNameExpressionResolver; @Before public void init() { clientProxy = mock(ClientProxy.class); - indexNameExpressionResolver = mock(IndexNameExpressionResolver.class); - historyStore = new HistoryStore(Settings.EMPTY, clientProxy, indexNameExpressionResolver); + historyStore = new HistoryStore(Settings.EMPTY, clientProxy); historyStore.start(); }