From 82c92de465e0e13d7d8883bdcedb2979130daf04 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Tue, 2 Jan 2024 15:10:13 -0500 Subject: [PATCH 1/3] Fix issue when calling Delete PIT endpoint and no PITs exist Signed-off-by: Craig Perkins --- .../opensearch/action/search/PitService.java | 1 + .../search/TransportDeletePitActionTests.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/server/src/main/java/org/opensearch/action/search/PitService.java b/server/src/main/java/org/opensearch/action/search/PitService.java index ed12938883e48..b6480ce63f827 100644 --- a/server/src/main/java/org/opensearch/action/search/PitService.java +++ b/server/src/main/java/org/opensearch/action/search/PitService.java @@ -71,6 +71,7 @@ public void deletePitContexts( ) { if (nodeToContextsMap.size() == 0) { listener.onResponse(new DeletePitResponse(Collections.emptyList())); + return; } final Set clusters = nodeToContextsMap.values() .stream() diff --git a/server/src/test/java/org/opensearch/action/search/TransportDeletePitActionTests.java b/server/src/test/java/org/opensearch/action/search/TransportDeletePitActionTests.java index 8d3cdc070c695..365b0d79bc6a0 100644 --- a/server/src/test/java/org/opensearch/action/search/TransportDeletePitActionTests.java +++ b/server/src/test/java/org/opensearch/action/search/TransportDeletePitActionTests.java @@ -21,6 +21,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.core.action.ActionListener; import org.opensearch.core.common.io.stream.NamedWriteableRegistry; +import org.opensearch.core.rest.RestStatus; import org.opensearch.core.tasks.TaskId; import org.opensearch.index.query.IdsQueryBuilder; import org.opensearch.index.query.MatchAllQueryBuilder; @@ -34,6 +35,7 @@ import org.opensearch.transport.RemoteClusterConnectionTests; import org.opensearch.transport.Transport; import org.junit.Before; +import org.opensearch.transport.TransportService; import java.util.ArrayList; import java.util.Arrays; @@ -262,6 +264,51 @@ public void getAllPits(ActionListener getAllPitsListener } } + public void testDeleteAllPITSuccessWhenNoPITsExist() throws InterruptedException, ExecutionException { + ActionFilters actionFilters = mock(ActionFilters.class); + when(actionFilters.filters()).thenReturn(new ActionFilter[0]); + List knownNodes = new CopyOnWriteArrayList<>(); + try ( + MockTransportService cluster1Transport = startTransport("cluster_1_node", knownNodes, Version.CURRENT) + ) { + knownNodes.add(cluster1Transport.getLocalDiscoNode()); + TransportService mockTransportService = mock(TransportService.class); + PitService pitService = new PitService(clusterServiceMock, mock(SearchTransportService.class), mockTransportService, client) { + @Override + public void getAllPits(ActionListener getAllPitsListener) { + List list = new ArrayList<>(); + GetAllPitNodeResponse getAllPitNodeResponse = new GetAllPitNodeResponse( + cluster1Transport.getLocalDiscoNode(), + list + ); + List nodeList = new ArrayList(); + nodeList.add(getAllPitNodeResponse); + getAllPitsListener.onResponse(new GetAllPitNodesResponse(new ClusterName("cn"), nodeList, new ArrayList())); + } + }; + TransportDeletePitAction action = new TransportDeletePitAction( + mockTransportService, + actionFilters, + namedWriteableRegistry, + pitService + ); + DeletePitRequest deletePITRequest = new DeletePitRequest("_all"); + ActionListener listener = new ActionListener() { + @Override + public void onResponse(DeletePitResponse deletePitResponse) { + assertEquals(RestStatus.OK, deletePitResponse.status()); + assertEquals(0, deletePitResponse.getDeletePitResults().size()); + } + + @Override + public void onFailure(Exception e) { + fail("Should not receive Exception"); + } + }; + action.execute(task, deletePITRequest, listener); + } + } + public void testDeletePitWhenNodeIsDown() throws InterruptedException, ExecutionException { List deleteNodesInvoked = new CopyOnWriteArrayList<>(); ActionFilters actionFilters = mock(ActionFilters.class); From c773bf01b3f0e6c170bb2787f077bb833c4615e0 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Tue, 2 Jan 2024 15:16:28 -0500 Subject: [PATCH 2/3] Add to CHANGELOG Signed-off-by: Craig Perkins --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 579d2695d3125..a167127a7d795 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -204,6 +204,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix for stuck update action in a bulk with `retry_on_conflict` property ([#11152](https://github.com/opensearch-project/OpenSearch/issues/11152)) - Fix template setting override for replication type ([#11417](https://github.com/opensearch-project/OpenSearch/pull/11417)) - Fix Automatic addition of protocol broken in #11512 ([#11609](https://github.com/opensearch-project/OpenSearch/pull/11609)) +- Fix issue when calling Delete PIT endpoint and no PITs exist ([#11711](https://github.com/opensearch-project/OpenSearch/pull/11711)) ### Security From 6f87b99cd56acb9fe2ebce4b880e3eb3656b70c3 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Tue, 2 Jan 2024 15:39:11 -0500 Subject: [PATCH 3/3] spotlessApply Signed-off-by: Craig Perkins --- .../action/search/TransportDeletePitActionTests.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/server/src/test/java/org/opensearch/action/search/TransportDeletePitActionTests.java b/server/src/test/java/org/opensearch/action/search/TransportDeletePitActionTests.java index 365b0d79bc6a0..a1e3a2b03caf7 100644 --- a/server/src/test/java/org/opensearch/action/search/TransportDeletePitActionTests.java +++ b/server/src/test/java/org/opensearch/action/search/TransportDeletePitActionTests.java @@ -34,8 +34,8 @@ import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.RemoteClusterConnectionTests; import org.opensearch.transport.Transport; -import org.junit.Before; import org.opensearch.transport.TransportService; +import org.junit.Before; import java.util.ArrayList; import java.util.Arrays; @@ -268,19 +268,14 @@ public void testDeleteAllPITSuccessWhenNoPITsExist() throws InterruptedException ActionFilters actionFilters = mock(ActionFilters.class); when(actionFilters.filters()).thenReturn(new ActionFilter[0]); List knownNodes = new CopyOnWriteArrayList<>(); - try ( - MockTransportService cluster1Transport = startTransport("cluster_1_node", knownNodes, Version.CURRENT) - ) { + try (MockTransportService cluster1Transport = startTransport("cluster_1_node", knownNodes, Version.CURRENT)) { knownNodes.add(cluster1Transport.getLocalDiscoNode()); TransportService mockTransportService = mock(TransportService.class); PitService pitService = new PitService(clusterServiceMock, mock(SearchTransportService.class), mockTransportService, client) { @Override public void getAllPits(ActionListener getAllPitsListener) { List list = new ArrayList<>(); - GetAllPitNodeResponse getAllPitNodeResponse = new GetAllPitNodeResponse( - cluster1Transport.getLocalDiscoNode(), - list - ); + GetAllPitNodeResponse getAllPitNodeResponse = new GetAllPitNodeResponse(cluster1Transport.getLocalDiscoNode(), list); List nodeList = new ArrayList(); nodeList.add(getAllPitNodeResponse); getAllPitsListener.onResponse(new GetAllPitNodesResponse(new ClusterName("cn"), nodeList, new ArrayList()));