Skip to content

Commit

Permalink
Adapt testPendingTasks() for replicated closed indices (elastic#38326)
Browse files Browse the repository at this point in the history
Relates to elastic#33888
  • Loading branch information
tlrx committed Mar 1, 2019
1 parent 7c6f8e9 commit 37e5e88
Showing 1 changed file with 42 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -271,60 +270,67 @@ public void testDeleteIndexStore() throws Exception {
ensureGreen("test");
}

// NORELEASE This test need to be adapted for replicated closed indices
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/33888")
public void testPendingTasks() throws Exception {
IndicesService indicesService = getIndicesService();
IndexService test = createIndex("test");
final IndexService indexService = createIndex("test");
final Index index = indexService.index();
final IndexSettings indexSettings = indexService.getIndexSettings();

assertTrue(test.hasShard(0));
ShardPath path = test.getShardOrNull(0).shardPath();
assertTrue(test.getShardOrNull(0).routingEntry().started());
ShardPath shardPath = ShardPath.loadShardPath(logger, getNodeEnvironment(), new ShardId(test.index(), 0), test.getIndexSettings());
assertEquals(shardPath, path);
try {
indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS));
fail("can't get lock");
} catch (ShardLockObtainFailedException ex) {
final IndexShard indexShard = indexService.getShardOrNull(0);
assertNotNull(indexShard);
assertTrue(indexShard.routingEntry().started());

}
assertTrue(path.exists());
final ShardPath shardPath = indexShard.shardPath();
assertEquals(ShardPath.loadShardPath(logger, getNodeEnvironment(), indexShard.shardId(), indexSettings), shardPath);

final IndicesService indicesService = getIndicesService();
expectThrows(ShardLockObtainFailedException.class, () ->
indicesService.processPendingDeletes(index, indexSettings, TimeValue.timeValueMillis(0)));
assertTrue(shardPath.exists());

int numPending = 1;
if (randomBoolean()) {
indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings());
indicesService.addPendingDelete(indexShard.shardId(), indexSettings);
} else {
if (randomBoolean()) {
numPending++;
indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings());
indicesService.addPendingDelete(indexShard.shardId(), indexSettings);
}
indicesService.addPendingDelete(test.index(), test.getIndexSettings());
indicesService.addPendingDelete(index, indexSettings);
}

assertAcked(client().admin().indices().prepareClose("test"));
assertTrue(path.exists());
assertTrue(shardPath.exists());
ensureGreen("test");

assertEquals(indicesService.numPendingDeletes(test.index()), numPending);
assertEquals(indicesService.numPendingDeletes(index), numPending);
assertTrue(indicesService.hasUncompletedPendingDeletes());

// shard lock released... we can now delete
indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS));
assertEquals(indicesService.numPendingDeletes(test.index()), 0);
assertFalse(indicesService.hasUncompletedPendingDeletes());
assertFalse(path.exists());
expectThrows(ShardLockObtainFailedException.class, () ->
indicesService.processPendingDeletes(index, indexSettings, TimeValue.timeValueMillis(0)));

if (randomBoolean()) {
indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings());
indicesService.addPendingDelete(new ShardId(test.index(), 1), test.getIndexSettings());
indicesService.addPendingDelete(new ShardId("bogus", "_na_", 1), test.getIndexSettings());
assertEquals(indicesService.numPendingDeletes(test.index()), 2);
assertEquals(indicesService.numPendingDeletes(index), numPending);
assertTrue(indicesService.hasUncompletedPendingDeletes());

final boolean hasBogus = randomBoolean();
if (hasBogus) {
indicesService.addPendingDelete(new ShardId(index, 0), indexSettings);
indicesService.addPendingDelete(new ShardId(index, 1), indexSettings);
indicesService.addPendingDelete(new ShardId("bogus", "_na_", 1), indexSettings);
assertEquals(indicesService.numPendingDeletes(index), numPending + 2);
assertTrue(indicesService.hasUncompletedPendingDeletes());
// shard lock released... we can now delete
indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS));
assertEquals(indicesService.numPendingDeletes(test.index()), 0);
assertTrue(indicesService.hasUncompletedPendingDeletes()); // "bogus" index has not been removed
}
assertAcked(client().admin().indices().prepareOpen("test").setTimeout(TimeValue.timeValueSeconds(1)));

assertAcked(client().admin().indices().prepareDelete("test"));
assertBusy(() -> {
try {
indicesService.processPendingDeletes(index, indexSettings, TimeValue.timeValueMillis(0));
assertEquals(indicesService.numPendingDeletes(index), 0);
} catch (final Exception e) {
fail(e.getMessage());
}
});
assertThat(indicesService.hasUncompletedPendingDeletes(), equalTo(hasBogus)); // "bogus" index has not been removed
assertFalse(shardPath.exists());
}

public void testVerifyIfIndexContentDeleted() throws Exception {
Expand Down

0 comments on commit 37e5e88

Please sign in to comment.