|
80 | 80 | import java.util.Map;
|
81 | 81 | import java.util.Optional;
|
82 | 82 | import java.util.concurrent.CountDownLatch;
|
83 |
| -import java.util.concurrent.TimeUnit; |
84 | 83 | import java.util.stream.Collectors;
|
85 | 84 | import java.util.stream.Stream;
|
86 | 85 |
|
@@ -271,60 +270,67 @@ public void testDeleteIndexStore() throws Exception {
|
271 | 270 | ensureGreen("test");
|
272 | 271 | }
|
273 | 272 |
|
274 |
| - // NORELEASE This test need to be adapted for replicated closed indices |
275 |
| - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/33888") |
276 | 273 | public void testPendingTasks() throws Exception {
|
277 |
| - IndicesService indicesService = getIndicesService(); |
278 |
| - IndexService test = createIndex("test"); |
| 274 | + final IndexService indexService = createIndex("test"); |
| 275 | + final Index index = indexService.index(); |
| 276 | + final IndexSettings indexSettings = indexService.getIndexSettings(); |
279 | 277 |
|
280 |
| - assertTrue(test.hasShard(0)); |
281 |
| - ShardPath path = test.getShardOrNull(0).shardPath(); |
282 |
| - assertTrue(test.getShardOrNull(0).routingEntry().started()); |
283 |
| - ShardPath shardPath = ShardPath.loadShardPath(logger, getNodeEnvironment(), new ShardId(test.index(), 0), test.getIndexSettings()); |
284 |
| - assertEquals(shardPath, path); |
285 |
| - try { |
286 |
| - indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS)); |
287 |
| - fail("can't get lock"); |
288 |
| - } catch (ShardLockObtainFailedException ex) { |
| 278 | + final IndexShard indexShard = indexService.getShardOrNull(0); |
| 279 | + assertNotNull(indexShard); |
| 280 | + assertTrue(indexShard.routingEntry().started()); |
289 | 281 |
|
290 |
| - } |
291 |
| - assertTrue(path.exists()); |
| 282 | + final ShardPath shardPath = indexShard.shardPath(); |
| 283 | + assertEquals(ShardPath.loadShardPath(logger, getNodeEnvironment(), indexShard.shardId(), indexSettings), shardPath); |
| 284 | + |
| 285 | + final IndicesService indicesService = getIndicesService(); |
| 286 | + expectThrows(ShardLockObtainFailedException.class, () -> |
| 287 | + indicesService.processPendingDeletes(index, indexSettings, TimeValue.timeValueMillis(0))); |
| 288 | + assertTrue(shardPath.exists()); |
292 | 289 |
|
293 | 290 | int numPending = 1;
|
294 | 291 | if (randomBoolean()) {
|
295 |
| - indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings()); |
| 292 | + indicesService.addPendingDelete(indexShard.shardId(), indexSettings); |
296 | 293 | } else {
|
297 | 294 | if (randomBoolean()) {
|
298 | 295 | numPending++;
|
299 |
| - indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings()); |
| 296 | + indicesService.addPendingDelete(indexShard.shardId(), indexSettings); |
300 | 297 | }
|
301 |
| - indicesService.addPendingDelete(test.index(), test.getIndexSettings()); |
| 298 | + indicesService.addPendingDelete(index, indexSettings); |
302 | 299 | }
|
| 300 | + |
303 | 301 | assertAcked(client().admin().indices().prepareClose("test"));
|
304 |
| - assertTrue(path.exists()); |
| 302 | + assertTrue(shardPath.exists()); |
| 303 | + ensureGreen("test"); |
305 | 304 |
|
306 |
| - assertEquals(indicesService.numPendingDeletes(test.index()), numPending); |
| 305 | + assertEquals(indicesService.numPendingDeletes(index), numPending); |
307 | 306 | assertTrue(indicesService.hasUncompletedPendingDeletes());
|
308 | 307 |
|
309 |
| - // shard lock released... we can now delete |
310 |
| - indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS)); |
311 |
| - assertEquals(indicesService.numPendingDeletes(test.index()), 0); |
312 |
| - assertFalse(indicesService.hasUncompletedPendingDeletes()); |
313 |
| - assertFalse(path.exists()); |
| 308 | + expectThrows(ShardLockObtainFailedException.class, () -> |
| 309 | + indicesService.processPendingDeletes(index, indexSettings, TimeValue.timeValueMillis(0))); |
314 | 310 |
|
315 |
| - if (randomBoolean()) { |
316 |
| - indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings()); |
317 |
| - indicesService.addPendingDelete(new ShardId(test.index(), 1), test.getIndexSettings()); |
318 |
| - indicesService.addPendingDelete(new ShardId("bogus", "_na_", 1), test.getIndexSettings()); |
319 |
| - assertEquals(indicesService.numPendingDeletes(test.index()), 2); |
| 311 | + assertEquals(indicesService.numPendingDeletes(index), numPending); |
| 312 | + assertTrue(indicesService.hasUncompletedPendingDeletes()); |
| 313 | + |
| 314 | + final boolean hasBogus = randomBoolean(); |
| 315 | + if (hasBogus) { |
| 316 | + indicesService.addPendingDelete(new ShardId(index, 0), indexSettings); |
| 317 | + indicesService.addPendingDelete(new ShardId(index, 1), indexSettings); |
| 318 | + indicesService.addPendingDelete(new ShardId("bogus", "_na_", 1), indexSettings); |
| 319 | + assertEquals(indicesService.numPendingDeletes(index), numPending + 2); |
320 | 320 | assertTrue(indicesService.hasUncompletedPendingDeletes());
|
321 |
| - // shard lock released... we can now delete |
322 |
| - indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS)); |
323 |
| - assertEquals(indicesService.numPendingDeletes(test.index()), 0); |
324 |
| - assertTrue(indicesService.hasUncompletedPendingDeletes()); // "bogus" index has not been removed |
325 | 321 | }
|
326 |
| - assertAcked(client().admin().indices().prepareOpen("test").setTimeout(TimeValue.timeValueSeconds(1))); |
327 | 322 |
|
| 323 | + assertAcked(client().admin().indices().prepareDelete("test")); |
| 324 | + assertBusy(() -> { |
| 325 | + try { |
| 326 | + indicesService.processPendingDeletes(index, indexSettings, TimeValue.timeValueMillis(0)); |
| 327 | + assertEquals(indicesService.numPendingDeletes(index), 0); |
| 328 | + } catch (final Exception e) { |
| 329 | + fail(e.getMessage()); |
| 330 | + } |
| 331 | + }); |
| 332 | + assertThat(indicesService.hasUncompletedPendingDeletes(), equalTo(hasBogus)); // "bogus" index has not been removed |
| 333 | + assertFalse(shardPath.exists()); |
328 | 334 | }
|
329 | 335 |
|
330 | 336 | public void testVerifyIfIndexContentDeleted() throws Exception {
|
|
0 commit comments