Skip to content

[8.x] More verbose logging in IndicesSegmentsRestCancellationIT (#113844) #114003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
More verbose logging in IndicesSegmentsRestCancellationIT (#113844)
Relates #88201
  • Loading branch information
DaveCTurner committed Oct 3, 2024
commit 70c4f245d63c701f6a83c529160e782819729be2
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

package org.elasticsearch.http;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.client.Cancellable;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils;
Expand All @@ -29,6 +31,8 @@
import org.elasticsearch.index.shard.IndexShardTestCase;
import org.elasticsearch.index.translog.TranslogStats;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.logging.LogManager;
import org.elasticsearch.logging.Logger;
import org.elasticsearch.plugins.EnginePlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.tasks.Task;
Expand Down Expand Up @@ -141,6 +145,12 @@ public List<Setting<?>> getSettings() {

private static class SearcherBlockingEngine extends ReadOnlyEngine {

// using a specialized logger for this case because and "logger" means "Engine#logger"
// (relates investigation into https://github.com/elastic/elasticsearch/issues/88201)
private static final Logger blockedSearcherRestCancellationTestCaseLogger = LogManager.getLogger(
BlockedSearcherRestCancellationTestCase.class
);

final Semaphore searcherBlock = new Semaphore(1);

SearcherBlockingEngine(EngineConfig config) {
Expand All @@ -149,12 +159,36 @@ private static class SearcherBlockingEngine extends ReadOnlyEngine {

@Override
public Searcher acquireSearcher(String source, SearcherScope scope, Function<Searcher, Searcher> wrapper) throws EngineException {
if (blockedSearcherRestCancellationTestCaseLogger.isDebugEnabled()) {
blockedSearcherRestCancellationTestCaseLogger.debug(
Strings.format(
"in acquireSearcher for shard [%s] on thread [%s], availablePermits=%d",
config().getShardId(),
Thread.currentThread().getName(),
searcherBlock.availablePermits()
),
new ElasticsearchException("stack trace")
);
}

try {
searcherBlock.acquire();
} catch (InterruptedException e) {
throw new AssertionError(e);
}
searcherBlock.release();

if (blockedSearcherRestCancellationTestCaseLogger.isDebugEnabled()) {
blockedSearcherRestCancellationTestCaseLogger.debug(
Strings.format(
"continuing in acquireSearcher for shard [%s] on thread [%s], availablePermits=%d",
config().getShardId(),
Thread.currentThread().getName(),
searcherBlock.availablePermits()
)
);
}

return super.acquireSearcher(source, scope, wrapper);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@
import org.apache.http.client.methods.HttpGet;
import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction;
import org.elasticsearch.client.Request;
import org.elasticsearch.test.junit.annotations.TestIssueLogging;

public class IndicesSegmentsRestCancellationIT extends BlockedSearcherRestCancellationTestCase {
@TestIssueLogging(
issueUrl = "https://github.com/elastic/elasticsearch/issues/88201",
value = "org.elasticsearch.http.BlockedSearcherRestCancellationTestCase:DEBUG"
+ ",org.elasticsearch.transport.TransportService:TRACE"
)
public void testIndicesSegmentsRestCancellation() throws Exception {
runTest(new Request(HttpGet.METHOD_NAME, "/_segments"), IndicesSegmentsAction.NAME);
}

@TestIssueLogging(
issueUrl = "https://github.com/elastic/elasticsearch/issues/88201",
value = "org.elasticsearch.http.BlockedSearcherRestCancellationTestCase:DEBUG"
+ ",org.elasticsearch.transport.TransportService:TRACE"
)
public void testCatSegmentsRestCancellation() throws Exception {
runTest(new Request(HttpGet.METHOD_NAME, "/_cat/segments"), IndicesSegmentsAction.NAME);
}
Expand Down