From 115bb3072717ba33eb4a35a482e3a7fe10ba354e Mon Sep 17 00:00:00 2001 From: Rishikesh Pasham <62345295+Rishikesh1159@users.noreply.github.com> Date: Fri, 21 Apr 2023 18:38:43 -0700 Subject: [PATCH] Making PressureService as Singleton class. (#7274) --- .../index/SegmentReplicationPressureIT.java | 18 ++++++++++++++++++ .../org/opensearch/indices/IndicesModule.java | 2 ++ 2 files changed, 20 insertions(+) diff --git a/server/src/internalClusterTest/java/org/opensearch/index/SegmentReplicationPressureIT.java b/server/src/internalClusterTest/java/org/opensearch/index/SegmentReplicationPressureIT.java index d7699ef3b1e9a..b76d9d5a9cceb 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/SegmentReplicationPressureIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/SegmentReplicationPressureIT.java @@ -5,6 +5,7 @@ package org.opensearch.index; +import org.opensearch.action.admin.indices.replication.SegmentReplicationStatsResponse; import org.opensearch.action.bulk.BulkItemResponse; import org.opensearch.action.bulk.BulkRequest; import org.opensearch.action.bulk.BulkResponse; @@ -101,6 +102,23 @@ public void testWritesRejected() throws Exception { totalDocs.incrementAndGet(); }); }); + // Try to index one more doc. + expectThrows(OpenSearchRejectedExecutionException.class, () -> { + indexDoc(); + totalDocs.incrementAndGet(); + refresh(INDEX_NAME); + }); + + // Verify the rejected doc count. + SegmentReplicationStatsResponse segmentReplicationStatsResponse = dataNodeClient().admin() + .indices() + .prepareSegmentReplicationStats(INDEX_NAME) + .setDetailed(true) + .execute() + .actionGet(); + SegmentReplicationPerGroupStats perGroupStats = segmentReplicationStatsResponse.getReplicationStats().get(INDEX_NAME).get(0); + + assertEquals(perGroupStats.getRejectedRequestCount(), 2L); } refresh(INDEX_NAME); // wait for the replicas to catch up after block is released. diff --git a/server/src/main/java/org/opensearch/indices/IndicesModule.java b/server/src/main/java/org/opensearch/indices/IndicesModule.java index 5a5c79c37a0ac..a5276350d582a 100644 --- a/server/src/main/java/org/opensearch/indices/IndicesModule.java +++ b/server/src/main/java/org/opensearch/indices/IndicesModule.java @@ -42,6 +42,7 @@ import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.NamedWriteableRegistry.Entry; import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.index.SegmentReplicationPressureService; import org.opensearch.index.mapper.BinaryFieldMapper; import org.opensearch.index.mapper.BooleanFieldMapper; import org.opensearch.index.mapper.CompletionFieldMapper; @@ -284,6 +285,7 @@ protected void configure() { bind(RetentionLeaseBackgroundSyncAction.class).asEagerSingleton(); bind(RetentionLeaseSyncer.class).asEagerSingleton(); bind(SegmentReplicationCheckpointPublisher.class).asEagerSingleton(); + bind(SegmentReplicationPressureService.class).asEagerSingleton(); } /**