|
72 | 72 | import org.elasticsearch.core.internal.io.IOUtils;
|
73 | 73 | import org.elasticsearch.env.NodeEnvironment;
|
74 | 74 | import org.elasticsearch.index.IndexSettings;
|
| 75 | +import org.elasticsearch.index.MergePolicyConfig; |
75 | 76 | import org.elasticsearch.index.VersionType;
|
76 | 77 | import org.elasticsearch.index.engine.Engine;
|
77 | 78 | import org.elasticsearch.index.engine.EngineException;
|
78 | 79 | import org.elasticsearch.index.engine.InternalEngine;
|
| 80 | +import org.elasticsearch.index.engine.Segment; |
79 | 81 | import org.elasticsearch.index.engine.SegmentsStats;
|
80 | 82 | import org.elasticsearch.index.fielddata.FieldDataStats;
|
81 | 83 | import org.elasticsearch.index.fielddata.IndexFieldData;
|
@@ -1867,7 +1869,7 @@ public IndexSearcher wrap(IndexSearcher searcher) throws EngineException {
|
1867 | 1869 | closeShards(shard);
|
1868 | 1870 | IndexShard newShard = newShard(
|
1869 | 1871 | ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE),
|
1870 |
| - shard.shardPath(), shard.indexSettings().getIndexMetaData(), wrapper, null, () -> {}); |
| 1872 | + shard.shardPath(), shard.indexSettings().getIndexMetaData(), wrapper, null, () -> {}, EMPTY_EVENT_LISTENER); |
1871 | 1873 |
|
1872 | 1874 | recoverShardFromStore(newShard);
|
1873 | 1875 |
|
@@ -2013,7 +2015,7 @@ public IndexSearcher wrap(IndexSearcher searcher) throws EngineException {
|
2013 | 2015 | closeShards(shard);
|
2014 | 2016 | IndexShard newShard = newShard(
|
2015 | 2017 | ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE),
|
2016 |
| - shard.shardPath(), shard.indexSettings().getIndexMetaData(), wrapper, null, () -> {}); |
| 2018 | + shard.shardPath(), shard.indexSettings().getIndexMetaData(), wrapper, null, () -> {}, EMPTY_EVENT_LISTENER); |
2017 | 2019 |
|
2018 | 2020 | recoverShardFromStore(newShard);
|
2019 | 2021 |
|
@@ -2496,7 +2498,7 @@ public void testReadSnapshotAndCheckIndexConcurrently() throws Exception {
|
2496 | 2498 | .put(IndexSettings.INDEX_CHECK_ON_STARTUP.getKey(), randomFrom("false", "true", "checksum", "fix")))
|
2497 | 2499 | .build();
|
2498 | 2500 | final IndexShard newShard = newShard(shardRouting, indexShard.shardPath(), indexMetaData,
|
2499 |
| - null, indexShard.engineFactory, indexShard.getGlobalCheckpointSyncer()); |
| 2501 | + null, indexShard.engineFactory, indexShard.getGlobalCheckpointSyncer(), EMPTY_EVENT_LISTENER); |
2500 | 2502 |
|
2501 | 2503 | Store.MetadataSnapshot storeFileMetaDatas = newShard.snapshotStoreMetadata();
|
2502 | 2504 | assertTrue("at least 2 files, commit and data: " + storeFileMetaDatas.toString(), storeFileMetaDatas.size() > 1);
|
@@ -2980,4 +2982,74 @@ public void testSegmentMemoryTrackedWithRandomSearchers() throws Exception {
|
2980 | 2982 | breaker = primary.circuitBreakerService.getBreaker(CircuitBreaker.ACCOUNTING);
|
2981 | 2983 | assertThat(breaker.getUsed(), equalTo(0L));
|
2982 | 2984 | }
|
| 2985 | + |
| 2986 | + public void testFlushOnInactive() throws Exception { |
| 2987 | + Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) |
| 2988 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 2989 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) |
| 2990 | + .build(); |
| 2991 | + IndexMetaData metaData = IndexMetaData.builder("test") |
| 2992 | + .putMapping("test", "{ \"properties\": { \"foo\": { \"type\": \"text\"}}}") |
| 2993 | + .settings(settings) |
| 2994 | + .primaryTerm(0, 1).build(); |
| 2995 | + ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(metaData.getIndex(), 0), "n1", true, ShardRoutingState |
| 2996 | + .INITIALIZING, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE); |
| 2997 | + final ShardId shardId = shardRouting.shardId(); |
| 2998 | + final NodeEnvironment.NodePath nodePath = new NodeEnvironment.NodePath(createTempDir()); |
| 2999 | + ShardPath shardPath = new ShardPath(false, nodePath.resolve(shardId), nodePath.resolve(shardId), shardId); |
| 3000 | + AtomicBoolean markedInactive = new AtomicBoolean(); |
| 3001 | + AtomicReference<IndexShard> primaryRef = new AtomicReference<>(); |
| 3002 | + IndexShard primary = newShard(shardRouting, shardPath, metaData, null, null, () -> { |
| 3003 | + }, new IndexEventListener() { |
| 3004 | + @Override |
| 3005 | + public void onShardInactive(IndexShard indexShard) { |
| 3006 | + markedInactive.set(true); |
| 3007 | + primaryRef.get().flush(new FlushRequest()); |
| 3008 | + } |
| 3009 | + }); |
| 3010 | + primaryRef.set(primary); |
| 3011 | + recoverShardFromStore(primary); |
| 3012 | + for (int i = 0; i < 3; i++) { |
| 3013 | + indexDoc(primary, "test", "" + i, "{\"foo\" : \"" + randomAlphaOfLength(10) + "\"}"); |
| 3014 | + primary.refresh("test"); // produce segments |
| 3015 | + } |
| 3016 | + List<Segment> segments = primary.segments(false); |
| 3017 | + Set<String> names = new HashSet<>(); |
| 3018 | + for (Segment segment : segments) { |
| 3019 | + assertFalse(segment.committed); |
| 3020 | + assertTrue(segment.search); |
| 3021 | + names.add(segment.getName()); |
| 3022 | + } |
| 3023 | + assertEquals(3, segments.size()); |
| 3024 | + primary.flush(new FlushRequest()); |
| 3025 | + primary.forceMerge(new ForceMergeRequest().maxNumSegments(1).flush(false)); |
| 3026 | + primary.refresh("test"); |
| 3027 | + segments = primary.segments(false); |
| 3028 | + for (Segment segment : segments) { |
| 3029 | + if (names.contains(segment.getName())) { |
| 3030 | + assertTrue(segment.committed); |
| 3031 | + assertFalse(segment.search); |
| 3032 | + } else { |
| 3033 | + assertFalse(segment.committed); |
| 3034 | + assertTrue(segment.search); |
| 3035 | + } |
| 3036 | + } |
| 3037 | + assertEquals(4, segments.size()); |
| 3038 | + |
| 3039 | + assertFalse(markedInactive.get()); |
| 3040 | + assertBusy(() -> { |
| 3041 | + primary.checkIdle(0); |
| 3042 | + assertFalse(primary.isActive()); |
| 3043 | + }); |
| 3044 | + |
| 3045 | + assertTrue(markedInactive.get()); |
| 3046 | + segments = primary.segments(false); |
| 3047 | + assertEquals(1, segments.size()); |
| 3048 | + for (Segment segment : segments) { |
| 3049 | + assertTrue(segment.committed); |
| 3050 | + assertTrue(segment.search); |
| 3051 | + } |
| 3052 | + closeShards(primary); |
| 3053 | + } |
| 3054 | + |
2983 | 3055 | }
|
0 commit comments