Skip to content

Commit 93f2012

Browse files
committed
remove resource usages object from headers
Signed-off-by: Chenyang Ji <[email protected]>
1 parent 4b284c5 commit 93f2012

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

server/src/main/java/org/opensearch/action/search/SearchTaskRequestOperationsListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public SearchTaskRequestOperationsListener(TaskResourceTrackingService taskResou
2525

2626
@Override
2727
public void onRequestEnd(SearchPhaseContext context, SearchRequestContext searchRequestContext) {
28+
// Refresh the coordinator node level resource usages
2829
taskResourceTrackingService.refreshResourceStats(context.getTask());
30+
// Remove the shard level resource usages from thread context
31+
taskResourceTrackingService.removeTaskResourceUsage();
2932
}
3033
}

server/src/main/java/org/opensearch/common/util/concurrent/ThreadContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,15 @@ public void updateResponseHeader(final String key, final String value, final Fun
547547
threadLocal.set(threadLocal.get().putResponse(key, value, uniqueValue, maxWarningHeaderCount, maxWarningHeaderSize, true));
548548
}
549549

550+
/**
551+
* Remove the {@code value} for the specified {@code key}.
552+
*
553+
* @param key the header name
554+
*/
555+
public void removeResponseHeader(final String key) {
556+
threadLocal.get().responseHeaders.remove(key);
557+
}
558+
550559
/**
551560
* Saves the current thread context and wraps command in a Runnable that restores that context before running command. If
552561
* <code>command</code> has already been passed through this method then it is returned unaltered rather than wrapped twice.

server/src/main/java/org/opensearch/tasks/TaskResourceTrackingService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ public void writeTaskResourceUsage(SearchShardTask task, String nodeId) {
328328
}
329329
}
330330

331+
/**
332+
* Remove the current task level resource usages.
333+
*/
334+
public void removeTaskResourceUsage() {
335+
threadPool.getThreadContext().removeResponseHeader(TASK_RESOURCE_USAGE);
336+
}
337+
331338
/**
332339
* Get the task resource usages from {@link ThreadContext}
333340
*

0 commit comments

Comments
 (0)