Skip to content

Commit 8b2fe27

Browse files
Throw CircuitBreakingException for too many shards in snashot status API call (#15688)
Signed-off-by: Lakshya Taragi <[email protected]> (cherry picked from commit f33c786) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent ba11fb9 commit 8b2fe27

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.opensearch.common.unit.TimeValue;
5252
import org.opensearch.common.util.io.IOUtils;
5353
import org.opensearch.core.common.Strings;
54+
import org.opensearch.core.common.breaker.CircuitBreakingException;
5455
import org.opensearch.core.common.unit.ByteSizeUnit;
5556
import org.opensearch.core.rest.RestStatus;
5657
import org.opensearch.index.IndexNotFoundException;
@@ -602,28 +603,28 @@ public void testSnapshotStatusApiFailureForTooManyShardsAcrossSnapshots() throws
602603

603604
// across a single snapshot
604605
assertBusy(() -> {
605-
TooManyShardsInSnapshotsStatusException exception = expectThrows(
606-
TooManyShardsInSnapshotsStatusException.class,
606+
CircuitBreakingException exception = expectThrows(
607+
CircuitBreakingException.class,
607608
() -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(snapshot1).execute().actionGet()
608609
);
609-
assertEquals(exception.status(), RestStatus.REQUEST_ENTITY_TOO_LARGE);
610+
assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS);
610611
assertTrue(
611612
exception.getMessage().endsWith(" is more than the maximum allowed value of shard count [2] for snapshot status request")
612613
);
613614
}, 1, TimeUnit.MINUTES);
614615

615616
// across multiple snapshots
616617
assertBusy(() -> {
617-
TooManyShardsInSnapshotsStatusException exception = expectThrows(
618-
TooManyShardsInSnapshotsStatusException.class,
618+
CircuitBreakingException exception = expectThrows(
619+
CircuitBreakingException.class,
619620
() -> client().admin()
620621
.cluster()
621622
.prepareSnapshotStatus(repositoryName)
622623
.setSnapshots(snapshot1, snapshot2)
623624
.execute()
624625
.actionGet()
625626
);
626-
assertEquals(exception.status(), RestStatus.REQUEST_ENTITY_TOO_LARGE);
627+
assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS);
627628
assertTrue(
628629
exception.getMessage().endsWith(" is more than the maximum allowed value of shard count [2] for snapshot status request")
629630
);
@@ -741,8 +742,8 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
741742
updateSettingsRequest.persistentSettings(Settings.builder().put(MAX_SHARDS_ALLOWED_IN_STATUS_API.getKey(), 2));
742743
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
743744

744-
TooManyShardsInSnapshotsStatusException ex = expectThrows(
745-
TooManyShardsInSnapshotsStatusException.class,
745+
CircuitBreakingException ex = expectThrows(
746+
CircuitBreakingException.class,
746747
() -> client().admin()
747748
.cluster()
748749
.prepareSnapshotStatus(repositoryName)
@@ -751,7 +752,7 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
751752
.execute()
752753
.actionGet()
753754
);
754-
assertEquals(ex.status(), RestStatus.REQUEST_ENTITY_TOO_LARGE);
755+
assertEquals(ex.status(), RestStatus.TOO_MANY_REQUESTS);
755756
assertTrue(ex.getMessage().endsWith(" is more than the maximum allowed value of shard count [2] for snapshot status request"));
756757

757758
logger.info("Reset MAX_SHARDS_ALLOWED_IN_STATUS_API to default value");

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import org.opensearch.common.util.set.Sets;
5050
import org.opensearch.core.action.ActionListener;
5151
import org.opensearch.core.common.Strings;
52+
import org.opensearch.core.common.breaker.CircuitBreaker;
53+
import org.opensearch.core.common.breaker.CircuitBreakingException;
5254
import org.opensearch.core.common.io.stream.StreamInput;
5355
import org.opensearch.core.common.util.CollectionUtils;
5456
import org.opensearch.core.index.shard.ShardId;
@@ -66,7 +68,6 @@
6668
import org.opensearch.snapshots.SnapshotShardsService;
6769
import org.opensearch.snapshots.SnapshotState;
6870
import org.opensearch.snapshots.SnapshotsService;
69-
import org.opensearch.snapshots.TooManyShardsInSnapshotsStatusException;
7071
import org.opensearch.threadpool.ThreadPool;
7172
import org.opensearch.transport.TransportService;
7273

@@ -458,13 +459,17 @@ private Map<SnapshotId, SnapshotInfo> snapshotsInfo(
458459
snapshotsInfoMap.put(snapshotId, snapshotInfo);
459460
}
460461
if (totalShardsAcrossSnapshots > maximumAllowedShardCount && request.indices().length == 0) {
461-
String message = "Total shard count ["
462+
String message = "["
463+
+ repositoryName
464+
+ ":"
465+
+ String.join(", ", request.snapshots())
466+
+ "]"
467+
+ " Total shard count ["
462468
+ totalShardsAcrossSnapshots
463469
+ "] is more than the maximum allowed value of shard count ["
464470
+ maximumAllowedShardCount
465471
+ "] for snapshot status request";
466-
467-
throw new TooManyShardsInSnapshotsStatusException(repositoryName, message, request.snapshots());
472+
throw new CircuitBreakingException(message, CircuitBreaker.Durability.PERMANENT);
468473
}
469474
return unmodifiableMap(snapshotsInfoMap);
470475
}
@@ -520,15 +525,19 @@ private Map<ShardId, IndexShardSnapshotStatus> snapshotShards(
520525
}
521526

522527
if (totalShardsAcrossIndices > maximumAllowedShardCount && requestedIndexNames.isEmpty() == false && isV2Snapshot == false) {
523-
String message = "Total shard count ["
528+
String message = "["
529+
+ repositoryName
530+
+ ":"
531+
+ String.join(", ", request.snapshots())
532+
+ "]"
533+
+ " Total shard count ["
524534
+ totalShardsAcrossIndices
525535
+ "] across the requested indices ["
526536
+ requestedIndexNames.stream().collect(Collectors.joining(", "))
527537
+ "] is more than the maximum allowed value of shard count ["
528538
+ maximumAllowedShardCount
529539
+ "] for snapshot status request";
530-
531-
throw new TooManyShardsInSnapshotsStatusException(repositoryName, message, snapshotName);
540+
throw new CircuitBreakingException(message, CircuitBreaker.Durability.PERMANENT);
532541
}
533542

534543
final Map<ShardId, IndexShardSnapshotStatus> shardStatus = new HashMap<>();

0 commit comments

Comments
 (0)