Skip to content

Commit

Permalink
Add test logging debug to SimpleBlocksIT.testAddBlockWhileIndexingDoc…
Browse files Browse the repository at this point in the history
…uments (#74952) (#74979)

Relates #74345
  • Loading branch information
tlrx committed Jul 6, 2021
1 parent 4828950 commit 17ba4ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.readonly.AddIndexBlockRequestBuilder;
import org.elasticsearch.action.admin.indices.readonly.AddIndexBlockResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.index.IndexResponse;
Expand All @@ -28,6 +29,7 @@
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.test.BackgroundIndexer;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.junit.annotations.TestLogging;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -362,14 +364,16 @@ public void testConcurrentAddBlock() throws InterruptedException {
}
}

@TestLogging(
reason = "https://github.com/elastic/elasticsearch/issues/74345",
value = "org.elasticsearch.action.admin.indices.readonly:DEBUG,org.elasticsearch.cluster.metadata:DEBUG"
)
public void testAddBlockWhileIndexingDocuments() throws Exception {
final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
createIndex(indexName);

final APIBlock block = randomAddableBlock();

int nbDocs = 0;

try {
try (BackgroundIndexer indexer = new BackgroundIndexer(indexName, "_doc", client(), 1000)) {
indexer.setFailureAssertion(t -> {
Expand All @@ -381,11 +385,11 @@ public void testAddBlockWhileIndexingDocuments() throws Exception {
});

waitForDocs(randomIntBetween(10, 50), indexer);
assertAcked(client().admin().indices().prepareAddBlock(block, indexName));
final AddIndexBlockResponse response = client().admin().indices().prepareAddBlock(block, indexName).get();
assertTrue("Add Index Block request was not acknowledged: " + response, response.isAcknowledged());
indexer.stopAndAwaitStopped();
nbDocs += indexer.totalIndexedDocs();
}

assertIndexHasBlock(block, indexName);
} finally {
disableIndexBlock(indexName, block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.action.support.master.ShardsAcknowledgedResponse;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.index.Index;

import java.io.IOException;
Expand Down Expand Up @@ -66,7 +67,7 @@ public String toString() {
return Strings.toString(this);
}

public static class AddBlockResult implements Writeable, ToXContentFragment {
public static class AddBlockResult implements Writeable, ToXContentObject {

private final Index index;
private final @Nullable Exception exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,9 @@ public void innerOnFailure(final Exception e) {

private void processIfFinished() {
if (countDown.countDown()) {
onResponse.accept(new AddBlockResult(index, results.toArray(new AddBlockShardResult[results.length()])));
AddBlockResult result = new AddBlockResult(index, results.toArray(new AddBlockShardResult[results.length()]));
logger.debug("result of applying block to index {}: {}", index, result);
onResponse.accept(result);
}
}
});
Expand Down Expand Up @@ -885,7 +887,6 @@ static Tuple<ClusterState, Collection<AddBlockResult>> finalizeBlock(final Clust
logger.debug("verification of shards before blocking {} failed [{}]", index, result);
continue;
}
final IndexMetadata indexMetadata = metadata.getSafe(index);
final ClusterBlock tempBlock = blockedIndices.get(index);
assert tempBlock != null;
assert tempBlock.uuid() != null;
Expand Down

0 comments on commit 17ba4ac

Please sign in to comment.