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

Deletepit API #3

Open
wants to merge 34 commits into
base: createpit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
34da6ea
fixing ci, adding tests and java docs
bharath-techie Apr 12, 2022
30cb6c0
Segregating create pit logic into separate controller
bharath-techie Apr 13, 2022
43fed74
Segregating create pit logic into separate controller
bharath-techie Apr 13, 2022
57232fb
Delete PIT API
bharath-techie Apr 13, 2022
ece4c00
Delete PIT API
bharath-techie Apr 18, 2022
d67e389
Delete PIT API changes
bharath-techie Apr 18, 2022
65c123a
Addressing review comments
bharath-techie Apr 29, 2022
a938e26
Merge branch 'createpit' of github.com:bharath-techie/OpenSearch into…
bharath-techie Apr 29, 2022
6789468
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie May 2, 2022
98451da
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie May 2, 2022
975b871
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie May 2, 2022
2a8e4ff
Merge branch 'createpit' of github.com:bharath-techie/OpenSearch into…
bharath-techie May 2, 2022
77be351
addressing review comments
bharath-techie May 2, 2022
849d1d3
Merge branch 'createpit' of github.com:bharath-techie/OpenSearch into…
bharath-techie May 2, 2022
51ce82f
addressing review comments
bharath-techie May 3, 2022
68e210d
Adding java docs and addressing comments
bharath-techie May 4, 2022
81ff93d
Merge branch 'createpit' of github.com:bharath-techie/OpenSearch into…
bharath-techie May 6, 2022
2acb465
changes to uniformly name pit
bharath-techie May 6, 2022
648402e
Addressing comments
bharath-techie May 10, 2022
480bdc2
Merge branch 'createpit' of github.com:bharath-techie/OpenSearch into…
bharath-techie May 11, 2022
04532f4
adding tests and comments
bharath-techie May 11, 2022
6ceaf61
addressing comments
bharath-techie May 13, 2022
fe4e41a
Merge branch 'createpit' of github.com:bharath-techie/OpenSearch into…
bharath-techie May 13, 2022
1dd62b4
Merge branch 'createpit' of github.com:bharath-techie/OpenSearch into…
bharath-techie May 17, 2022
af9b143
Rest high level clients
bharath-techie May 17, 2022
dc111f5
Merge branch 'createpit' of github.com:bharath-techie/OpenSearch into…
bharath-techie May 17, 2022
87cb8a5
Bump com.diffplug.spotless from 6.5.2 to 6.6.1 (#3356)
dependabot[bot] May 18, 2022
76b5ea6
Bump grpc-context from 1.45.1 to 1.46.0 in /plugins/repository-gcs (#…
dependabot[bot] May 18, 2022
892e984
[Type removal] Remove redundant _type in pipeline simulate action (#3…
dreamer-89 May 18, 2022
f8b102c
Removing hard coded value of max concurrent shard requests (#3364)
jainankitk May 18, 2022
248f188
fixing tests and adding util
bharath-techie May 18, 2022
829d79e
Merge branch 'createpit' of github.com:bharath-techie/OpenSearch into…
bharath-techie May 19, 2022
4a1cbd9
Create PIT API (#2745)
bharath-techie May 19, 2022
45a897f
Merge branch 'feature/point_in_time' of https://github.com/opensearch…
bharath-techie May 19, 2022
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ plugins {
id 'lifecycle-base'
id 'opensearch.docker-support'
id 'opensearch.global-build-info'
id "com.diffplug.spotless" version "6.5.2" apply false
id "com.diffplug.spotless" version "6.6.1" apply false
id "org.gradle.test-retry" version "1.4.0" apply false
id "test-report-aggregation"
id 'jacoco-report-aggregation'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.search.ClearScrollRequest;
import org.opensearch.action.search.CreatePitRequest;
import org.opensearch.action.search.DeletePitRequest;
import org.opensearch.action.search.MultiSearchRequest;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchScrollRequest;
Expand Down Expand Up @@ -477,6 +478,17 @@ static Request createPit(CreatePitRequest createPitRequest) throws IOException {
return request;
}

static Request deletePit(DeletePitRequest deletePitRequest) throws IOException {
Request request = new Request(HttpDelete.METHOD_NAME, "/_search/point_in_time");
request.setEntity(createEntity(deletePitRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request deleteAllPits(DeletePitRequest deletePitRequest) {
Request request = new Request(HttpDelete.METHOD_NAME, "/_search/point_in_time/_all");
return request;
}

static Request clearScroll(ClearScrollRequest clearScrollRequest) throws IOException {
Request request = new Request(HttpDelete.METHOD_NAME, "/_search/scroll");
request.setEntity(createEntity(clearScrollRequest, REQUEST_BODY_CONTENT_TYPE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
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.MultiSearchResponse;
import org.opensearch.action.search.SearchRequest;
Expand Down Expand Up @@ -1298,6 +1300,86 @@ public final Cancellable createPitAsync(
);
}

/**
* Delete PIT context using delete PIT API
*
* @param deletePitRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
*/
public final DeletePitResponse deletePit(DeletePitRequest deletePitRequest, RequestOptions options) throws IOException {
return performRequestAndParseEntity(
deletePitRequest,
RequestConverters::deletePit,
options,
DeletePitResponse::fromXContent,
emptySet()
);
}

/**
* Asynchronously Delete PIT context using delete PIT API
*
* @param deletePitRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @return the response
*/
public final Cancellable deletePitAsync(
DeletePitRequest deletePitRequest,
RequestOptions options,
ActionListener<DeletePitResponse> listener
) {
return performRequestAsyncAndParseEntity(
deletePitRequest,
RequestConverters::deletePit,
options,
DeletePitResponse::fromXContent,
listener,
emptySet()
);
}

/**
* Delete all PIT contexts using delete all PITs API
*
* @param deletePitRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
*/
public final DeletePitResponse deleteAllPits(DeletePitRequest deletePitRequest, RequestOptions options) throws IOException {
return performRequestAndParseEntity(
deletePitRequest,
RequestConverters::deleteAllPits,
options,
DeletePitResponse::fromXContent,
emptySet()
);
}

/**
* Asynchronously Delete all PIT contexts using delete all PITs API
*
* @param deletePitRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @return the response
*/
public final Cancellable deleteAllPitsAsync(
DeletePitRequest deletePitRequest,
RequestOptions options,
ActionListener<DeletePitResponse> listener
) {
return performRequestAsyncAndParseEntity(
deletePitRequest,
RequestConverters::deleteAllPits,
options,
DeletePitResponse::fromXContent,
listener,
emptySet()
);
}

/**
* Clears one or more scroll ids using the Clear Scroll API.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public void testSimulatePipeline() throws IOException {
+ " \"docs\": ["
+ " {"
+ " \"_index\": \"index\","
+ " \"_type\": \"_doc\","
+ " \"_id\": \"id\","
+ " \"_source\": {"
+ " \"foo\": \"rab\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
import org.junit.Before;
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.common.unit.TimeValue;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -51,8 +55,28 @@ public void testCreatePit() throws IOException {
assertEquals(1, pitResponse.getSuccessfulShards());
assertEquals(0, pitResponse.getFailedShards());
assertEquals(0, pitResponse.getSkippedShards());
List<String> pitIds = new ArrayList<>();
pitIds.add(pitResponse.getId());
DeletePitRequest deletePitRequest = new DeletePitRequest(pitIds);
DeletePitResponse deletePitResponse = execute(deletePitRequest, highLevelClient()::deletePit, highLevelClient()::deletePitAsync);
assertTrue(deletePitResponse.isSucceeded());
}
/**
* Todo: add deletion logic and test cluster settings
*/

public void testDeleteAllPits() throws IOException {
CreatePitRequest pitRequest = new CreatePitRequest(new TimeValue(1, TimeUnit.DAYS), true, "index");
CreatePitResponse pitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync);
CreatePitResponse pitResponse1 = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync);
assertTrue(pitResponse.getId() != null);
assertTrue(pitResponse1.getId() != null);
List<String> pitIds = new ArrayList<>();
pitIds.add("_all");
DeletePitRequest deletePitRequest = new DeletePitRequest(pitIds);
DeletePitResponse deletePitResponse = execute(
deletePitRequest,
highLevelClient()::deleteAllPits,
highLevelClient()::deleteAllPitsAsync
);
assertTrue(deletePitResponse.isSucceeded());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.search.ClearScrollRequest;
import org.opensearch.action.search.CreatePitRequest;
import org.opensearch.action.search.DeletePitRequest;
import org.opensearch.action.search.MultiSearchRequest;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.action.search.SearchScrollRequest;
Expand Down Expand Up @@ -1326,6 +1327,28 @@ public void testCreatePit() throws IOException {
assertEquals(REQUEST_BODY_CONTENT_TYPE.mediaTypeWithoutParameters(), request.getEntity().getContentType().getValue());
}

public void testDeletePit() throws IOException {
List<String> pitIds = new ArrayList<>();
pitIds.add("pitid1");
pitIds.add("pitid2");
DeletePitRequest deletePitRequest = new DeletePitRequest(pitIds);
Request request = RequestConverters.deletePit(deletePitRequest);
String endpoint = "/_search/point_in_time";
assertEquals(HttpDelete.METHOD_NAME, request.getMethod());
assertEquals(endpoint, request.getEndpoint());
assertToXContentBody(deletePitRequest, request.getEntity());
assertEquals(REQUEST_BODY_CONTENT_TYPE.mediaTypeWithoutParameters(), request.getEntity().getContentType().getValue());
}

public void testDeleteAllPits() throws IOException {
DeletePitRequest deletePitRequest = new DeletePitRequest();
Request request = RequestConverters.deletePit(deletePitRequest);
String endpoint = "/_search/point_in_time/_all";
assertEquals(HttpDelete.METHOD_NAME, request.getMethod());
assertEquals(endpoint, request.getEndpoint());
assertEquals(REQUEST_BODY_CONTENT_TYPE.mediaTypeWithoutParameters(), request.getEntity().getContentType().getValue());
}

public void testSearchTemplate() throws Exception {
// Create a random request.
String[] indices = randomIndicesNames(0, 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
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.MultiSearchResponse;
import org.opensearch.action.search.SearchRequest;
Expand Down Expand Up @@ -103,6 +105,7 @@
import org.junit.Before;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -774,16 +777,13 @@ public void testSearchWithPit() throws Exception {
client().performRequest(doc);
}
client().performRequest(new Request(HttpPost.METHOD_NAME, "/test/_refresh"));

CreatePitRequest pitRequest = new CreatePitRequest(new TimeValue(1, TimeUnit.DAYS), true, "test");
CreatePitResponse pitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync);

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(35)
.sort("field", SortOrder.ASC)
.pointInTimeBuilder(new PointInTimeBuilder(pitResponse.getId()));
SearchRequest searchRequest = new SearchRequest().source(searchSourceBuilder);
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);

try {
long counter = 0;
assertSearchHeader(searchResponse);
Expand All @@ -793,7 +793,15 @@ public void testSearchWithPit() throws Exception {
assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++));
}
} finally {
// TODO : Delete PIT
List<String> pitIds = new ArrayList<>();
pitIds.add(pitResponse.getId());
DeletePitRequest deletePitRequest = new DeletePitRequest(pitIds);
DeletePitResponse deletePitResponse = execute(
deletePitRequest,
highLevelClient()::deletePit,
highLevelClient()::deletePitAsync
);
assertTrue(deletePitResponse.isSucceeded());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ teardown:
"docs": [
{
"_index": "index",
"_type": "type",
"_id": "id",
"_source": {
"field": "abc2xyz"
Expand Down
2 changes: 1 addition & 1 deletion plugins/repository-gcs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies {
api 'com.google.http-client:google-http-client-jackson2:1.35.0'
api 'com.google.http-client:google-http-client-gson:1.41.4'
api 'com.google.api:gax-httpjson:0.101.0'
api 'io.grpc:grpc-context:1.45.1'
api 'io.grpc:grpc-context:1.46.0'
api 'io.opencensus:opencensus-api:0.18.0'
api 'io.opencensus:opencensus-contrib-http-util:0.18.0'
api 'com.google.apis:google-api-services-storage:v1-rev20200814-1.30.10'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
621d765a459758cdcd9aa4b4795392a4353e3576
28 changes: 28 additions & 0 deletions rest-api-spec/src/main/resources/rest-api-spec/api/delete_pit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"delete_pit":{
"documentation":{
"url":"https://opensearch.org/docs/latest/opensearch/rest-api/point_in_time/",
"description":"Deletes point in time context."
},
"stability":"stable",
"url":{
"paths":[
{
"path":"/_search/point_in_time",
"methods":[
"DELETE"
]
},
{
"path":"/_search/point_in_time/_all",
"methods":[
"DELETE"
]
}
]
},
"body":{
"description":"A comma-separated list of pit IDs to clear"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public void testSimulate() throws Exception {
.startArray("docs")
.startObject()
.field("_index", "index")
.field("_type", "type")
.field("_id", "id")
.startObject("_source")
.field("foo", "bar")
Expand Down
5 changes: 5 additions & 0 deletions server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,13 @@
import org.opensearch.action.main.TransportMainAction;
import org.opensearch.action.search.ClearScrollAction;
import org.opensearch.action.search.CreatePitAction;
import org.opensearch.action.search.DeletePitAction;
import org.opensearch.action.search.MultiSearchAction;
import org.opensearch.action.search.SearchAction;
import org.opensearch.action.search.SearchScrollAction;
import org.opensearch.action.search.TransportClearScrollAction;
import org.opensearch.action.search.TransportCreatePitAction;
import org.opensearch.action.search.TransportDeletePitAction;
import org.opensearch.action.search.TransportMultiSearchAction;
import org.opensearch.action.search.TransportSearchAction;
import org.opensearch.action.search.TransportSearchScrollAction;
Expand Down Expand Up @@ -399,6 +401,7 @@
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;
Expand Down Expand Up @@ -660,6 +663,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(DeleteDanglingIndexAction.INSTANCE, TransportDeleteDanglingIndexAction.class);
actions.register(FindDanglingIndexAction.INSTANCE, TransportFindDanglingIndexAction.class);
actions.register(CreatePitAction.INSTANCE, TransportCreatePitAction.class);
actions.register(DeletePitAction.INSTANCE, TransportDeletePitAction.class);

return unmodifiableMap(actions.getRegistry());
}
Expand Down Expand Up @@ -835,6 +839,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {

// Point in time API
registerHandler.accept(new RestCreatePitAction());
registerHandler.accept(new RestDeletePitAction());
for (ActionPlugin plugin : actionPlugins) {
for (RestHandler handler : plugin.getRestHandlers(
settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,6 @@ public void onFailure(Exception e) {
logger.error("Cleaning up PIT contexts failed ", e);
}
};
ClearScrollController.closeContexts(clusterService.state().getNodes(), searchTransportService, contexts, deleteListener);
SearchUtils.deletePits(contexts, deleteListener, clusterService.state(), searchTransportService);
}
}
Loading