true
iff the given listener is already registered otherwise false
+ */
+ public boolean isRegistered(Listener listener) {
+ return listeners.contains(listener);
+ }
public interface Listener {
void onRefreshSettings(Settings settings);
}
diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java
index e2e3720735b..b9dd7853812 100644
--- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java
+++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java
@@ -37,10 +37,8 @@ import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest;
import org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest;
import org.elasticsearch.action.termvectors.TermVectorsRequest;
import org.elasticsearch.action.termvectors.TermVectorsResponse;
-import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
-import org.elasticsearch.cluster.routing.RestoreSource;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.common.Booleans;
@@ -85,6 +83,7 @@ import org.elasticsearch.index.recovery.RecoveryStats;
import org.elasticsearch.index.refresh.RefreshStats;
import org.elasticsearch.index.search.stats.SearchStats;
import org.elasticsearch.index.search.stats.ShardSearchStats;
+import org.elasticsearch.index.settings.IndexSettings;
import org.elasticsearch.index.settings.IndexSettingsService;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.snapshots.IndexShardRepository;
@@ -121,10 +120,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-public class IndexShard extends AbstractIndexShardComponent {
+public class IndexShard extends AbstractIndexShardComponent implements IndexSettingsService.Listener {
private final ThreadPool threadPool;
- private final IndexSettingsService indexSettingsService;
private final MapperService mapperService;
private final IndexQueryParserService queryParserService;
private final IndexCache indexCache;
@@ -144,8 +142,6 @@ public class IndexShard extends AbstractIndexShardComponent {
private final IndexFieldDataService indexFieldDataService;
private final ShardSuggestMetric shardSuggestMetric = new ShardSuggestMetric();
private final ShardBitsetFilterCache shardBitsetFilterCache;
- private final DiscoveryNode localNode;
-
private final Object mutex = new Object();
private final String checkIndexOnStartup;
private final CodecService codecService;
@@ -171,9 +167,6 @@ public class IndexShard extends AbstractIndexShardComponent {
private RecoveryState recoveryState;
private final RecoveryStats recoveryStats = new RecoveryStats();
-
- private ApplyRefreshSettings applyRefreshSettings = new ApplyRefreshSettings();
-
private final MeanMetric refreshMetric = new MeanMetric();
private final MeanMetric flushMetric = new MeanMetric();
@@ -200,13 +193,13 @@ public class IndexShard extends AbstractIndexShardComponent {
private EnumSettrue
if the the shard has been recovered successfully, false
if the recovery
* has been ignored due to a concurrent modification of if the clusters state has changed due to async updates.
*/
- boolean recoverFromRepository(final IndexShard indexShard, IndexShardRepository repository) {
+ boolean recoverFromRepository(final IndexShard indexShard, IndexShardRepository repository, DiscoveryNode localNode) {
if (canRecover(indexShard)) {
- if (indexShard.routingEntry().restoreSource() == null) {
+ final ShardRouting shardRouting = indexShard.routingEntry();
+ if (shardRouting.restoreSource() == null) {
throw new IllegalStateException("can't restore - restore source is null");
}
try {
- indexShard.recovering("from snapshot", RecoveryState.Type.SNAPSHOT, indexShard.routingEntry().restoreSource());
+ final RecoveryState recoveryState = new RecoveryState(shardId, shardRouting.primary(), RecoveryState.Type.SNAPSHOT, shardRouting.restoreSource(), localNode);
+ indexShard.recovering("from snapshot", recoveryState);
} catch (IllegalIndexShardStateException e) {
// that's fine, since we might be called concurrently, just ignore this, we are already recovering
return false;
}
return executeRecovery(indexShard, () -> {
- logger.debug("restoring from {} ...", indexShard.routingEntry().restoreSource());
+ logger.debug("restoring from {} ...", shardRouting.restoreSource());
restore(indexShard, repository);
});
}
diff --git a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java
index 4f59428eede..8331a3d1a27 100644
--- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java
+++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java
@@ -677,14 +677,15 @@ public class IndicesClusterStateService extends AbstractLifecycleComponentdiff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index 08c2f8773fa..25a8bf2b40e 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -40,6 +40,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.InternalClusterInfoService; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.SnapshotId; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.*; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -48,6 +49,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -787,7 +789,8 @@ public class IndexShardTests extends ESSingleNodeTestCase { ShardRoutingHelper.reinit(routing); IndexShard newShard = test.createShard(0, routing); newShard.updateRoutingEntry(routing, false); - assertTrue(newShard.recoverFromStore(routing)); + DiscoveryNode localNode = new DiscoveryNode("foo", DummyTransportAddress.INSTANCE, Version.CURRENT); + assertTrue(newShard.recoverFromStore(routing, localNode)); routing = new ShardRouting(routing); ShardRoutingHelper.moveToStarted(routing); newShard.updateRoutingEntry(routing, true); @@ -799,6 +802,7 @@ public class IndexShardTests extends ESSingleNodeTestCase { createIndex("test"); ensureGreen(); IndicesService indicesService = getInstanceFromNode(IndicesService.class); + DiscoveryNode localNode = new DiscoveryNode("foo", DummyTransportAddress.INSTANCE, Version.CURRENT); IndexService test = indicesService.indexService("test"); final IndexShard shard = test.shard(0); @@ -817,7 +821,7 @@ public class IndexShardTests extends ESSingleNodeTestCase { IndexShard newShard = test.createShard(0, routing); newShard.updateRoutingEntry(routing, false); try { - newShard.recoverFromStore(routing); + newShard.recoverFromStore(routing, localNode); fail("index not there!"); } catch (IndexShardRecoveryException ex) { assertTrue(ex.getMessage().contains("failed to fetch index version after copying it over")); @@ -826,11 +830,11 @@ public class IndexShardTests extends ESSingleNodeTestCase { ShardRoutingHelper.moveToUnassigned(routing, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "because I say so")); ShardRoutingHelper.initialize(routing, origRouting.currentNodeId()); - assertFalse("it's already recovering", newShard.recoverFromStore(routing)); + assertFalse("it's already recovering", newShard.recoverFromStore(routing, localNode)); test.removeShard(0, "I broken it"); newShard = test.createShard(0, routing); newShard.updateRoutingEntry(routing, false); - assertTrue("recover even if there is nothing to recover", newShard.recoverFromStore(routing)); + assertTrue("recover even if there is nothing to recover", newShard.recoverFromStore(routing, localNode)); routing = new ShardRouting(routing); ShardRoutingHelper.moveToStarted(routing); @@ -865,6 +869,7 @@ public class IndexShardTests extends ESSingleNodeTestCase { Store targetStore = test_target_shard.store(); test_target_shard.updateRoutingEntry(routing, false); + DiscoveryNode localNode = new DiscoveryNode("foo", DummyTransportAddress.INSTANCE, Version.CURRENT); assertTrue(test_target_shard.restoreFromRepository(routing, new IndexShardRepository() { @Override public void snapshot(SnapshotId snapshotId, ShardId shardId, IndexCommit snapshotIndexCommit, IndexShardSnapshotStatus snapshotStatus) { @@ -893,7 +898,7 @@ public class IndexShardTests extends ESSingleNodeTestCase { @Override public void verify(String verificationToken) { } - })); + }, localNode)); routing = new ShardRouting(routing); ShardRoutingHelper.moveToStarted(routing); @@ -902,4 +907,15 @@ public class IndexShardTests extends ESSingleNodeTestCase { assertSearchHits(client().prepareSearch("test_target").get(), "0"); } + public void testListenersAreRemoved() { + createIndex("test"); + ensureGreen(); + IndicesService indicesService = getInstanceFromNode(IndicesService.class); + IndexService indexService = indicesService.indexService("test"); + IndexShard shard = indexService.shard(0); + IndexSettingsService settingsService = indexService.settingsService(); + assertTrue(settingsService.isRegistered(shard)); + indexService.removeShard(0, "simon says so"); + assertFalse(settingsService.isRegistered(shard)); + } }