Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Fix issue when calling Delete PIT endpoint and no PITs exist #11713

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void deletePitContexts(
) {
if (nodeToContextsMap.size() == 0) {
listener.onResponse(new DeletePitResponse(Collections.emptyList()));
return;
}
final Set<String> clusters = nodeToContextsMap.values()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +34,7 @@
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.RemoteClusterConnectionTests;
import org.opensearch.transport.Transport;
import org.opensearch.transport.TransportService;
import org.junit.Before;

import java.util.ArrayList;
Expand Down Expand Up @@ -262,6 +264,46 @@ public void getAllPits(ActionListener<GetAllPitNodesResponse> getAllPitsListener
}
}

public void testDeleteAllPITSuccessWhenNoPITsExist() throws InterruptedException, ExecutionException {
ActionFilters actionFilters = mock(ActionFilters.class);
when(actionFilters.filters()).thenReturn(new ActionFilter[0]);
List<DiscoveryNode> 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<GetAllPitNodesResponse> getAllPitsListener) {
List<ListPitInfo> list = new ArrayList<>();
GetAllPitNodeResponse getAllPitNodeResponse = new GetAllPitNodeResponse(cluster1Transport.getLocalDiscoNode(), list);
List<GetAllPitNodeResponse> 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<DeletePitResponse> listener = new ActionListener<DeletePitResponse>() {
@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<DiscoveryNode> deleteNodesInvoked = new CopyOnWriteArrayList<>();
ActionFilters actionFilters = mock(ActionFilters.class);
Expand Down
Loading