From cf7005361a9b3426685eb5911f36c6255c423f2e Mon Sep 17 00:00:00 2001 From: markharwood Date: Fri, 30 Apr 2021 14:30:35 +0100 Subject: [PATCH] Moved initialisation of data node timing of request from NodeTermsEnumRequest constructor to TransportTermsEnumAction#asyncNodeOperation --- .../core/termsenum/action/NodeTermsEnumRequest.java | 11 ++++++----- .../termsenum/action/TransportTermsEnumAction.java | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/NodeTermsEnumRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/NodeTermsEnumRequest.java index a7e781a466315..2dd1b9776ac00 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/NodeTermsEnumRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/NodeTermsEnumRequest.java @@ -39,9 +39,6 @@ public class NodeTermsEnumRequest extends TransportRequest implements IndicesReq public NodeTermsEnumRequest(StreamInput in) throws IOException { super(in); - // Set the clock running as soon as we appear on a node. - nodeStartedTimeMillis = System.currentTimeMillis(); - field = in.readString(); string = in.readString(); caseInsensitive = in.readBoolean(); @@ -85,15 +82,19 @@ public long taskStartedTimeMillis() { /** * The time this request was materialized on a node - * (defaults to "now" if serialization was not used e.g. a local request). */ - public long nodeStartedTimeMillis() { + long nodeStartedTimeMillis() { + // In case startTimerOnDataNode has not been called (should never happen in normal circumstances?) if (nodeStartedTimeMillis == 0) { nodeStartedTimeMillis = System.currentTimeMillis(); } return this.nodeStartedTimeMillis; } + public void startTimerOnDataNode() { + nodeStartedTimeMillis = System.currentTimeMillis(); + } + public Set shardIds() { return Collections.unmodifiableSet(shardIds); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/TransportTermsEnumAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/TransportTermsEnumAction.java index 41b057df871af..6ad321cc1096a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/TransportTermsEnumAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/TransportTermsEnumAction.java @@ -576,8 +576,11 @@ public void messageReceived(NodeTermsEnumRequest request, TransportChannel chann private void asyncNodeOperation(NodeTermsEnumRequest request, Task task, ActionListener listener) throws IOException { + // Start the clock ticking on the data node using the data node's local current time. + request.startTimerOnDataNode(); + // DLS/FLS check copied from ResizeRequestInterceptor - check permissions and - // any index_filter canMatch checks on network thread before allocating work + // any index_filter canMatch checks on network thread before allocating work ThreadContext threadContext = transportService.getThreadPool().getThreadContext(); final XPackLicenseState frozenLicenseState = licenseState.copyCurrentLicenseState(); for (ShardId shardId : request.shardIds().toArray(new ShardId[0])) {