Skip to content

Commit

Permalink
logging for readercontext
Browse files Browse the repository at this point in the history
  • Loading branch information
ywangd committed Oct 9, 2024
1 parent fb482f8 commit 3b37f43
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onResponse(@Nullable T result) {

@Override
public void onFailure(Exception e) {
assert assertCompleteAllowed();
// assert assertCompleteAllowed();
if (sync.setException(Objects.requireNonNull(e))) {
done(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ protected void putReaderContext(ReaderContext context) {
final Index index = context.indexShard().shardId().getIndex();
if (indicesService.hasIndex(index) == false) {
removeReaderContext(id);
logger.info("--> immediately removed readerContext [{}]", context.toString());
throw new IndexNotFoundException(index);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public ReaderContext(
this.refCounted = AbstractRefCounted.of(this::doClose);
}

@Override
public String toString() {
return "ReaderContext{" + "id=" + id + ", indexShard=" + indexShard.shardId() + '}';
}

public void validate(TransportRequest request) {
indexShard.getSearchOperationListener().validateReaderContext(this, request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static String threadInfo(String threadName) {
Matcher m = ELASTICSEARCH_THREAD_NAME_PATTERN.matcher(threadName);
if (m.matches()) {
// Thread looks like a node thread so use the node name
return m.group(1);
return threadName.substring(13); // m.group(1);
}
m = TEST_THREAD_NAME_PATTERN.matcher(threadName);
if (m.matches()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.elasticsearch.indices.ExecutorSelector;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.logging.LogManager;
import org.elasticsearch.logging.Logger;
import org.elasticsearch.node.MockNode;
import org.elasticsearch.node.ResponseCollectorService;
import org.elasticsearch.plugins.Plugin;
Expand All @@ -36,6 +38,8 @@
import java.util.function.Function;

public class MockSearchService extends SearchService {
private static final Logger logger = LogManager.getLogger(MockSearchService.class);

/**
* Marker plugin used by {@link MockNode} to enable {@link MockSearchService}.
*/
Expand All @@ -54,11 +58,14 @@ public static class TestPlugin extends Plugin {}
public static void assertNoInFlightContext() {
final Map<ReaderContext, Throwable> copy = new HashMap<>(ACTIVE_SEARCH_CONTEXTS);
if (copy.isEmpty() == false) {
final Map.Entry<ReaderContext, Throwable> entry = copy.entrySet().iterator().next();
throw new AssertionError(
"There are still ["
+ copy.size()
+ "] in-flight contexts. The first one's creation site is listed as the cause of this exception.",
copy.values().iterator().next()
+ "] in-flight contexts. The first one's ("
+ entry.getKey().toString()
+ ") creation site is listed as the cause of this exception.",
entry.getValue()
);
}
}
Expand All @@ -67,14 +74,17 @@ public static void assertNoInFlightContext() {
* Add an active search context to the list of tracked contexts. Package private for testing.
*/
static void addActiveContext(ReaderContext context) {
ACTIVE_SEARCH_CONTEXTS.put(context, new RuntimeException(context.toString()));
final String contextString = context.toString();
ACTIVE_SEARCH_CONTEXTS.put(context, new RuntimeException(contextString));
logger.info("--> addActiveContext [{}]", contextString);
}

/**
* Clear an active search context from the list of tracked contexts. Package private for testing.
*/
static void removeActiveContext(ReaderContext context) {
ACTIVE_SEARCH_CONTEXTS.remove(context);
logger.info("--> removeActiveContext [{}]", context.toString());
}

public MockSearchService(
Expand Down

0 comments on commit 3b37f43

Please sign in to comment.