Azure / Azure/azure-sdk-for-python

Cosmos: Per-Partition Circuit Breaker should only be enabled when multiple regions are available

オープン
#46,327 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
Client Cosmos
主要言語
Python
スター
5.6k
フォーク
3.4k
平均マージ
2日 2時間
マージ済み PR(30日)
213

説明

## Description

The per-partition circuit breaker (PPCB) should only be enabled when there are multiple regions a request can be routed to. If there is only a single region available, circuit breaking provides no benefit since there is no fallback region to route to.

## Current Behavior

In [`_global_partition_endpoint_manager_circuit_breaker_core.py` (L60-L85)](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/cosmos/azure-cosmos/azure/cosmos/_global_partition_endpoint_manager_circuit_breaker_core.py#L60-L85), `is_circuit_breaker_applicable` checks whether multi-write locations can be used for write requests, but does not verify that there are actually multiple regions available for the request type (read or write).

For example, if a client has only 1 preferred region or excludes all but 1 region, PPCB should not kick in since there is nowhere to failover to.

## Expected Behavior

Add a check similar to the Java SDK implementation in [`GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker.java` (L429-L442)](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/perPartitionCircuitBreaker/GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker.java#L429-L442):

- If multi-write locations **cannot** be used:
- For **write** requests: return `False` (already handled)
- For **read** requests: only enable PPCB if there are **more than 1** applicable read endpoints
- If multi-write locations **can** be used:
- Only enable PPCB if there are **more than 1** applicable write endpoints

### Java SDK Reference

```java
if (!globalEndpointManager.canUseMultipleWriteLocations(request)) {
if (!request.isReadOnlyRequest()) {
return false;
}
UnmodifiableList applicableReadEndpoints =
globalEndpointManager.getApplicableReadRegionalRoutingContexts(Collections.emptyList());
return applicableReadEndpoints != null && applicableReadEndpoints.size() > 1;
}

UnmodifiableList applicableWriteEndpoints =
globalEndpointManager.getApplicableWriteRegionalRoutingContexts(Collections.emptyList());
return applicableWriteEndpoints != null && applicableWriteEndpoints.size() > 1;
```

## Suggested Change

In `is_circuit_breaker_applicable`, after the existing write-location check, add logic to verify the number of applicable endpoints:

1. When `can_use_multiple_write_locations` is `False` and the request is a read: check that the number of applicable read regions > 1
2. When `can_use_multiple_write_locations` is `True`: check that the number of applicable write regions > 1

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

sdk/cosmos/azure-cosmos/azure/cosmos/_global_partition_endpoint_manager_circuit_breaker_core.py、特に L60-L85 の is_circuit_breaker_applicable から始めます。エンドポイント数のロジックを、GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker.java L429-L442 の参照されている Java 実装と比較します。リクエストタイプに対して適用可能な読み取りまたは書き込みエンドポイントが 2 つ以上ある場合にのみ PPCB が有効になることが完了条件です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
databases
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
72/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。