From f54184fbac31987a07df7bfbbb3391ff31e88752 Mon Sep 17 00:00:00 2001 From: Rajiv Kumar Vaidyanathan Date: Tue, 19 Mar 2024 12:00:10 +0530 Subject: [PATCH] updated changelog and renamed localExecuteSupportedByAction Signed-off-by: Rajiv Kumar Vaidyanathan --- CHANGELOG.md | 1 + .../cluster/state/TransportClusterStateAction.java | 2 +- .../cluster/state/term/GetTermVersionRequest.java | 2 +- .../TransportClusterManagerNodeAction.java | 14 +++++++------- .../TransportClusterManagerTermCheckTests.java | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b5a7cc705a79..5fb89180a0887 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,6 +120,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - [Admission Control] Integrated IO Based AdmissionController to AdmissionControl Framework ([#12583](https://github.com/opensearch-project/OpenSearch/pull/12583)) - Introduce a new setting `index.check_pending_flush.enabled` to expose the ability to disable the check for pending flushes by write threads ([#12710](https://github.com/opensearch-project/OpenSearch/pull/12710)) - Built-in secure transports support ([#12435](https://github.com/opensearch-project/OpenSearch/pull/12435)) +- Lightweight Transport action to verify local term before fetching cluster-state from remote ([#12252](https://github.com/opensearch-project/OpenSearch/pull/12252/)) ### Dependencies - Bump `peter-evans/find-comment` from 2 to 3 ([#12288](https://github.com/opensearch-project/OpenSearch/pull/12288)) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/state/TransportClusterStateAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/state/TransportClusterStateAction.java index fdcb3ee6346b6..cae465a90446e 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/state/TransportClusterStateAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/state/TransportClusterStateAction.java @@ -235,7 +235,7 @@ private ClusterStateResponse buildResponse(final ClusterStateRequest request, fi } @Override - protected boolean canUseLocalNodeClusterState() { + protected boolean localExecuteSupportedByAction() { return true; } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/state/term/GetTermVersionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/state/term/GetTermVersionRequest.java index 2ea07d7332977..b099f8087bd15 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/state/term/GetTermVersionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/state/term/GetTermVersionRequest.java @@ -15,7 +15,7 @@ import java.io.IOException; /** - * Request object to get cluster term + * Request object to get cluster term and version * * @opensearch.internal */ diff --git a/server/src/main/java/org/opensearch/action/support/clustermanager/TransportClusterManagerNodeAction.java b/server/src/main/java/org/opensearch/action/support/clustermanager/TransportClusterManagerNodeAction.java index a976dd87ca213..6a081f9dfecde 100644 --- a/server/src/main/java/org/opensearch/action/support/clustermanager/TransportClusterManagerNodeAction.java +++ b/server/src/main/java/org/opensearch/action/support/clustermanager/TransportClusterManagerNodeAction.java @@ -274,7 +274,7 @@ protected void doStart(ClusterState clusterState) { retryOnMasterChange(clusterState, null); } else { DiscoveryNode clusterManagerNode = nodes.getClusterManagerNode(); - if (clusterManagerNode.getVersion().onOrAfter(V_3_0_0) && canUseLocalNodeClusterState()) { + if (clusterManagerNode.getVersion().onOrAfter(V_3_0_0) && localExecuteSupportedByAction()) { BiConsumer executeOnLocalOrClusterManager = clusterStateLatestChecker( this::executeOnLocalNode, this::executeOnClusterManager @@ -353,8 +353,8 @@ private ActionListener getDelegateForLocalExecute(ClusterState cluster } protected BiConsumer clusterStateLatestChecker( - Consumer onLatestWithLocalState, - BiConsumer onMisMatchWithLocalState + Consumer onLatestLocalState, + BiConsumer onStaleLocalState ) { return (clusterManagerNode, clusterState) -> { transportService.sendRequest( @@ -371,9 +371,9 @@ public void handleResponse(GetTermVersionResponse response) { isLatestClusterStatePresentOnLocalNode ); if (isLatestClusterStatePresentOnLocalNode) { - onLatestWithLocalState.accept(clusterState); + onLatestLocalState.accept(clusterState); } else { - onMisMatchWithLocalState.accept(clusterManagerNode, clusterState); + onStaleLocalState.accept(clusterManagerNode, clusterState); } } @@ -462,13 +462,13 @@ protected String getMasterActionName(DiscoveryNode node) { } /** - * Override to true if the transport action need NOT be executed always on cluster-manager (example Read-only actions). + * Override to true if the transport action can be executed locally and need NOT be executed always on cluster-manager (Read actions). * The action is executed locally if this method returns true AND * the ClusterState on local node is in-sync with ClusterManager. * * @return - boolean if the action can be run locally */ - protected boolean canUseLocalNodeClusterState() { + protected boolean localExecuteSupportedByAction() { return false; } } diff --git a/server/src/test/java/org/opensearch/action/support/clustermanager/TransportClusterManagerTermCheckTests.java b/server/src/test/java/org/opensearch/action/support/clustermanager/TransportClusterManagerTermCheckTests.java index d22d4871d92af..8c7b7a0940c82 100644 --- a/server/src/test/java/org/opensearch/action/support/clustermanager/TransportClusterManagerTermCheckTests.java +++ b/server/src/test/java/org/opensearch/action/support/clustermanager/TransportClusterManagerTermCheckTests.java @@ -190,7 +190,7 @@ protected String executor() { } @Override - protected boolean canUseLocalNodeClusterState() { + protected boolean localExecuteSupportedByAction() { return true; } @@ -276,7 +276,7 @@ public void testTermCheckNoMatchWithClusterManager() throws ExecutionException, public void testTermCheckOnOldVersionClusterManager() throws ExecutionException, InterruptedException { - setUpCluster(Version.V_2_13_0); + setUpCluster(Version.V_2_12_0); TransportClusterManagerTermCheckTests.Request request = new TransportClusterManagerTermCheckTests.Request(); PlainActionFuture listener = new PlainActionFuture<>();