Search in sources :

Example 1 with ClusterUpdateSettingsRequest

use of org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest in project OpenSearch by opensearch-project.

the class RemoteClustersIT method testProxyModeConnectionWorks.

public void testProxyModeConnectionWorks() throws IOException {
    String cluster2RemoteClusterSeed = "opensearch-2:9300";
    logger.info("Configuring remote cluster [{}]", cluster2RemoteClusterSeed);
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest().persistentSettings(Settings.builder().put("cluster.remote.cluster2.mode", "proxy").put("cluster.remote.cluster2.proxy_address", cluster2RemoteClusterSeed).build());
    assertTrue(cluster1Client().cluster().putSettings(request, RequestOptions.DEFAULT).isAcknowledged());
    RemoteConnectionInfo rci = cluster1Client().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT).getInfos().get(0);
    logger.info("Connection info: {}", rci);
    assertTrue(rci.isConnected());
    assertEquals(2L, cluster1Client().search(new SearchRequest("cluster2:test2"), RequestOptions.DEFAULT).getHits().getTotalHits().value);
}
Also used : SearchRequest(org.opensearch.action.search.SearchRequest) RemoteConnectionInfo(org.opensearch.client.cluster.RemoteConnectionInfo) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Example 2 with ClusterUpdateSettingsRequest

use of org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest in project OpenSearch by opensearch-project.

the class RemoteClustersIT method testSniffModeConnectionFails.

public void testSniffModeConnectionFails() throws IOException {
    String cluster2RemoteClusterSeed = "opensearch-2:9300";
    logger.info("Configuring remote cluster [{}]", cluster2RemoteClusterSeed);
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest().persistentSettings(Settings.builder().put("cluster.remote.cluster2alt.mode", "sniff").put("cluster.remote.cluster2alt.seeds", cluster2RemoteClusterSeed).build());
    assertTrue(cluster1Client().cluster().putSettings(request, RequestOptions.DEFAULT).isAcknowledged());
    RemoteConnectionInfo rci = cluster1Client().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT).getInfos().get(0);
    logger.info("Connection info: {}", rci);
    assertFalse(rci.isConnected());
}
Also used : RemoteConnectionInfo(org.opensearch.client.cluster.RemoteConnectionInfo) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Example 3 with ClusterUpdateSettingsRequest

use of org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest in project OpenSearch by opensearch-project.

the class RemoteClustersIT method testHAProxyModeConnectionWorks.

public void testHAProxyModeConnectionWorks() throws IOException {
    String proxyAddress = "haproxy:9600";
    logger.info("Configuring remote cluster [{}]", proxyAddress);
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest().persistentSettings(Settings.builder().put("cluster.remote.haproxynosn.mode", "proxy").put("cluster.remote.haproxynosn.proxy_address", proxyAddress).build());
    assertTrue(cluster1Client().cluster().putSettings(request, RequestOptions.DEFAULT).isAcknowledged());
    RemoteConnectionInfo rci = cluster1Client().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT).getInfos().get(0);
    logger.info("Connection info: {}", rci);
    assertTrue(rci.isConnected());
    assertEquals(2L, cluster1Client().search(new SearchRequest("haproxynosn:test2"), RequestOptions.DEFAULT).getHits().getTotalHits().value);
}
Also used : SearchRequest(org.opensearch.action.search.SearchRequest) RemoteConnectionInfo(org.opensearch.client.cluster.RemoteConnectionInfo) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Example 4 with ClusterUpdateSettingsRequest

use of org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest in project OpenSearch by opensearch-project.

the class UnsafeBootstrapAndDetachCommandIT method testCanRunUnsafeBootstrapAfterErroneousDetachWithoutLoosingMetadata.

public void testCanRunUnsafeBootstrapAfterErroneousDetachWithoutLoosingMetadata() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(0);
    String masterNode = internalCluster().startMasterOnlyNode();
    Settings masterNodeDataPathSettings = internalCluster().dataPathSettings(masterNode);
    ClusterUpdateSettingsRequest req = new ClusterUpdateSettingsRequest().persistentSettings(Settings.builder().put(INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), "1234kb"));
    internalCluster().client().admin().cluster().updateSettings(req).get();
    ClusterState state = internalCluster().client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.metadata().persistentSettings().get(INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey()), equalTo("1234kb"));
    ensureReadOnlyBlock(false, masterNode);
    internalCluster().stopCurrentMasterNode();
    final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(masterNodeDataPathSettings).build());
    detachCluster(environment);
    // read-only block will remain same as one before bootstrap, in this case it is false
    unsafeBootstrap(environment);
    String masterNode2 = internalCluster().startMasterOnlyNode(masterNodeDataPathSettings);
    ensureGreen();
    ensureReadOnlyBlock(false, masterNode2);
    state = internalCluster().client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.metadata().settings().get(INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey()), equalTo("1234kb"));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) NodeEnvironment(org.opensearch.env.NodeEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) DiscoverySettings(org.opensearch.node.Node.DiscoverySettings) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)

Example 5 with ClusterUpdateSettingsRequest

use of org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest in project OpenSearch by opensearch-project.

the class ShardIndexingPressureSettingsIT method testShardIndexingPressureLastSuccessfulSettingsUpdate.

public void testShardIndexingPressureLastSuccessfulSettingsUpdate() throws Exception {
    final BulkRequest bulkRequest = new BulkRequest();
    int totalRequestSize = 0;
    for (int i = 0; i < 80; ++i) {
        IndexRequest request = new IndexRequest(INDEX_NAME).id(UUIDs.base64UUID()).source(Collections.singletonMap("key", randomAlphaOfLength(50)));
        totalRequestSize += request.ramBytesUsed();
        assertTrue(request.ramBytesUsed() > request.source().length());
        bulkRequest.add(request);
    }
    final long bulkShardRequestSize = totalRequestSize + (RamUsageEstimator.shallowSizeOfInstance(BulkItemRequest.class) * 80) + RamUsageEstimator.shallowSizeOfInstance(BulkShardRequest.class);
    boolean randomBoolean = randomBoolean();
    Settings settings = Settings.builder().put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED.getKey(), true).put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENFORCED.getKey(), true).put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), (long) (bulkShardRequestSize * 3.8) + "B").put(ShardIndexingPressureMemoryManager.MAX_OUTSTANDING_REQUESTS.getKey(), 1).put(ShardIndexingPressureMemoryManager.SUCCESSFUL_REQUEST_ELAPSED_TIMEOUT.getKey(), "10ms").build();
    restartCluster(settings);
    assertAcked(prepareCreate(INDEX_NAME, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)));
    ensureGreen(INDEX_NAME);
    Tuple<String, String> primaryReplicaNodeNames = getPrimaryReplicaNodeNames(INDEX_NAME);
    String primaryName = primaryReplicaNodeNames.v1();
    String coordinatingOnlyNode = getCoordinatingOnlyNode();
    IndexService indexService = internalCluster().getInstance(IndicesService.class, primaryName).iterator().next();
    Index index = indexService.getIndexSettings().getIndex();
    ShardId shardId = new ShardId(index, 0);
    // Send first request which gets successful to set the last successful time-stamp
    if (randomBoolean) {
        ActionFuture<BulkResponse> successFuture = client(coordinatingOnlyNode).bulk(bulkRequest);
        successFuture.actionGet();
    } else {
        ActionFuture<BulkResponse> successFuture = client(primaryName).bulk(bulkRequest);
        successFuture.actionGet();
    }
    // Send couple of more requests which remains outstanding to increase time-stamp value
    ActionFuture<BulkResponse> successFuture;
    ActionFuture<BulkResponse> secondSuccessFuture;
    Releasable primaryReleasable = blockPrimary(primaryName);
    if (randomBoolean) {
        successFuture = client(coordinatingOnlyNode).bulk(bulkRequest);
        secondSuccessFuture = client(coordinatingOnlyNode).bulk(bulkRequest);
    } else {
        successFuture = client(primaryName).bulk(bulkRequest);
        secondSuccessFuture = client(primaryName).bulk(bulkRequest);
    }
    // Delay to breach the success time stamp threshold
    Thread.sleep(25);
    // This request breaches the threshold and hence will be rejected
    if (randomBoolean) {
        ShardIndexingPressureTracker coordinatingShardTracker = internalCluster().getInstance(IndexingPressureService.class, coordinatingOnlyNode).getShardIndexingPressure().getShardIndexingPressureTracker(shardId);
        waitForTwoOutstandingRequests(coordinatingShardTracker);
        expectThrows(OpenSearchRejectedExecutionException.class, () -> client(coordinatingOnlyNode).bulk(bulkRequest).actionGet());
        assertEquals(1, coordinatingShardTracker.getCoordinatingOperationTracker().getRejectionTracker().getTotalRejections());
        assertEquals(1, coordinatingShardTracker.getCoordinatingOperationTracker().getRejectionTracker().getLastSuccessfulRequestLimitsBreachedRejections());
    } else {
        ShardIndexingPressureTracker primaryShardTracker = internalCluster().getInstance(IndexingPressureService.class, primaryName).getShardIndexingPressure().getShardIndexingPressureTracker(shardId);
        waitForTwoOutstandingRequests(primaryShardTracker);
        expectThrows(OpenSearchRejectedExecutionException.class, () -> client(primaryName).bulk(bulkRequest).actionGet());
        assertEquals(1, primaryShardTracker.getCoordinatingOperationTracker().getRejectionTracker().getTotalRejections());
        assertEquals(1, primaryShardTracker.getCoordinatingOperationTracker().getRejectionTracker().getLastSuccessfulRequestLimitsBreachedRejections());
    }
    primaryReleasable.close();
    successFuture.actionGet();
    secondSuccessFuture.actionGet();
    // Update the outstanding threshold setting to see no rejections
    ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
    updateSettingsRequest.persistentSettings(Settings.builder().put(ShardIndexingPressureMemoryManager.MAX_OUTSTANDING_REQUESTS.getKey(), 10));
    assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
    // Verify no rejection with similar request pattern
    primaryReleasable = blockPrimary(primaryName);
    if (randomBoolean) {
        successFuture = client(coordinatingOnlyNode).bulk(bulkRequest);
        secondSuccessFuture = client(coordinatingOnlyNode).bulk(bulkRequest);
    } else {
        successFuture = client(primaryName).bulk(bulkRequest);
        secondSuccessFuture = client(primaryName).bulk(bulkRequest);
    }
    Thread.sleep(25);
    ActionFuture<BulkResponse> thirdSuccessFuture;
    if (randomBoolean) {
        ShardIndexingPressureTracker coordinatingShardTracker = internalCluster().getInstance(IndexingPressureService.class, coordinatingOnlyNode).getShardIndexingPressure().getShardIndexingPressureTracker(shardId);
        thirdSuccessFuture = client(coordinatingOnlyNode).bulk(bulkRequest);
        assertEquals(1, coordinatingShardTracker.getCoordinatingOperationTracker().getRejectionTracker().getTotalRejections());
        assertEquals(1, coordinatingShardTracker.getCoordinatingOperationTracker().getRejectionTracker().getLastSuccessfulRequestLimitsBreachedRejections());
    } else {
        ShardIndexingPressureTracker primaryShardTracker = internalCluster().getInstance(IndexingPressureService.class, primaryName).getShardIndexingPressure().getShardIndexingPressureTracker(shardId);
        thirdSuccessFuture = client(primaryName).bulk(bulkRequest);
        assertEquals(1, primaryShardTracker.getCoordinatingOperationTracker().getRejectionTracker().getTotalRejections());
        assertEquals(1, primaryShardTracker.getCoordinatingOperationTracker().getRejectionTracker().getLastSuccessfulRequestLimitsBreachedRejections());
    }
    primaryReleasable.close();
    successFuture.actionGet();
    secondSuccessFuture.actionGet();
    thirdSuccessFuture.actionGet();
}
Also used : BulkShardRequest(org.opensearch.action.bulk.BulkShardRequest) BulkResponse(org.opensearch.action.bulk.BulkResponse) IndexRequest(org.opensearch.action.index.IndexRequest) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) ShardId(org.opensearch.index.shard.ShardId) BulkRequest(org.opensearch.action.bulk.BulkRequest) Releasable(org.opensearch.common.lease.Releasable) Settings(org.opensearch.common.settings.Settings)

Aggregations

ClusterUpdateSettingsRequest (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)26 Settings (org.opensearch.common.settings.Settings)9 RemoteInfoRequest (org.opensearch.client.cluster.RemoteInfoRequest)6 OpenSearchException (org.opensearch.OpenSearchException)5 BulkRequest (org.opensearch.action.bulk.BulkRequest)5 BulkResponse (org.opensearch.action.bulk.BulkResponse)5 IndexRequest (org.opensearch.action.index.IndexRequest)5 SearchResponse (org.opensearch.action.search.SearchResponse)5 ShardId (org.opensearch.index.shard.ShardId)5 HashMap (java.util.HashMap)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 BulkShardRequest (org.opensearch.action.bulk.BulkShardRequest)4 Map (java.util.Map)3 ClusterUpdateSettingsResponse (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse)3 SearchRequest (org.opensearch.action.search.SearchRequest)3 RemoteConnectionInfo (org.opensearch.client.cluster.RemoteConnectionInfo)3 Releasable (org.opensearch.common.lease.Releasable)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClusterHealthRequest (org.opensearch.action.admin.cluster.health.ClusterHealthRequest)2 ClusterGetSettingsRequest (org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest)2