Skip to content

Commit

Permalink
Delete pit service layer changes
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <bharath78910@gmail.com>
  • Loading branch information
bharath-techie committed Jul 15, 2022
2 parents a8be024 + 8a8f708 commit f20dbdc
Show file tree
Hide file tree
Showing 20 changed files with 2,139 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
import org.opensearch.action.ActionFuture;
import org.opensearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.search.*;
import org.opensearch.action.search.CreatePitAction;
import org.opensearch.action.search.CreatePitRequest;
import org.opensearch.action.search.CreatePitResponse;
import org.opensearch.action.search.SearchPhaseExecutionException;
import org.opensearch.action.search.SearchRequestBuilder;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.action.search.ShardSearchFailure;
import org.opensearch.common.UUIDs;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.xcontent.XContentBuilder;
Expand Down Expand Up @@ -159,48 +165,48 @@ public void testPitWithSearchAfter() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test").setMapping("field1", "type=long", "field2", "type=keyword").get());
ensureGreen();
indexRandom(
true,
client().prepareIndex("test").setId("0").setSource("field1", 0),
client().prepareIndex("test").setId("1").setSource("field1", 100, "field2", "toto"),
client().prepareIndex("test").setId("2").setSource("field1", 101),
client().prepareIndex("test").setId("3").setSource("field1", 99)
true,
client().prepareIndex("test").setId("0").setSource("field1", 0),
client().prepareIndex("test").setId("1").setSource("field1", 100, "field2", "toto"),
client().prepareIndex("test").setId("2").setSource("field1", 101),
client().prepareIndex("test").setId("3").setSource("field1", 99)
);

CreatePitRequest request = new CreatePitRequest(TimeValue.timeValueDays(1), true);
request.setIndices(new String[] { "test" });
ActionFuture<CreatePitResponse> execute = client().execute(CreatePitAction.INSTANCE, request);
CreatePitResponse pitResponse = execute.get();
SearchResponse sr = client().prepareSearch()
.addSort("field1", SortOrder.ASC)
.setQuery(matchAllQuery())
.searchAfter(new Object[] { 99 })
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.get();
.addSort("field1", SortOrder.ASC)
.setQuery(matchAllQuery())
.searchAfter(new Object[] { 99 })
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.get();
assertEquals(2, sr.getHits().getHits().length);
sr = client().prepareSearch()
.addSort("field1", SortOrder.ASC)
.setQuery(matchAllQuery())
.searchAfter(new Object[] { 100 })
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.get();
.addSort("field1", SortOrder.ASC)
.setQuery(matchAllQuery())
.searchAfter(new Object[] { 100 })
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.get();
assertEquals(1, sr.getHits().getHits().length);
sr = client().prepareSearch()
.addSort("field1", SortOrder.ASC)
.setQuery(matchAllQuery())
.searchAfter(new Object[] { 0 })
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.get();
.addSort("field1", SortOrder.ASC)
.setQuery(matchAllQuery())
.searchAfter(new Object[] { 0 })
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.get();
assertEquals(3, sr.getHits().getHits().length);
/**
* Add new data and assert PIT results remain the same and normal search results gets refreshed
*/
indexRandom(true, client().prepareIndex("test").setId("4").setSource("field1", 102));
sr = client().prepareSearch()
.addSort("field1", SortOrder.ASC)
.setQuery(matchAllQuery())
.searchAfter(new Object[] { 0 })
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.get();
.addSort("field1", SortOrder.ASC)
.setQuery(matchAllQuery())
.searchAfter(new Object[] { 0 })
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.get();
assertEquals(3, sr.getHits().getHits().length);
sr = client().prepareSearch().addSort("field1", SortOrder.ASC).setQuery(matchAllQuery()).searchAfter(new Object[] { 0 }).get();
assertEquals(4, sr.getHits().getHits().length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
import org.opensearch.action.admin.indices.alias.IndicesAliasesRequest;

import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.search.*;
import org.opensearch.action.search.CreatePitAction;
import org.opensearch.action.search.CreatePitRequest;
import org.opensearch.action.search.CreatePitResponse;
import org.opensearch.action.search.SearchPhaseExecutionException;
import org.opensearch.action.search.SearchRequestBuilder;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
Expand Down Expand Up @@ -87,10 +92,10 @@ private void setupIndex(int numDocs, int numberOfShards) throws IOException, Exe
.indices()
.prepareCreate("test")
.setSettings(
Settings.builder()
.put("number_of_shards", numberOfShards)
.put("index.max_slices_per_scroll", 10000)
.put("index.max_slices_per_pit", 10000)
Settings.builder()
.put("number_of_shards", numberOfShards)
.put("index.max_slices_per_scroll", 10000)
.put("index.max_slices_per_pit", 10000)
)
.setMapping(mapping)
);
Expand Down Expand Up @@ -140,9 +145,9 @@ public void testSearchSortWithoutPitOrScroll() throws Exception {
setupIndex(numDocs, numShards);
int fetchSize = randomIntBetween(10, 100);
SearchRequestBuilder request = client().prepareSearch("test")
.setQuery(matchAllQuery())
.setSize(fetchSize)
.addSort(SortBuilders.fieldSort("_doc"));
.setQuery(matchAllQuery())
.setSize(fetchSize)
.addSort(SortBuilders.fieldSort("_doc"));
SliceBuilder sliceBuilder = new SliceBuilder("_id", 0, 4);
SearchPhaseExecutionException ex = expectThrows(SearchPhaseExecutionException.class, () -> request.slice(sliceBuilder).get());
assertTrue(ex.getMessage().contains("all shards failed"));
Expand All @@ -162,18 +167,18 @@ public void testSearchSortWithPIT() throws Exception {

// test _doc sort
SearchRequestBuilder request = client().prepareSearch("test")
.setQuery(matchAllQuery())
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.setSize(fetchSize)
.addSort(SortBuilders.fieldSort("_doc"));
.setQuery(matchAllQuery())
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.setSize(fetchSize)
.addSort(SortBuilders.fieldSort("_doc"));
assertSearchSlicesWithPIT(request, field, max, numDocs);

// test numeric sort
request = client().prepareSearch("test")
.setQuery(matchAllQuery())
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.setSize(fetchSize)
.addSort(SortBuilders.fieldSort("random_int"));
.setQuery(matchAllQuery())
.setPointInTime(new PointInTimeBuilder(pitResponse.getId()))
.setSize(fetchSize)
.addSort(SortBuilders.fieldSort("random_int"));
assertSearchSlicesWithPIT(request, field, max, numDocs);
}
client().admin().indices().prepareDelete("test").get();
Expand Down
3 changes: 3 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 @@ -661,6 +663,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg

// point in time actions
actions.register(CreatePitAction.INSTANCE, TransportCreatePitAction.class);
actions.register(DeletePitAction.INSTANCE, TransportDeletePitAction.class);

return unmodifiableMap(actions.getRegistry());
}
Expand Down
Loading

0 comments on commit f20dbdc

Please sign in to comment.