Search in sources :

Example 11 with IndexingPressurePerShardStats

use of org.opensearch.index.stats.IndexingPressurePerShardStats in project OpenSearch by opensearch-project.

the class ShardIndexingPressureTests method testCoordinatingPrimaryShardRejectionSkippedInShadowModeViaSuccessfulRequestsParam.

public void testCoordinatingPrimaryShardRejectionSkippedInShadowModeViaSuccessfulRequestsParam() throws InterruptedException {
    Settings settings = Settings.builder().put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), "10KB").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED.getKey(), true).put(ShardIndexingPressureMemoryManager.MAX_OUTSTANDING_REQUESTS.getKey(), 1).put(ShardIndexingPressureMemoryManager.SUCCESSFUL_REQUEST_ELAPSED_TIMEOUT.getKey(), "20ms").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENFORCED.getKey(), false).build();
    ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
    Index index = new Index("IndexName", "UUID");
    ShardId shardId = new ShardId(index, 0);
    boolean randomBoolean = randomBoolean();
    try (Releasable coordinating = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 1 * 1024, false);
        Releasable primary = shardIndexingPressure.markPrimaryOperationStarted(shardId, 1 * 1024, false)) {
        assertEquals(1 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCoordinatingBytes());
        assertEquals(1 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryBytes());
        assertEquals(2 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCombinedCoordinatingAndPrimaryBytes());
        assertEquals((long) (2 * 1024 / 0.85), shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryAndCoordinatingLimits());
    }
    IndexingPressurePerShardStats shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    assertEquals(0, shardStats.getCurrentCoordinatingBytes());
    assertEquals(0, shardStats.getCurrentPrimaryBytes());
    assertEquals(0, shardStats.getCurrentCombinedCoordinatingAndPrimaryBytes());
    assertEquals(1 * 1024, shardStats.getTotalCoordinatingBytes());
    assertEquals(1 * 1024, shardStats.getTotalPrimaryBytes());
    assertEquals(2 * 1024, shardStats.getTotalCombinedCoordinatingAndPrimaryBytes());
    assertEquals(10, shardStats.getCurrentPrimaryAndCoordinatingLimits());
    Thread.sleep(25);
    // Total Bytes are 9*1024 and node limit is 10*1024
    if (randomBoolean) {
        try (Releasable coordinating = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 7 * 1024, false);
            Releasable coordinating1 = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 1 * 1024, false)) {
            Releasable coordinating2 = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 1 * 1024, false);
            coordinating2.close();
        }
    } else {
        try (Releasable primary = shardIndexingPressure.markPrimaryOperationStarted(shardId, 7 * 1024, false);
            Releasable primary1 = shardIndexingPressure.markPrimaryOperationStarted(shardId, 1 * 1024, false)) {
            Releasable primary2 = shardIndexingPressure.markPrimaryOperationStarted(shardId, 1 * 1024, false);
            primary2.close();
        }
    }
    shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    if (randomBoolean) {
        assertEquals(0, shardStats.getCoordinatingRejections());
        assertEquals(0, shardStats.getCurrentCoordinatingBytes());
        assertEquals(1, shardStats.getCoordinatingLastSuccessfulRequestLimitsBreachedRejections());
    } else {
        assertEquals(0, shardStats.getPrimaryRejections());
        assertEquals(0, shardStats.getCurrentPrimaryBytes());
        assertEquals(1, shardStats.getPrimaryLastSuccessfulRequestLimitsBreachedRejections());
    }
    IndexingPressureStats nodeStats = shardIndexingPressure.stats();
    if (randomBoolean) {
        assertEquals(0, nodeStats.getCoordinatingRejections());
        assertEquals(0, nodeStats.getCurrentCoordinatingBytes());
    } else {
        assertEquals(0, nodeStats.getPrimaryRejections());
        assertEquals(0, nodeStats.getCurrentPrimaryBytes());
    }
}
Also used : ShardId(org.opensearch.index.shard.ShardId) Releasable(org.opensearch.common.lease.Releasable) IndexingPressureStats(org.opensearch.index.stats.IndexingPressureStats) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) IndexingPressurePerShardStats(org.opensearch.index.stats.IndexingPressurePerShardStats)

Example 12 with IndexingPressurePerShardStats

use of org.opensearch.index.stats.IndexingPressurePerShardStats in project OpenSearch by opensearch-project.

the class ShardIndexingPressureTests method testCoordinatingPrimaryShardRejectionSkippedInShadowModeViaThroughputDegradationParam.

public void testCoordinatingPrimaryShardRejectionSkippedInShadowModeViaThroughputDegradationParam() throws InterruptedException {
    Settings settings = Settings.builder().put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), "10KB").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED.getKey(), true).put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENFORCED.getKey(), false).put(ShardIndexingPressureMemoryManager.THROUGHPUT_DEGRADATION_LIMITS.getKey(), 1).put(ShardIndexingPressureSettings.REQUEST_SIZE_WINDOW.getKey(), 1).build();
    ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
    Index index = new Index("IndexName", "UUID");
    ShardId shardId = new ShardId(index, 0);
    boolean randomBoolean = randomBoolean();
    try (Releasable coordinating = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 1 * 1024, false);
        Releasable coordinating1 = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 3 * 1024, false);
        Releasable primary = shardIndexingPressure.markPrimaryOperationStarted(shardId, 1 * 1024, false);
        Releasable primary1 = shardIndexingPressure.markPrimaryOperationStarted(shardId, 3 * 1024, false)) {
        assertEquals(4 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCoordinatingBytes());
        assertEquals(4 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryBytes());
        assertEquals(8 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCombinedCoordinatingAndPrimaryBytes());
        assertEquals((long) (8 * 1024 / 0.85), shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryAndCoordinatingLimits());
        // Adding delay in the current in flight request to mimic throughput degradation
        Thread.sleep(100);
    }
    if (randomBoolean) {
        Releasable coordinating = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 8 * 1024, false);
        coordinating.close();
    } else {
        Releasable primary = shardIndexingPressure.markPrimaryOperationStarted(shardId, 8 * 1024, false);
        primary.close();
    }
    IndexingPressurePerShardStats shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    if (randomBoolean) {
        assertEquals(0, shardStats.getCoordinatingRejections());
        assertEquals(1, shardStats.getCoordinatingThroughputDegradationLimitsBreachedRejections());
        assertEquals(0, shardStats.getCurrentCoordinatingBytes());
        assertEquals(12 * 1024, shardStats.getTotalCoordinatingBytes());
    } else {
        assertEquals(0, shardStats.getPrimaryRejections());
        assertEquals(1, shardStats.getPrimaryThroughputDegradationLimitsBreachedRejections());
        assertEquals(0, shardStats.getCurrentPrimaryBytes());
        assertEquals(12 * 1024, shardStats.getTotalPrimaryBytes());
    }
    assertEquals(10, shardStats.getCurrentPrimaryAndCoordinatingLimits());
    assertEquals(0, shardStats.getCurrentCombinedCoordinatingAndPrimaryBytes());
    assertEquals(16 * 1024, shardStats.getTotalCombinedCoordinatingAndPrimaryBytes());
    IndexingPressureStats nodeStats = shardIndexingPressure.stats();
    if (randomBoolean) {
        assertEquals(0, nodeStats.getCoordinatingRejections());
        assertEquals(0, nodeStats.getCurrentCoordinatingBytes());
    } else {
        assertEquals(0, nodeStats.getPrimaryRejections());
        assertEquals(0, nodeStats.getCurrentPrimaryBytes());
    }
}
Also used : ShardId(org.opensearch.index.shard.ShardId) Releasable(org.opensearch.common.lease.Releasable) IndexingPressureStats(org.opensearch.index.stats.IndexingPressureStats) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) IndexingPressurePerShardStats(org.opensearch.index.stats.IndexingPressurePerShardStats)

Example 13 with IndexingPressurePerShardStats

use of org.opensearch.index.stats.IndexingPressurePerShardStats in project OpenSearch by opensearch-project.

the class ShardIndexingPressureTests method testCoordinatingPrimaryShardLimitIncreaseEvaluateSecondaryParam.

public void testCoordinatingPrimaryShardLimitIncreaseEvaluateSecondaryParam() {
    ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
    Index index = new Index("IndexName", "UUID");
    ShardId shardId = new ShardId(index, 0);
    try (Releasable coordinating = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 4 * 1024, false);
        Releasable primary = shardIndexingPressure.markPrimaryOperationStarted(shardId, 4 * 1024, false)) {
        assertEquals(4 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCoordinatingBytes());
        assertEquals(4 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryBytes());
        assertEquals(8 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCombinedCoordinatingAndPrimaryBytes());
        assertEquals((long) (8 * 1024 / 0.85), shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryAndCoordinatingLimits());
    }
    IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId);
    assertNull(shardStoreStats);
    IndexingPressurePerShardStats shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    assertEquals(0, shardStats.getCurrentCoordinatingBytes());
    assertEquals(0, shardStats.getCurrentPrimaryBytes());
    assertEquals(0, shardStats.getCurrentCombinedCoordinatingAndPrimaryBytes());
    assertEquals(4 * 1024, shardStats.getTotalCoordinatingBytes());
    assertEquals(4 * 1024, shardStats.getTotalPrimaryBytes());
    assertEquals(8 * 1024, shardStats.getTotalCombinedCoordinatingAndPrimaryBytes());
    assertEquals(10, shardStats.getCurrentPrimaryAndCoordinatingLimits());
}
Also used : ShardId(org.opensearch.index.shard.ShardId) Releasable(org.opensearch.common.lease.Releasable) IndexingPressurePerShardStats(org.opensearch.index.stats.IndexingPressurePerShardStats)

Example 14 with IndexingPressurePerShardStats

use of org.opensearch.index.stats.IndexingPressurePerShardStats in project OpenSearch by opensearch-project.

the class ShardIndexingPressureTests method testCoordinatingPrimaryShardLimitIncrease.

public void testCoordinatingPrimaryShardLimitIncrease() {
    ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
    Index index = new Index("IndexName", "UUID");
    ShardId shardId = new ShardId(index, 0);
    boolean randomBoolean = randomBoolean();
    try (Releasable coordinating = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 2, false);
        Releasable primary = shardIndexingPressure.markPrimaryOperationStarted(shardId, 2, false)) {
        assertEquals(2, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCoordinatingBytes());
        assertEquals(4, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCombinedCoordinatingAndPrimaryBytes());
        assertEquals(10, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryAndCoordinatingLimits());
        // Base Limit
        if (randomBoolean) {
            Releasable coordinating1 = shardIndexingPressure.markCoordinatingOperationStarted(shardId, 6, false);
            assertEquals(8, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCoordinatingBytes());
            assertEquals(10, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCombinedCoordinatingAndPrimaryBytes());
            assertEquals(11, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryAndCoordinatingLimits());
            // Increased Limit
            coordinating1.close();
        } else {
            Releasable primary1 = shardIndexingPressure.markPrimaryOperationStarted(shardId, 6, false);
            assertEquals(8, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryBytes());
            assertEquals(10, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentCombinedCoordinatingAndPrimaryBytes());
            assertEquals(11, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentPrimaryAndCoordinatingLimits());
            // Increased Limit
            primary1.close();
        }
    }
    IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId);
    assertNull(shardStoreStats);
    IndexingPressurePerShardStats shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    if (randomBoolean) {
        assertEquals(0, shardStats.getCurrentCoordinatingBytes());
        assertEquals(8, shardStats.getTotalCoordinatingBytes());
    } else {
        assertEquals(0, shardStats.getCurrentPrimaryBytes());
        assertEquals(8, shardStats.getTotalPrimaryBytes());
    }
    assertEquals(0, shardStats.getCurrentCombinedCoordinatingAndPrimaryBytes());
    assertEquals(10, shardStats.getTotalCombinedCoordinatingAndPrimaryBytes());
    assertEquals(10, shardStats.getCurrentPrimaryAndCoordinatingLimits());
}
Also used : ShardId(org.opensearch.index.shard.ShardId) Releasable(org.opensearch.common.lease.Releasable) IndexingPressurePerShardStats(org.opensearch.index.stats.IndexingPressurePerShardStats)

Example 15 with IndexingPressurePerShardStats

use of org.opensearch.index.stats.IndexingPressurePerShardStats in project OpenSearch by opensearch-project.

the class ShardIndexingPressureTests method testReplicaShardRejectionSkippedInShadowModeViaSuccessfulRequestsParam.

public void testReplicaShardRejectionSkippedInShadowModeViaSuccessfulRequestsParam() throws InterruptedException {
    Settings settings = Settings.builder().put(IndexingPressure.MAX_INDEXING_BYTES.getKey(), "10KB").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED.getKey(), true).put(ShardIndexingPressureMemoryManager.MAX_OUTSTANDING_REQUESTS.getKey(), 1).put(ShardIndexingPressureMemoryManager.SUCCESSFUL_REQUEST_ELAPSED_TIMEOUT.getKey(), "20ms").put(ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENFORCED.getKey(), false).build();
    ShardIndexingPressure shardIndexingPressure = new ShardIndexingPressure(settings, clusterService);
    Index index = new Index("IndexName", "UUID");
    ShardId shardId = new ShardId(index, 0);
    try (Releasable replica = shardIndexingPressure.markReplicaOperationStarted(shardId, 1 * 1024, false)) {
        assertEquals(1 * 1024, shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentReplicaBytes());
        assertEquals((long) (1 * 1024 / 0.85), shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId).getCurrentReplicaLimits());
    }
    IndexingPressurePerShardStats shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    assertEquals(0, shardStats.getCurrentReplicaBytes());
    assertEquals(1 * 1024, shardStats.getTotalReplicaBytes());
    assertEquals(15, shardStats.getCurrentReplicaLimits());
    Thread.sleep(25);
    // Total Bytes are 14*1024 and node limit is 15*1024
    try (Releasable replica = shardIndexingPressure.markReplicaOperationStarted(shardId, 10 * 1024, false);
        Releasable replica1 = shardIndexingPressure.markReplicaOperationStarted(shardId, 2 * 1024, false)) {
        Releasable replica2 = shardIndexingPressure.markReplicaOperationStarted(shardId, 2 * 1024, false);
        replica2.close();
    }
    shardStats = shardIndexingPressure.coldStats().getIndexingPressureShardStats(shardId);
    assertEquals(0, shardStats.getReplicaRejections());
    assertEquals(0, shardStats.getCurrentReplicaBytes());
    assertEquals(1, shardStats.getReplicaLastSuccessfulRequestLimitsBreachedRejections());
    IndexingPressureStats nodeStats = shardIndexingPressure.stats();
    assertEquals(0, nodeStats.getReplicaRejections());
    assertEquals(0, nodeStats.getCurrentReplicaBytes());
}
Also used : ShardId(org.opensearch.index.shard.ShardId) Releasable(org.opensearch.common.lease.Releasable) IndexingPressureStats(org.opensearch.index.stats.IndexingPressureStats) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) IndexingPressurePerShardStats(org.opensearch.index.stats.IndexingPressurePerShardStats)

Aggregations

ShardId (org.opensearch.index.shard.ShardId)43 IndexingPressurePerShardStats (org.opensearch.index.stats.IndexingPressurePerShardStats)43 Releasable (org.opensearch.common.lease.Releasable)31 ClusterSettings (org.opensearch.common.settings.ClusterSettings)18 Settings (org.opensearch.common.settings.Settings)18 IndexingPressureStats (org.opensearch.index.stats.IndexingPressureStats)18 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)6 ClusterState (org.opensearch.cluster.ClusterState)6 ShardRouting (org.opensearch.cluster.routing.ShardRouting)6 IndexingPressureService (org.opensearch.index.IndexingPressureService)6 ShardIndexingPressureSettings (org.opensearch.index.ShardIndexingPressureSettings)6 CommonStatsFlags (org.opensearch.action.admin.indices.stats.CommonStatsFlags)5 ShardIndexingPressureStats (org.opensearch.index.stats.ShardIndexingPressureStats)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)2 BulkItemRequest (org.opensearch.action.bulk.BulkItemRequest)1 BulkRequest (org.opensearch.action.bulk.BulkRequest)1 BulkShardRequest (org.opensearch.action.bulk.BulkShardRequest)1