private static ISessionToken ResolvePartitionLocalSessionToken(SessionContainerState self, DocumentServiceRequest request, string partitionKeyRangeId) { return(SessionTokenHelper.ResolvePartitionLocalSessionToken(request, partitionKeyRangeId, SessionContainer.GetPartitionKeyRangeIdToTokenMap(self, request))); }
private static string ResolvePartitionLocalSessionTokenForGateway(SessionContainerState self, DocumentServiceRequest request, string partitionKeyRangeId) { ConcurrentDictionary <string, ISessionToken> partitionKeyRangeIdToTokenMap = SessionContainer.GetPartitionKeyRangeIdToTokenMap(self, request); if (partitionKeyRangeIdToTokenMap != null) { if (partitionKeyRangeIdToTokenMap.TryGetValue(partitionKeyRangeId, out ISessionToken sessionToken)) { return(partitionKeyRangeId + SessionContainer.sessionTokenSeparator + sessionToken.ConvertToString()); } else if (request.RequestContext.ResolvedPartitionKeyRange.Parents != null) { ISessionToken parentSessionToken = null; for (int parentIndex = request.RequestContext.ResolvedPartitionKeyRange.Parents.Count - 1; parentIndex >= 0; parentIndex--) { if (partitionKeyRangeIdToTokenMap.TryGetValue(request.RequestContext.ResolvedPartitionKeyRange.Parents[parentIndex], out sessionToken)) { // A partition can have more than 1 parent (merge). In that case, we apply Merge to generate a token with both parent's max LSNs parentSessionToken = parentSessionToken != null?parentSessionToken.Merge(sessionToken) : sessionToken; } } // When we don't have the session token for a partition, we can leverage the session token of the parent(s) if (parentSessionToken != null) { return(partitionKeyRangeId + SessionContainer.sessionTokenSeparator + parentSessionToken.ConvertToString()); } } } return(null); }
private static string ResolveGlobalSessionToken(SessionContainerState self, DocumentServiceRequest request) { ConcurrentDictionary <string, ISessionToken> partitionKeyRangeIdToTokenMap = SessionContainer.GetPartitionKeyRangeIdToTokenMap(self, request); if (partitionKeyRangeIdToTokenMap != null) { return(SessionContainer.GetSessionTokenString(partitionKeyRangeIdToTokenMap)); } return(string.Empty); }
private static string ResolvePartitionLocalSessionTokenForGateway(SessionContainerState self, DocumentServiceRequest request, string partitionKeyRangeId) { ConcurrentDictionary <string, ISessionToken> partitionKeyRangeIdToTokenMap = SessionContainer.GetPartitionKeyRangeIdToTokenMap(self, request); if (partitionKeyRangeIdToTokenMap != null) { if (partitionKeyRangeIdToTokenMap.TryGetValue(partitionKeyRangeId, out ISessionToken sessionToken)) { return(partitionKeyRangeId + ":" + sessionToken.ConvertToString()); } else if (request.RequestContext.ResolvedPartitionKeyRange.Parents != null) { for (int parentIndex = request.RequestContext.ResolvedPartitionKeyRange.Parents.Count - 1; parentIndex >= 0; parentIndex--) { if (partitionKeyRangeIdToTokenMap.TryGetValue(request.RequestContext.ResolvedPartitionKeyRange.Parents[parentIndex], out sessionToken)) { return(partitionKeyRangeId + ":" + sessionToken.ConvertToString()); } } } } return(null); }