|
31 | 31 | import org.elasticsearch.index.engine.InternalEngine; |
32 | 32 | import org.elasticsearch.index.engine.NoOpEngine; |
33 | 33 | import org.elasticsearch.index.shard.IndexShard; |
34 | | -import org.elasticsearch.index.translog.TranslogStats; |
35 | 34 | import org.elasticsearch.indices.IndicesService; |
36 | 35 | import org.elasticsearch.plugins.ClusterPlugin; |
37 | 36 | import org.elasticsearch.plugins.EnginePlugin; |
@@ -97,11 +96,7 @@ public Decision canForceAllocatePrimary(ShardRouting shardRouting, RoutingNode n |
97 | 96 |
|
98 | 97 | @Override |
99 | 98 | public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) { |
100 | | - return Optional.of( |
101 | | - config -> config.isPromotableToPrimary() |
102 | | - ? new InternalEngine(config) |
103 | | - : new NoOpEngine(config, new TranslogStats(0, 0, 0, 0, 0)) |
104 | | - ); |
| 99 | + return Optional.of(config -> config.isPromotableToPrimary() ? new InternalEngine(config) : new NoOpEngine(config)); |
105 | 100 | } |
106 | 101 | } |
107 | 102 |
|
@@ -300,7 +295,8 @@ private void assertEngineTypes() { |
300 | 295 | for (IndexShard indexShard : indexService) { |
301 | 296 | final var engine = indexShard.getEngineOrNull(); |
302 | 297 | assertNotNull(engine); |
303 | | - if (indexShard.routingEntry().isPromotableToPrimary()) { |
| 298 | + if (indexShard.routingEntry().isPromotableToPrimary() |
| 299 | + && indexShard.indexSettings().getIndexMetadata().getState() == IndexMetadata.State.OPEN) { |
304 | 300 | assertThat(engine, instanceOf(InternalEngine.class)); |
305 | 301 | } else { |
306 | 302 | assertThat(engine, instanceOf(NoOpEngine.class)); |
@@ -453,4 +449,27 @@ public void testSearchRouting() { |
453 | 449 | } |
454 | 450 | } |
455 | 451 |
|
| 452 | + public void testClosedIndex() { |
| 453 | + var routingTableWatcher = new RoutingTableWatcher(); |
| 454 | + |
| 455 | + var numDataNodes = routingTableWatcher.numReplicas + 2; |
| 456 | + internalCluster().ensureAtLeastNumDataNodes(numDataNodes); |
| 457 | + getMasterNodePlugin().numIndexingCopies = routingTableWatcher.numIndexingCopies; |
| 458 | + |
| 459 | + final var masterClusterService = internalCluster().getCurrentMasterNodeInstance(ClusterService.class); |
| 460 | + try { |
| 461 | + // verify the correct number of shard copies of each role as the routing table evolves |
| 462 | + masterClusterService.addListener(routingTableWatcher); |
| 463 | + |
| 464 | + createIndex(INDEX_NAME, routingTableWatcher.getIndexSettings()); |
| 465 | + ensureGreen(INDEX_NAME); |
| 466 | + assertEngineTypes(); |
| 467 | + |
| 468 | + assertAcked(client().admin().indices().prepareClose(INDEX_NAME)); |
| 469 | + ensureGreen(INDEX_NAME); |
| 470 | + assertEngineTypes(); |
| 471 | + } finally { |
| 472 | + masterClusterService.removeListener(routingTableWatcher); |
| 473 | + } |
| 474 | + } |
456 | 475 | } |
0 commit comments