Skip to content

Commit

Permalink
Delete PIT API changes
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <[email protected]>
  • Loading branch information
bharath-techie committed Apr 19, 2022
1 parent ece4c00 commit d67e389
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 155 deletions.
9 changes: 8 additions & 1 deletion server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,14 @@
import org.opensearch.rest.action.ingest.RestGetPipelineAction;
import org.opensearch.rest.action.ingest.RestPutPipelineAction;
import org.opensearch.rest.action.ingest.RestSimulatePipelineAction;
import org.opensearch.rest.action.search.*;
import org.opensearch.rest.action.search.RestClearScrollAction;
import org.opensearch.rest.action.search.RestCountAction;
import org.opensearch.rest.action.search.RestCreatePITAction;
import org.opensearch.rest.action.search.RestDeletePITAction;
import org.opensearch.rest.action.search.RestExplainAction;
import org.opensearch.rest.action.search.RestMultiSearchAction;
import org.opensearch.rest.action.search.RestSearchAction;
import org.opensearch.rest.action.search.RestSearchScrollAction;
import org.opensearch.tasks.Task;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.usage.UsageService;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
*/
public class DeletePITRequest extends ActionRequest implements ToXContentObject {

/**
* List of PIT IDs to be deleted , and use "_all" to delete all PIT reader contexts
*/
private List<String> pitIds;

public DeletePITRequest(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
import org.opensearch.common.ParseField;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.*;
import org.opensearch.common.xcontent.ConstructingObjectParser;
import org.opensearch.common.xcontent.ObjectParser;
import org.opensearch.common.xcontent.StatusToXContentObject;
import org.opensearch.common.xcontent.ToXContent;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.rest.RestStatus;

import java.io.IOException;
Expand All @@ -23,6 +28,9 @@

public class DeletePITResponse extends ActionResponse implements StatusToXContentObject {

/**
* This will be true if all PIT reader contexts are deleted.
*/
private final boolean succeeded;

public DeletePITResponse(boolean succeeded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.opensearch.OpenSearchException;
import org.opensearch.action.ActionListener;
import org.opensearch.action.StepListener;
Expand All @@ -33,6 +34,9 @@
import java.util.function.BiFunction;
import java.util.stream.Collectors;

/**
* Transport action for deleting pit reader context - supports deleting list and all pit contexts
*/
public class TransportDeletePITAction extends HandledTransportAction<DeletePITRequest, DeletePITResponse> {
private SearchService searchService;
private final NamedWriteableRegistry namedWriteableRegistry;
Expand Down Expand Up @@ -74,15 +78,21 @@ protected void doExecute(Task task, DeletePITRequest request, ActionListener<Del
if (r == contexts.size()) {
listener.onResponse(new DeletePITResponse(true));
} else {
logger.debug(
() -> new ParameterizedMessage("Delete PITs failed. " + "Cleared {} contexts out of {}", r, contexts.size())
);
listener.onResponse(new DeletePITResponse(false));
}
}, e -> {
logger.debug("Delete PIT failed ", e);
logger.debug("Delete PITs failed ", e);
listener.onResponse(new DeletePITResponse(false));
}));
}
}

/**
* Delete all active PIT reader contexts
*/
void deleteAllPits(ActionListener<DeletePITResponse> listener) {
int size = clusterService.state().getNodes().getSize();
ActionListener groupedActionListener = getGroupedListener(listener, size);
Expand All @@ -96,11 +106,17 @@ void deleteAllPits(ActionListener<DeletePITResponse> listener) {
}
}

/**
* Delete list of pits, return success if all reader contexts are deleted ( or not found ).
*/
void deletePits(List<SearchContextIdForNode> contexts, ActionListener<Integer> listener) {
final StepListener<BiFunction<String, String, DiscoveryNode>> lookupListener = getLookupListener(contexts);
lookupListener.whenComplete(nodeLookup -> {
final GroupedActionListener<Boolean> groupedListener = new GroupedActionListener<>(
ActionListener.delegateFailure(listener, (l, rs) -> l.onResponse(Math.toIntExact(rs.stream().filter(r -> r).count()))),
ActionListener.delegateFailure(
listener,
(l, result) -> l.onResponse(Math.toIntExact(result.stream().filter(r -> r).count()))
),
contexts.size()
);

Expand All @@ -117,6 +133,7 @@ void deletePits(List<SearchContextIdForNode> contexts, ActionListener<Integer> l
ActionListener.wrap(r -> groupedListener.onResponse(r.isFreed()), e -> groupedListener.onResponse(false))
);
} catch (Exception e) {
logger.debug("Delete PIT failed ", e);
groupedListener.onResponse(false);
}
}
Expand Down
16 changes: 15 additions & 1 deletion server/src/main/java/org/opensearch/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,21 @@
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.action.search.*;
import org.opensearch.action.search.ClearScrollRequest;
import org.opensearch.action.search.ClearScrollRequestBuilder;
import org.opensearch.action.search.ClearScrollResponse;
import org.opensearch.action.search.CreatePITRequest;
import org.opensearch.action.search.CreatePITResponse;
import org.opensearch.action.search.DeletePITRequest;
import org.opensearch.action.search.DeletePITResponse;
import org.opensearch.action.search.MultiSearchRequest;
import org.opensearch.action.search.MultiSearchRequestBuilder;
import org.opensearch.action.search.MultiSearchResponse;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchRequestBuilder;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.action.search.SearchScrollRequest;
import org.opensearch.action.search.SearchScrollRequestBuilder;
import org.opensearch.action.termvectors.MultiTermVectorsRequest;
import org.opensearch.action.termvectors.MultiTermVectorsRequestBuilder;
import org.opensearch.action.termvectors.MultiTermVectorsResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,27 @@
import org.opensearch.action.ingest.SimulatePipelineRequest;
import org.opensearch.action.ingest.SimulatePipelineRequestBuilder;
import org.opensearch.action.ingest.SimulatePipelineResponse;
import org.opensearch.action.search.*;
import org.opensearch.action.search.ClearScrollAction;
import org.opensearch.action.search.ClearScrollRequest;
import org.opensearch.action.search.ClearScrollRequestBuilder;
import org.opensearch.action.search.ClearScrollResponse;
import org.opensearch.action.search.CreatePITAction;
import org.opensearch.action.search.CreatePITRequest;
import org.opensearch.action.search.CreatePITResponse;
import org.opensearch.action.search.DeletePITAction;
import org.opensearch.action.search.DeletePITRequest;
import org.opensearch.action.search.DeletePITResponse;
import org.opensearch.action.search.MultiSearchAction;
import org.opensearch.action.search.MultiSearchRequest;
import org.opensearch.action.search.MultiSearchRequestBuilder;
import org.opensearch.action.search.MultiSearchResponse;
import org.opensearch.action.search.SearchAction;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchRequestBuilder;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.action.search.SearchScrollAction;
import org.opensearch.action.search.SearchScrollRequest;
import org.opensearch.action.search.SearchScrollRequestBuilder;
import org.opensearch.action.support.PlainActionFuture;
import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.action.termvectors.MultiTermVectorsAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.opensearch.rest.RestRequest.Method.*;
import static org.opensearch.rest.RestRequest.Method.DELETE;

public class RestDeletePITAction extends BaseRestHandler {

Expand Down Expand Up @@ -50,6 +50,6 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client

@Override
public List<Route> routes() {
return unmodifiableList(asList(new Route(DELETE, "/_pit"), new Route(DELETE, "/_pit/{id}")));
return unmodifiableList(asList(new Route(DELETE, "/_search/_point_in_time"), new Route(DELETE, "/_search/_point_in_time/{id}")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ public boolean freeReaderContext(ShardSearchContextId contextId) {
}

/**
* Free reader context if found otherwise return false
* Free reader context if found , return false if delete reader fails
*/
public boolean freeReaderContextIfFound(ShardSearchContextId contextId) {
try {
Expand Down
Loading

0 comments on commit d67e389

Please sign in to comment.