Search in sources :

Example 1 with RecoveryRequest

use of org.opensearch.action.admin.indices.recovery.RecoveryRequest in project OpenSearch by opensearch-project.

the class IndexRecoveryIT method testHistoryRetention.

public void testHistoryRetention() throws Exception {
    internalCluster().startNodes(3);
    final String indexName = "test";
    client().admin().indices().prepareCreate(indexName).setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2).put(IndexSettings.FILE_BASED_RECOVERY_THRESHOLD_SETTING.getKey(), 1.0)).get();
    ensureGreen(indexName);
    // Perform some replicated operations so the replica isn't simply empty, because ops-based recovery isn't better in that case
    final List<IndexRequestBuilder> requests = new ArrayList<>();
    final int replicatedDocCount = scaledRandomIntBetween(25, 250);
    while (requests.size() < replicatedDocCount) {
        requests.add(client().prepareIndex(indexName).setSource("{}", XContentType.JSON));
    }
    indexRandom(true, requests);
    if (randomBoolean()) {
        flush(indexName);
    }
    String firstNodeToStop = randomFrom(internalCluster().getNodeNames());
    Settings firstNodeToStopDataPathSettings = internalCluster().dataPathSettings(firstNodeToStop);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(firstNodeToStop));
    String secondNodeToStop = randomFrom(internalCluster().getNodeNames());
    Settings secondNodeToStopDataPathSettings = internalCluster().dataPathSettings(secondNodeToStop);
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(secondNodeToStop));
    final long desyncNanoTime = System.nanoTime();
    // noinspection StatementWithEmptyBody
    while (System.nanoTime() <= desyncNanoTime) {
    // time passes
    }
    final int numNewDocs = scaledRandomIntBetween(25, 250);
    for (int i = 0; i < numNewDocs; i++) {
        client().prepareIndex(indexName).setSource("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
    }
    // Flush twice to update the safe commit's local checkpoint
    assertThat(client().admin().indices().prepareFlush(indexName).setForce(true).execute().get().getFailedShards(), equalTo(0));
    assertThat(client().admin().indices().prepareFlush(indexName).setForce(true).execute().get().getFailedShards(), equalTo(0));
    assertAcked(client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)));
    internalCluster().startNode(randomFrom(firstNodeToStopDataPathSettings, secondNodeToStopDataPathSettings));
    ensureGreen(indexName);
    final RecoveryResponse recoveryResponse = client().admin().indices().recoveries(new RecoveryRequest(indexName)).get();
    final List<RecoveryState> recoveryStates = recoveryResponse.shardRecoveryStates().get(indexName);
    recoveryStates.removeIf(r -> r.getTimer().getStartNanoTime() <= desyncNanoTime);
    assertThat(recoveryStates, hasSize(1));
    assertThat(recoveryStates.get(0).getIndex().totalFileCount(), is(0));
    assertThat(recoveryStates.get(0).getTranslog().recoveredOperations(), greaterThan(0));
}
Also used : IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) RecoveryRequest(org.opensearch.action.admin.indices.recovery.RecoveryRequest) ArrayList(java.util.ArrayList) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) RecoveryResponse(org.opensearch.action.admin.indices.recovery.RecoveryResponse)

Example 2 with RecoveryRequest

use of org.opensearch.action.admin.indices.recovery.RecoveryRequest in project OpenSearch by opensearch-project.

the class RestRecoveryAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index")));
    recoveryRequest.detailed(request.paramAsBoolean("detailed", false));
    recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false));
    recoveryRequest.indicesOptions(IndicesOptions.fromRequest(request, recoveryRequest.indicesOptions()));
    return channel -> client.admin().indices().recoveries(recoveryRequest, new RestToXContentListener<>(channel));
}
Also used : List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) Arrays.asList(java.util.Arrays.asList) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) BaseRestHandler(org.opensearch.rest.BaseRestHandler) RecoveryRequest(org.opensearch.action.admin.indices.recovery.RecoveryRequest) Strings(org.opensearch.common.Strings) RecoveryRequest(org.opensearch.action.admin.indices.recovery.RecoveryRequest)

Example 3 with RecoveryRequest

use of org.opensearch.action.admin.indices.recovery.RecoveryRequest in project OpenSearch by opensearch-project.

the class IndicesRequestIT method testRecovery.

public void testRecovery() {
    String recoveryAction = RecoveryAction.NAME + "[n]";
    interceptTransportActions(recoveryAction);
    RecoveryRequest recoveryRequest = new RecoveryRequest(randomIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().recoveries(recoveryRequest).actionGet();
    clearInterceptedActions();
    assertSameIndices(recoveryRequest, recoveryAction);
}
Also used : RecoveryRequest(org.opensearch.action.admin.indices.recovery.RecoveryRequest)

Example 4 with RecoveryRequest

use of org.opensearch.action.admin.indices.recovery.RecoveryRequest in project OpenSearch by opensearch-project.

the class RestCatRecoveryAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index")));
    recoveryRequest.timeout(request.param("timeout"));
    recoveryRequest.detailed(request.paramAsBoolean("detailed", false));
    recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false));
    recoveryRequest.indicesOptions(IndicesOptions.fromRequest(request, recoveryRequest.indicesOptions()));
    return channel -> client.admin().indices().recoveries(recoveryRequest, new RestResponseListener<RecoveryResponse>(channel) {

        @Override
        public RestResponse buildResponse(final RecoveryResponse response) throws Exception {
            return RestTable.buildResponse(buildRecoveryTable(request, response), channel);
        }
    });
}
Also used : TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) SnapshotRecoverySource(org.opensearch.cluster.routing.RecoverySource.SnapshotRecoverySource) Table(org.opensearch.common.Table) IndicesOptions(org.opensearch.action.support.IndicesOptions) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) CollectionUtil(org.apache.lucene.util.CollectionUtil) RecoverySource(org.opensearch.cluster.routing.RecoverySource) RecoveryResponse(org.opensearch.action.admin.indices.recovery.RecoveryResponse) List(java.util.List) RecoveryState(org.opensearch.indices.recovery.RecoveryState) Locale(java.util.Locale) Arrays.asList(java.util.Arrays.asList) XContentOpenSearchExtension(org.opensearch.common.xcontent.XContentOpenSearchExtension) Comparator(java.util.Comparator) RecoveryRequest(org.opensearch.action.admin.indices.recovery.RecoveryRequest) RestResponseListener(org.opensearch.rest.action.RestResponseListener) RecoveryRequest(org.opensearch.action.admin.indices.recovery.RecoveryRequest) RestResponse(org.opensearch.rest.RestResponse) RecoveryResponse(org.opensearch.action.admin.indices.recovery.RecoveryResponse)

Aggregations

RecoveryRequest (org.opensearch.action.admin.indices.recovery.RecoveryRequest)4 Arrays.asList (java.util.Arrays.asList)2 Collections.unmodifiableList (java.util.Collections.unmodifiableList)2 List (java.util.List)2 RecoveryResponse (org.opensearch.action.admin.indices.recovery.RecoveryResponse)2 IndicesOptions (org.opensearch.action.support.IndicesOptions)2 NodeClient (org.opensearch.client.node.NodeClient)2 Strings (org.opensearch.common.Strings)2 RestRequest (org.opensearch.rest.RestRequest)2 GET (org.opensearch.rest.RestRequest.Method.GET)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Locale (java.util.Locale)1 CollectionUtil (org.apache.lucene.util.CollectionUtil)1 IndexRequestBuilder (org.opensearch.action.index.IndexRequestBuilder)1 RecoverySource (org.opensearch.cluster.routing.RecoverySource)1 SnapshotRecoverySource (org.opensearch.cluster.routing.RecoverySource.SnapshotRecoverySource)1 Table (org.opensearch.common.Table)1 Settings (org.opensearch.common.settings.Settings)1