|
37 | 37 | import org.elasticsearch.common.unit.ByteSizeValue;
|
38 | 38 | import org.elasticsearch.common.xcontent.XContentType;
|
39 | 39 | import org.elasticsearch.index.Index;
|
| 40 | +import org.elasticsearch.index.IndexService; |
40 | 41 | import org.elasticsearch.index.IndexSettings;
|
41 | 42 | import org.elasticsearch.index.engine.Engine;
|
42 | 43 | import org.elasticsearch.index.engine.InternalEngine;
|
|
47 | 48 | import org.elasticsearch.index.shard.IndexShard;
|
48 | 49 | import org.elasticsearch.index.shard.IndexShardTestCase;
|
49 | 50 | import org.elasticsearch.index.shard.ShardId;
|
| 51 | +import org.elasticsearch.indices.IndexingMemoryController; |
50 | 52 | import org.elasticsearch.indices.IndicesService;
|
| 53 | +import org.elasticsearch.plugins.Plugin; |
51 | 54 | import org.elasticsearch.test.ESIntegTestCase;
|
| 55 | +import org.elasticsearch.test.InternalSettingsPlugin; |
| 56 | +import org.elasticsearch.test.InternalTestCluster; |
52 | 57 |
|
53 | 58 | import java.io.IOException;
|
54 | 59 | import java.util.Arrays;
|
| 60 | +import java.util.Collection; |
| 61 | +import java.util.Collections; |
55 | 62 | import java.util.List;
|
56 | 63 | import java.util.Map;
|
57 | 64 | import java.util.concurrent.CopyOnWriteArrayList;
|
58 | 65 | import java.util.concurrent.CountDownLatch;
|
| 66 | +import java.util.concurrent.TimeUnit; |
59 | 67 | import java.util.concurrent.atomic.AtomicBoolean;
|
60 | 68 | import java.util.concurrent.atomic.AtomicInteger;
|
61 | 69 | import java.util.stream.Collectors;
|
|
71 | 79 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST)
|
72 | 80 | public class FlushIT extends ESIntegTestCase {
|
73 | 81 |
|
| 82 | + @Override |
| 83 | + protected Collection<Class<? extends Plugin>> nodePlugins() { |
| 84 | + return Collections.singletonList(InternalSettingsPlugin.class); |
| 85 | + } |
| 86 | + |
74 | 87 | public void testWaitIfOngoing() throws InterruptedException {
|
75 | 88 | createIndex("test");
|
76 | 89 | ensureGreen("test");
|
@@ -369,4 +382,29 @@ public void testDoNotRenewSyncedFlushWhenAllSealed() throws Exception {
|
369 | 382 | assertThat(forthSeal.successfulShards(), equalTo(numberOfReplicas + 1));
|
370 | 383 | assertThat(forthSeal.syncId(), not(equalTo(thirdSeal.syncId())));
|
371 | 384 | }
|
| 385 | + |
| 386 | + public void testFlushOnInactive() throws Exception { |
| 387 | + final String indexName = "flush_on_inactive"; |
| 388 | + List<String> dataNodes = internalCluster().startDataOnlyNodes(2, Settings.builder() |
| 389 | + .put(IndexingMemoryController.SHARD_INACTIVE_TIME_SETTING.getKey(), randomTimeValue(10, 1000, "ms")).build()); |
| 390 | + assertAcked(client().admin().indices().prepareCreate(indexName).setSettings(Settings.builder() |
| 391 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) |
| 392 | + .put(IndexService.GLOBAL_CHECKPOINT_SYNC_INTERVAL_SETTING.getKey(), randomTimeValue(50, 200, "ms")) |
| 393 | + .put("index.routing.allocation.include._name", String.join(",", dataNodes)) |
| 394 | + .build())); |
| 395 | + ensureGreen(indexName); |
| 396 | + int numDocs = randomIntBetween(1, 10); |
| 397 | + for (int i = 0; i < numDocs; i++) { |
| 398 | + client().prepareIndex(indexName, "_doc").setSource("f", "v").get(); |
| 399 | + } |
| 400 | + if (randomBoolean()) { |
| 401 | + internalCluster().restartNode(randomFrom(dataNodes), new InternalTestCluster.RestartCallback()); |
| 402 | + ensureGreen(indexName); |
| 403 | + } |
| 404 | + assertBusy(() -> { |
| 405 | + for (ShardStats shardStats : client().admin().indices().prepareStats(indexName).get().getShards()) { |
| 406 | + assertThat(shardStats.getStats().getTranslog().getUncommittedOperations(), equalTo(0)); |
| 407 | + } |
| 408 | + }, 30, TimeUnit.SECONDS); |
| 409 | + } |
372 | 410 | }
|
0 commit comments