Skip to content

Commit

Permalink
Adding java docs
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 May 5, 2022
1 parent 232179e commit 730afa8
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import org.opensearch.action.ActionType;

/**
* Action type for creating PIT reader context
*/
public class CreatePITAction extends ActionType<CreatePITResponse> {
public static final CreatePITAction INSTANCE = new CreatePITAction();
public static final String NAME = "indices:data/write/pit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions server/src/main/java/org/opensearch/search/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeValue> MAX_PIT_KEEPALIVE_SETTING = Setting.positiveTimeSetting(
"pit.max_keep_alive",
timeValueHours(24),
Expand Down Expand Up @@ -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<Integer> MAX_OPEN_PIT_CONTEXT = Setting.intSetting(
"search.max_open_pit_context",
500,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> createPitCalled = new SetOnce<>();
Expand Down

0 comments on commit 730afa8

Please sign in to comment.