diff --git a/docs/SdkDesign.md b/docs/SdkDesign.md index e1be7d282a..f277661544 100644 --- a/docs/SdkDesign.md +++ b/docs/SdkDesign.md @@ -17,6 +17,74 @@ flowchart LR TransportClient <--> Service[(Cosmos DB Service)] ``` +## Address caches conceptual model + +![image](https://user-images.githubusercontent.com/6880899/199167007-bcc054c3-ecb1-4469-ba7d-eae52362e9cd.png) + + +- CollectionCache: Dictionary +- CollectionRoutingMap: Single collection PartitionKeyRanges map +- PartitionKeyRangeCache: Dictionary +- GlobalPartitionEndpointManager: Per partition override state. Every reqeust will flow throgh + - Today GlobalEndpointManager is at region scope only and doesn't look at the partition + - Ideal abstraction is to fold it into GlobalEndpointManager --> extra hash computation + - Posible to refactor direct code and flow HashedValue down stream (more contract work with direct package) +- AddressResolver: It does use IAddressCache (Above diagram missing it) + + +```mermaid +flowchart LR + subgraph CDB_account + subgraph CDB_Account_Endpoint + CDB_EP[[CosmosDB-Account/Endpoint]] + end + + subgraph CDB_Account_Region1 + CDBR1_GW[[CosmosDB-Account/Gateway/Region1]] + CDBR1_BE[[CosmosDB-Account/Backend/Region1]] + end + subgraph CDB_Account_RegionN + CDBRN_GW[[CosmosDB-Account/Gateway/Region1]] + CDBRN_BE[[CosmosDB-Account/Backend/RegionN]] + end + end + subgraph AddressCaches + GAC1[GatewayAddressCache/R1] + GACN[GatewayAddressCache/RN] + + GAC1 --> |NonBlockingAsyncCache| CDBR1_GW + GAC1 -.-> CDBR1_BE + GACN --> |NonBlockingAsyncCache| CDBRN_GW + GACN -.-> CDBRN_BE + end +``` + +### Sequence of interaction + +```mermaid +sequenceDiagram + GlobalAddressResolver->>GlobalEndpointManager: ResolveServiceEndpoint(DocumentServiceRequest) + GlobalEndpointManager-->>GlobalAddressResolver: URI (ServingRegion) + GlobalAddressResolver->>GlobalAddressResolver: GetEndpointCache(ServingRegion).AddressResolver + + critical RegularAddressResolution(Implicit contract of dsr.RequestContext.ResolvedPartitionKeyRange population) + GlobalAddressResolver->>AddressResolver: ResolveAsync(DocumentServiceRequest) + AddressResolver-->>GlobalAddressResolver: PartitionAddressInformation + end + + critical AnyPerpartitionOverrides + GlobalAddressResolver->>GlobalPartitionEndpointManager: TryAddPartitionLevelLocationOverride(DocumentServiceRequest) + GlobalPartitionEndpointManager-->>GlobalAddressResolver: (bool, DSR.RequestContext.RouteToLocation) + + option YES + GlobalAddressResolver->>GlobalEndpointManager: ResolveServiceEndpoint(DocumentServiceRequest) + GlobalEndpointManager-->>GlobalAddressResolver: URI (ServingRegion) + end + GlobalAddressResolver->>GlobalAddressResolver: GetEndpointCache(ServingRegion) + GlobalAddressResolver->>AddressResolver: ResolveAsync(DocumentServiceRequest) + AddressResolver-->>GlobalAddressResolver: PartitionAddressInformation +``` + ## Handler pipeline The handler pipeline processes the RequestMessage and each handler can choose to augment it in different ways, as shown in our [handler samples](../Microsoft.Azure.Cosmos.Samples/Usage/Handlers/) and also handle certain error conditions and retry, like our own [RetryHandler](../Microsoft.Azure.Cosmos/src/Handler/RetryHandler.cs). The RetryHandler will handle any failures from the [Transport layer](#transport) that should be [handled as regional failovers](#cross-region-retries).