|
43 | 43 | import org.elasticsearch.index.shard.IndexShard; |
44 | 44 | import org.elasticsearch.index.shard.IndexShardState; |
45 | 45 | import org.elasticsearch.index.shard.ShardId; |
| 46 | +import org.elasticsearch.indices.IndexingMemoryController; |
| 47 | +import org.elasticsearch.indices.IndicesService; |
46 | 48 | import org.elasticsearch.indices.recovery.PeerRecoveryTargetService; |
47 | 49 | import org.elasticsearch.indices.recovery.RecoveryFileChunkRequest; |
48 | 50 | import org.elasticsearch.plugins.Plugin; |
|
74 | 76 | import java.util.concurrent.Semaphore; |
75 | 77 | import java.util.concurrent.TimeUnit; |
76 | 78 | import java.util.concurrent.atomic.AtomicBoolean; |
| 79 | +import java.util.concurrent.locks.LockSupport; |
77 | 80 | import java.util.stream.Collectors; |
78 | 81 | import java.util.stream.Stream; |
79 | 82 |
|
@@ -117,6 +120,64 @@ public Settings indexSettings() { |
117 | 120 | .build(); |
118 | 121 | } |
119 | 122 |
|
| 123 | + public void testSimpleRelocationIndexingPaused() { |
| 124 | + logger.info("--> starting [node1] ..."); |
| 125 | + final String node_1 = internalCluster().startNode( |
| 126 | + Settings.builder() |
| 127 | + .put(IndexingMemoryController.PAUSE_INDEXING_ON_THROTTLE.getKey(), true)); |
| 128 | + |
| 129 | + logger.info("--> creating test index ..."); |
| 130 | + prepareCreate("test", indexSettings(1, 0)).get(); |
| 131 | + |
| 132 | + logger.info("--> index 10 docs"); |
| 133 | + for (int i = 0; i < 10; i++) { |
| 134 | + prepareIndex("test").setId(Integer.toString(i)).setSource("field", "value" + i).get(); |
| 135 | + } |
| 136 | + logger.info("--> flush so we have an actual index"); |
| 137 | + indicesAdmin().prepareFlush().get(); |
| 138 | + logger.info("--> index more docs so we have something in the translog"); |
| 139 | + for (int i = 10; i < 20; i++) { |
| 140 | + prepareIndex("test").setId(Integer.toString(i)).setSource("field", "value" + i).get(); |
| 141 | + } |
| 142 | + |
| 143 | + logger.info("--> verifying count"); |
| 144 | + indicesAdmin().prepareRefresh().get(); |
| 145 | + assertHitCount(prepareSearch("test").setSize(0), 20L); |
| 146 | + |
| 147 | + logger.info("--> start another node"); |
| 148 | + final String node_2 = internalCluster().startNode(); |
| 149 | + ClusterHealthResponse clusterHealthResponse = clusterAdmin().prepareHealth(TEST_REQUEST_TIMEOUT) |
| 150 | + .setWaitForEvents(Priority.LANGUID) |
| 151 | + .setWaitForNodes("2") |
| 152 | + .get(); |
| 153 | + assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); |
| 154 | + |
| 155 | + IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node_1); |
| 156 | + IndexService indexService = indicesService.indexService(resolveIndex("test")); |
| 157 | + IndexShard shard = indexService.getShard(0); |
| 158 | + shard.activateThrottling(); |
| 159 | + LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100)); |
| 160 | + logger.info("--> index 1 more doc"); |
| 161 | + IndexRequestBuilder indexRequestBuilder = prepareIndex("test").setId(Integer.toString(20)).setSource("field", "value" + 20); |
| 162 | + var future = indexRequestBuilder.execute(); |
| 163 | + //future.actionGet(); |
| 164 | + |
| 165 | + logger.info("--> relocate the shard from node1 to node2"); |
| 166 | + ClusterRerouteUtils.reroute(client(), new MoveAllocationCommand("test", 0, node_1, node_2)); |
| 167 | + |
| 168 | + clusterHealthResponse = clusterAdmin().prepareHealth(TEST_REQUEST_TIMEOUT) |
| 169 | + .setWaitForEvents(Priority.LANGUID) |
| 170 | + .setWaitForNoRelocatingShards(true) |
| 171 | + .setTimeout(ACCEPTABLE_RELOCATION_TIME) |
| 172 | + .get(); |
| 173 | + //assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); |
| 174 | + assertThat(clusterHealthResponse.isTimedOut(), equalTo(true)); |
| 175 | + |
| 176 | + logger.info("--> verifying count again..."); |
| 177 | + indicesAdmin().prepareRefresh().get(); |
| 178 | + assertHitCount(prepareSearch("test").setSize(0), 20); |
| 179 | + } |
| 180 | + |
120 | 181 | public void testSimpleRelocationNoIndexing() { |
121 | 182 | logger.info("--> starting [node1] ..."); |
122 | 183 | final String node_1 = internalCluster().startNode(); |
|
0 commit comments