From 730afa8c8351825f2e9e094598c79c37d897db94 Mon Sep 17 00:00:00 2001 From: Bharathwaj G Date: Tue, 3 May 2022 22:22:13 +0530 Subject: [PATCH] Adding java docs Signed-off-by: Bharathwaj G --- .../org/opensearch/search/searchafter/SearchAfterIT.java | 1 + .../java/org/opensearch/search/slice/SearchSliceIT.java | 1 + .../org/opensearch/action/search/CreatePITAction.java | 3 +++ .../action/search/UpdatePitContextResponse.java | 3 +++ .../opensearch/index/shard/SearchOperationListener.java | 9 +++++++++ .../rest/action/search/RestCreatePITAction.java | 3 +++ .../main/java/org/opensearch/search/SearchService.java | 7 +++++++ .../org/opensearch/search/internal/ReaderContext.java | 3 +++ .../action/search/CreatePitControllerTests.java | 4 ++++ .../java/org/opensearch/search/PitMultiNodeTests.java | 3 +++ .../java/org/opensearch/search/PitSingleNodeTests.java | 3 +++ .../opensearch/search/pit/RestCreatePitActionTests.java | 3 +++ 12 files changed, 43 insertions(+) diff --git a/server/src/internalClusterTest/java/org/opensearch/search/searchafter/SearchAfterIT.java b/server/src/internalClusterTest/java/org/opensearch/search/searchafter/SearchAfterIT.java index f1a552c929d3d..735ac50cc71f9 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/searchafter/SearchAfterIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/searchafter/SearchAfterIT.java @@ -209,6 +209,7 @@ public void testPitWithSearchAfter() throws Exception { 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); + client().admin().indices().prepareDelete("test").get(); } public void testWithNullStrings() throws InterruptedException { diff --git a/server/src/internalClusterTest/java/org/opensearch/search/slice/SearchSliceIT.java b/server/src/internalClusterTest/java/org/opensearch/search/slice/SearchSliceIT.java index 6a9b998d3abab..e1ceab904e46d 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/slice/SearchSliceIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/slice/SearchSliceIT.java @@ -176,6 +176,7 @@ public void testSearchSortWithPIT() throws Exception { .addSort(SortBuilders.fieldSort("random_int")); assertSearchSlicesWithPIT(request, field, max, numDocs); } + client().admin().indices().prepareDelete("test").get(); } private void assertSearchSlicesWithPIT(SearchRequestBuilder request, String field, int numSlice, int numDocs) { diff --git a/server/src/main/java/org/opensearch/action/search/CreatePITAction.java b/server/src/main/java/org/opensearch/action/search/CreatePITAction.java index 31b7b8b2bd415..9092932fe4f9e 100644 --- a/server/src/main/java/org/opensearch/action/search/CreatePITAction.java +++ b/server/src/main/java/org/opensearch/action/search/CreatePITAction.java @@ -10,6 +10,9 @@ import org.opensearch.action.ActionType; +/** + * Action type for creating PIT reader context + */ public class CreatePITAction extends ActionType { public static final CreatePITAction INSTANCE = new CreatePITAction(); public static final String NAME = "indices:data/write/pit"; diff --git a/server/src/main/java/org/opensearch/action/search/UpdatePitContextResponse.java b/server/src/main/java/org/opensearch/action/search/UpdatePitContextResponse.java index b907ae1f8b8a9..919dd87ea3041 100644 --- a/server/src/main/java/org/opensearch/action/search/UpdatePitContextResponse.java +++ b/server/src/main/java/org/opensearch/action/search/UpdatePitContextResponse.java @@ -14,6 +14,9 @@ import java.io.IOException; +/** + * Update PIT context response with creation time, keep alive etc. + */ public class UpdatePitContextResponse extends TransportResponse { private final String pitId; diff --git a/server/src/main/java/org/opensearch/index/shard/SearchOperationListener.java b/server/src/main/java/org/opensearch/index/shard/SearchOperationListener.java index bd4e16f50a2cb..e1ca0bea33147 100644 --- a/server/src/main/java/org/opensearch/index/shard/SearchOperationListener.java +++ b/server/src/main/java/org/opensearch/index/shard/SearchOperationListener.java @@ -277,6 +277,10 @@ public void validateReaderContext(ReaderContext readerContext, TransportRequest ExceptionsHelper.reThrowIfNotNull(exception); } + /** + * Executed when a new Point-In-Time {@link ReaderContext} was created + * @param readerContext the created reader context + */ @Override public void onNewPitContext(ReaderContext readerContext) { for (SearchOperationListener listener : listeners) { @@ -288,6 +292,11 @@ public void onNewPitContext(ReaderContext readerContext) { } } + /** + * Executed when a Point-In-Time search {@link SearchContext} is freed. + * This happens on deletion of a Point-In-Time or on it's keep-alive is expiring. + * @param readerContext the freed search context + */ @Override public void onFreePitContext(ReaderContext readerContext) { for (SearchOperationListener listener : listeners) { diff --git a/server/src/main/java/org/opensearch/rest/action/search/RestCreatePITAction.java b/server/src/main/java/org/opensearch/rest/action/search/RestCreatePITAction.java index e257dc17ffa07..e67d674af3ded 100644 --- a/server/src/main/java/org/opensearch/rest/action/search/RestCreatePITAction.java +++ b/server/src/main/java/org/opensearch/rest/action/search/RestCreatePITAction.java @@ -24,6 +24,9 @@ import static java.util.Collections.unmodifiableList; import static org.opensearch.rest.RestRequest.Method.POST; +/** + * Rest action for creating PIT context + */ public class RestCreatePITAction extends BaseRestHandler { @Override public String getName() { diff --git a/server/src/main/java/org/opensearch/search/SearchService.java b/server/src/main/java/org/opensearch/search/SearchService.java index 8a0a08ad5d703..392390d582d4b 100644 --- a/server/src/main/java/org/opensearch/search/SearchService.java +++ b/server/src/main/java/org/opensearch/search/SearchService.java @@ -170,6 +170,9 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv Property.NodeScope, Property.Dynamic ); + /** + * This setting will help validate the max keep alive that can be set during creation or extension for a PIT reader context + */ public static final Setting MAX_PIT_KEEPALIVE_SETTING = Setting.positiveTimeSetting( "pit.max_keep_alive", timeValueHours(24), @@ -222,6 +225,10 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv Property.NodeScope ); + /** + * This setting defines the maximum number of active PIT reader contexts in the node , since each PIT context + * has a resource cost attached to it + */ public static final Setting MAX_OPEN_PIT_CONTEXT = Setting.intSetting( "search.max_open_pit_context", 500, diff --git a/server/src/main/java/org/opensearch/search/internal/ReaderContext.java b/server/src/main/java/org/opensearch/search/internal/ReaderContext.java index 7e720e6cc0c73..6342051ce4405 100644 --- a/server/src/main/java/org/opensearch/search/internal/ReaderContext.java +++ b/server/src/main/java/org/opensearch/search/internal/ReaderContext.java @@ -138,6 +138,9 @@ public Engine.Searcher acquireSearcher(String source) { return searcherSupplier.acquireSearcher(source); } + /** + * Update keep alive if it is greater than current keep alive + */ public void tryUpdateKeepAlive(long keepAlive) { this.keepAlive.updateAndGet(curr -> Math.max(curr, keepAlive)); } diff --git a/server/src/test/java/org/opensearch/action/search/CreatePitControllerTests.java b/server/src/test/java/org/opensearch/action/search/CreatePitControllerTests.java index 9742a58346e73..c69d3ad7da1bb 100644 --- a/server/src/test/java/org/opensearch/action/search/CreatePitControllerTests.java +++ b/server/src/test/java/org/opensearch/action/search/CreatePitControllerTests.java @@ -50,6 +50,10 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +/** + * Functional tests for various methods in create pit controller. Covers update pit phase specifically since + * integration tests don't cover it. + */ public class CreatePitControllerTests extends OpenSearchTestCase { DiscoveryNode node1 = null; diff --git a/server/src/test/java/org/opensearch/search/PitMultiNodeTests.java b/server/src/test/java/org/opensearch/search/PitMultiNodeTests.java index 3efdcadb8e09f..f04061791e3f0 100644 --- a/server/src/test/java/org/opensearch/search/PitMultiNodeTests.java +++ b/server/src/test/java/org/opensearch/search/PitMultiNodeTests.java @@ -27,6 +27,9 @@ import static org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; +/** + * Multi node integration tests for PIT creation and search operation with PIT ID. + */ @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, numDataNodes = 2) public class PitMultiNodeTests extends OpenSearchIntegTestCase { diff --git a/server/src/test/java/org/opensearch/search/PitSingleNodeTests.java b/server/src/test/java/org/opensearch/search/PitSingleNodeTests.java index 9bad643a4f0ac..98c518738939c 100644 --- a/server/src/test/java/org/opensearch/search/PitSingleNodeTests.java +++ b/server/src/test/java/org/opensearch/search/PitSingleNodeTests.java @@ -31,6 +31,9 @@ import static org.opensearch.index.query.QueryBuilders.termQuery; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount; +/** + * Single node integration tests for various PIT use cases such as create pit, search etc + */ public class PitSingleNodeTests extends OpenSearchSingleNodeTestCase { @Override protected boolean resetNodeAfterTest() { diff --git a/server/src/test/java/org/opensearch/search/pit/RestCreatePitActionTests.java b/server/src/test/java/org/opensearch/search/pit/RestCreatePitActionTests.java index f922b4e9af497..202a0a8fe3c01 100644 --- a/server/src/test/java/org/opensearch/search/pit/RestCreatePitActionTests.java +++ b/server/src/test/java/org/opensearch/search/pit/RestCreatePitActionTests.java @@ -25,6 +25,9 @@ import static org.hamcrest.Matchers.equalTo; +/** + * Tests to verify behavior of create pit rest action + */ public class RestCreatePitActionTests extends OpenSearchTestCase { public void testRestCreatePit() throws Exception { SetOnce createPitCalled = new SetOnce<>();