@azure/cosmos 4.5.0-alpha.20250829.1 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/common/constants.js +1 -1
- package/dist/browser/common/constants.js.map +1 -1
- package/dist/browser/globalEndpointManager.d.ts.map +1 -1
- package/dist/browser/globalEndpointManager.js +15 -19
- package/dist/browser/globalEndpointManager.js.map +1 -1
- package/dist/browser/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/defaultRetryPolicy.js +3 -4
- package/dist/browser/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts +3 -2
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.js +13 -5
- package/dist/browser/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/browser/retry/retryUtility.d.ts.map +1 -1
- package/dist/browser/retry/retryUtility.js +3 -2
- package/dist/browser/retry/retryUtility.js.map +1 -1
- package/dist/commonjs/common/constants.js +1 -1
- package/dist/commonjs/common/constants.js.map +1 -1
- package/dist/commonjs/globalEndpointManager.d.ts.map +1 -1
- package/dist/commonjs/globalEndpointManager.js +15 -19
- package/dist/commonjs/globalEndpointManager.js.map +1 -1
- package/dist/commonjs/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/defaultRetryPolicy.js +2 -3
- package/dist/commonjs/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts +3 -2
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js +13 -5
- package/dist/commonjs/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/commonjs/retry/retryUtility.d.ts.map +1 -1
- package/dist/commonjs/retry/retryUtility.js +3 -2
- package/dist/commonjs/retry/retryUtility.js.map +1 -1
- package/dist/esm/common/constants.js +1 -1
- package/dist/esm/common/constants.js.map +1 -1
- package/dist/esm/globalEndpointManager.d.ts.map +1 -1
- package/dist/esm/globalEndpointManager.js +15 -19
- package/dist/esm/globalEndpointManager.js.map +1 -1
- package/dist/esm/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/defaultRetryPolicy.js +3 -4
- package/dist/esm/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts +3 -2
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.js +13 -5
- package/dist/esm/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/esm/retry/retryUtility.d.ts.map +1 -1
- package/dist/esm/retry/retryUtility.js +3 -2
- package/dist/esm/retry/retryUtility.js.map +1 -1
- package/dist/react-native/common/constants.js +1 -1
- package/dist/react-native/common/constants.js.map +1 -1
- package/dist/react-native/globalEndpointManager.d.ts.map +1 -1
- package/dist/react-native/globalEndpointManager.js +15 -19
- package/dist/react-native/globalEndpointManager.js.map +1 -1
- package/dist/react-native/retry/defaultRetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/defaultRetryPolicy.js +3 -4
- package/dist/react-native/retry/defaultRetryPolicy.js.map +1 -1
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts +3 -2
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.d.ts.map +1 -1
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js +13 -5
- package/dist/react-native/retry/endpointDiscoveryRetryPolicy.js.map +1 -1
- package/dist/react-native/retry/retryUtility.d.ts.map +1 -1
- package/dist/react-native/retry/retryUtility.js +3 -2
- package/dist/react-native/retry/retryUtility.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OperationType, ResourceType } from "../common/index.js";
|
|
1
2
|
import { isReadRequest } from "../common/helper.js";
|
|
2
3
|
/**
|
|
3
4
|
* This class implements the retry policy for endpoint discovery.
|
|
@@ -5,6 +6,7 @@ import { isReadRequest } from "../common/helper.js";
|
|
|
5
6
|
*/
|
|
6
7
|
export class EndpointDiscoveryRetryPolicy {
|
|
7
8
|
globalEndpointManager;
|
|
9
|
+
resourceType;
|
|
8
10
|
operationType;
|
|
9
11
|
globalPartitionEndpointManager;
|
|
10
12
|
/** Current retry attempt count. */
|
|
@@ -18,8 +20,9 @@ export class EndpointDiscoveryRetryPolicy {
|
|
|
18
20
|
/**
|
|
19
21
|
* @param globalEndpointManager - The GlobalEndpointManager instance.
|
|
20
22
|
*/
|
|
21
|
-
constructor(globalEndpointManager, operationType, globalPartitionEndpointManager) {
|
|
23
|
+
constructor(globalEndpointManager, resourceType, operationType, globalPartitionEndpointManager) {
|
|
22
24
|
this.globalEndpointManager = globalEndpointManager;
|
|
25
|
+
this.resourceType = resourceType;
|
|
23
26
|
this.operationType = operationType;
|
|
24
27
|
this.globalPartitionEndpointManager = globalPartitionEndpointManager;
|
|
25
28
|
this.maxTries = EndpointDiscoveryRetryPolicy.maxTries;
|
|
@@ -50,16 +53,21 @@ export class EndpointDiscoveryRetryPolicy {
|
|
|
50
53
|
return false;
|
|
51
54
|
}
|
|
52
55
|
this.currentRetryAttemptCount++;
|
|
56
|
+
retryContext.retryCount = this.currentRetryAttemptCount;
|
|
57
|
+
retryContext.clearSessionTokenNotAvailable = false;
|
|
58
|
+
retryContext.retryRequestOnPreferredLocations = false;
|
|
59
|
+
diagnosticNode.addData({ successfulRetryPolicy: "endpointDiscovery" });
|
|
60
|
+
// check if this is a readDatabaseAccount call
|
|
61
|
+
// If yes, then simply return true (avoid recursive call triggered for readDatabaseAccount)
|
|
62
|
+
if (this.resourceType === ResourceType.none && this.operationType === OperationType.Read) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
53
65
|
if (isReadRequest(this.operationType)) {
|
|
54
66
|
await this.globalEndpointManager.markCurrentLocationUnavailableForRead(diagnosticNode, locationEndpoint);
|
|
55
67
|
}
|
|
56
68
|
else {
|
|
57
69
|
await this.globalEndpointManager.markCurrentLocationUnavailableForWrite(diagnosticNode, locationEndpoint);
|
|
58
70
|
}
|
|
59
|
-
retryContext.retryCount = this.currentRetryAttemptCount;
|
|
60
|
-
retryContext.clearSessionTokenNotAvailable = false;
|
|
61
|
-
retryContext.retryRequestOnPreferredLocations = false;
|
|
62
|
-
diagnosticNode.addData({ successfulRetryPolicy: "endpointDiscovery" });
|
|
63
71
|
return true;
|
|
64
72
|
}
|
|
65
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpointDiscoveryRetryPolicy.js","sourceRoot":"","sources":["../../../src/retry/endpointDiscoveryRetryPolicy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"endpointDiscoveryRetryPolicy.js","sourceRoot":"","sources":["../../../src/retry/endpointDiscoveryRetryPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAOpD;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IAe7B;IACA;IACA;IACA;IAjBV,mCAAmC;IAC5B,wBAAwB,CAAS;IACxC,sCAAsC;IAC/B,cAAc,CAAS;IAE9B,+CAA+C;IACvC,QAAQ,CAAS;IACjB,MAAM,CAAU,QAAQ,GAAG,GAAG,CAAC,CAAC,kBAAkB;IAClD,MAAM,CAAU,cAAc,GAAG,IAAI,CAAC;IAE9C;;OAEG;IACH,YACU,qBAA4C,EAC5C,YAA0B,EAC1B,aAA4B,EAC5B,8BAA+D;QAH/D,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,iBAAY,GAAZ,YAAY,CAAc;QAC1B,kBAAa,GAAb,aAAa,CAAe;QAC5B,mCAA8B,GAA9B,8BAA8B,CAA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,KAAK,aAAa,CAAC,IAAI,EAAE,CAAC;YACzF,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,CAAC,qBAAqB,CAAC,qCAAqC,CACpE,cAAc,EACd,gBAAgB,CACjB,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,qBAAqB,CAAC,sCAAsC,CACrE,cAAc,EACd,gBAAgB,CACjB,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { OperationType, ResourceType } from \"../common/index.js\";\nimport { isReadRequest } from \"../common/helper.js\";\nimport type { GlobalEndpointManager } from \"../globalEndpointManager.js\";\nimport type { ErrorResponse, RequestContext } from \"../request/index.js\";\nimport type { RetryContext } from \"./RetryContext.js\";\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\nimport { GlobalPartitionEndpointManager } from \"../globalPartitionEndpointManager.js\";\n\n/**\n * This class implements the retry policy for endpoint discovery.\n * @hidden\n */\nexport class EndpointDiscoveryRetryPolicy implements RetryPolicy {\n /** Current retry attempt count. */\n public currentRetryAttemptCount: number;\n /** Retry interval in milliseconds. */\n public retryAfterInMs: number;\n\n /** Max number of retry attempts to perform. */\n private maxTries: number;\n private static readonly maxTries = 120; // TODO: Constant?\n private static readonly retryAfterInMs = 1000;\n\n /**\n * @param globalEndpointManager - The GlobalEndpointManager instance.\n */\n constructor(\n private globalEndpointManager: GlobalEndpointManager,\n private resourceType: ResourceType,\n private operationType: OperationType,\n private globalPartitionEndpointManager?: GlobalPartitionEndpointManager,\n ) {\n this.maxTries = EndpointDiscoveryRetryPolicy.maxTries;\n this.currentRetryAttemptCount = 0;\n this.retryAfterInMs = EndpointDiscoveryRetryPolicy.retryAfterInMs;\n }\n\n /**\n * Determines whether the request should be retried or not.\n * @param err - Error returned by the request.\n */\n public async shouldRetry(\n err: ErrorResponse,\n diagnosticNode: DiagnosticNodeInternal,\n retryContext?: RetryContext,\n locationEndpoint?: string,\n requestContext?: RequestContext,\n ): Promise<boolean | [boolean, string]> {\n if (!err) {\n return false;\n }\n\n if (!retryContext || !locationEndpoint) {\n return false;\n }\n\n if (!this.globalEndpointManager.enableEndpointDiscovery) {\n return false;\n }\n\n if (this.globalPartitionEndpointManager) {\n const didFailover = await this.globalPartitionEndpointManager.tryPartitionLevelFailover(\n requestContext,\n diagnosticNode,\n );\n if (didFailover) {\n return true;\n }\n }\n\n if (this.currentRetryAttemptCount >= this.maxTries) {\n return false;\n }\n\n this.currentRetryAttemptCount++;\n retryContext.retryCount = this.currentRetryAttemptCount;\n retryContext.clearSessionTokenNotAvailable = false;\n retryContext.retryRequestOnPreferredLocations = false;\n diagnosticNode.addData({ successfulRetryPolicy: \"endpointDiscovery\" });\n\n // check if this is a readDatabaseAccount call\n // If yes, then simply return true (avoid recursive call triggered for readDatabaseAccount)\n if (this.resourceType === ResourceType.none && this.operationType === OperationType.Read) {\n return true;\n }\n\n if (isReadRequest(this.operationType)) {\n await this.globalEndpointManager.markCurrentLocationUnavailableForRead(\n diagnosticNode,\n locationEndpoint,\n );\n } else {\n await this.globalEndpointManager.markCurrentLocationUnavailableForWrite(\n diagnosticNode,\n locationEndpoint,\n );\n }\n return true;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryUtility.d.ts","sourceRoot":"","sources":["../../../src/retry/retryUtility.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAEvF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAInE,OAAO,EAAE,kBAAkB,EAAE,MAAM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,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAE7E;;GAEG;AACH,UAAU,WAAW;IACnB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,cAAc,EAAE,sBAAsB,CAAC;IACvC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,cAAc,EAAE,cAAc,CAAC;IAC/B,cAAc,EAAE,CACd,cAAc,EAAE,sBAAsB,EACtC,cAAc,EAAE,cAAc,KAC3B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,UAAU,aAAa;IACrB,4BAA4B,EAAE,4BAA4B,CAAC;IAC3D,2BAA2B,EAAE,2BAA2B,CAAC;IACzD,sBAAsB,EAAE,kBAAkB,CAAC;IAC3C,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,0BAA0B,EAAE,0BAA0B,CAAC;CACxD;AAED;;GAEG;AACH,wBAAsB,OAAO,CAAC,EAC5B,cAAc,EACd,YAAgC,EAChC,aAAa,EACb,cAAc,EACd,cAAc,GACf,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAoJtC"}
|
|
@@ -21,7 +21,7 @@ export async function execute({ diagnosticNode, retryContext = { retryCount: 0 }
|
|
|
21
21
|
localDiagnosticNode.addData({ requestAttempNumber: retryContext.retryCount });
|
|
22
22
|
if (!retryPolicies) {
|
|
23
23
|
retryPolicies = {
|
|
24
|
-
endpointDiscoveryRetryPolicy: new EndpointDiscoveryRetryPolicy(requestContext.globalEndpointManager, requestContext.operationType, requestContext.globalPartitionEndpointManager),
|
|
24
|
+
endpointDiscoveryRetryPolicy: new EndpointDiscoveryRetryPolicy(requestContext.globalEndpointManager, requestContext.resourceType, requestContext.operationType, requestContext.globalPartitionEndpointManager),
|
|
25
25
|
resourceThrottleRetryPolicy: new ResourceThrottleRetryPolicy(requestContext.connectionPolicy.retryOptions ?? {}),
|
|
26
26
|
sessionReadRetryPolicy: new SessionRetryPolicy(requestContext.globalEndpointManager, requestContext.resourceType, requestContext.operationType, requestContext.connectionPolicy),
|
|
27
27
|
defaultRetryPolicy: new DefaultRetryPolicy(requestContext.operationType),
|
|
@@ -65,7 +65,8 @@ export async function execute({ diagnosticNode, retryContext = { retryCount: 0 }
|
|
|
65
65
|
if (correlatedActivityId) {
|
|
66
66
|
headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;
|
|
67
67
|
}
|
|
68
|
-
if (err.code ===
|
|
68
|
+
if (err.code === StatusCodes.ENOTFOUND ||
|
|
69
|
+
err.code === "REQUEST_SEND_ERROR" ||
|
|
69
70
|
(err.code === StatusCodes.Forbidden &&
|
|
70
71
|
(err.substatus === SubStatusCodes.DatabaseAccountNotFound ||
|
|
71
72
|
err.substatus === SubStatusCodes.WriteForbidden))) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryUtility.js","sourceRoot":"","sources":["../../../src/retry/retryUtility.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAG9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,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AO,CAAC;oBACb,cAAc;oBACd,cAAc;oBACd,cAAc;oBACd,YAAY;oBACZ,aAAa;iBACd,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,EACD,cAAc,EACd,kBAAkB,CAAC,YAAY,CAChC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,cAA8B;IACnD,OAAO,CACL,cAAc,CAAC,aAAa,KAAK,OAAO;QACxC,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { Constants } from \"../common/constants.js\";\nimport { sleep } from \"../common/helper.js\";\nimport { StatusCodes, SubStatusCodes } from \"../common/statusCodes.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { DiagnosticNodeType } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { Response } from \"../request/index.js\";\nimport type { RequestContext } from \"../request/RequestContext.js\";\nimport { TimeoutErrorCode } from \"../request/TimeoutError.js\";\nimport { addDiagnosticChild } from \"../utils/diagnostics.js\";\nimport { getCurrentTimestampInMs } from \"../utils/time.js\";\nimport { DefaultRetryPolicy } from \"./defaultRetryPolicy.js\";\nimport { EndpointDiscoveryRetryPolicy } from \"./endpointDiscoveryRetryPolicy.js\";\nimport { ResourceThrottleRetryPolicy } from \"./resourceThrottleRetryPolicy.js\";\nimport type { RetryContext } from \"./RetryContext.js\";\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\nimport { SessionRetryPolicy } from \"./sessionRetryPolicy.js\";\nimport { TimeoutFailoverRetryPolicy } from \"./timeoutFailoverRetryPolicy.js\";\n\n/**\n * @hidden\n */\ninterface ExecuteArgs {\n retryContext?: RetryContext;\n diagnosticNode: DiagnosticNodeInternal;\n retryPolicies?: RetryPolicies;\n requestContext: RequestContext;\n executeRequest: (\n diagnosticNode: DiagnosticNodeInternal,\n requestContext: RequestContext,\n ) => Promise<Response<any>>;\n}\n\n/**\n * @hidden\n */\ninterface RetryPolicies {\n endpointDiscoveryRetryPolicy: EndpointDiscoveryRetryPolicy;\n resourceThrottleRetryPolicy: ResourceThrottleRetryPolicy;\n sessionReadRetryPolicy: SessionRetryPolicy;\n defaultRetryPolicy: DefaultRetryPolicy;\n timeoutFailoverRetryPolicy: TimeoutFailoverRetryPolicy;\n}\n\n/**\n * @hidden\n */\nexport async function execute({\n diagnosticNode,\n retryContext = { retryCount: 0 },\n retryPolicies,\n requestContext,\n executeRequest,\n}: ExecuteArgs): Promise<Response<any>> {\n // TODO: any response\n return addDiagnosticChild(\n async (localDiagnosticNode: DiagnosticNodeInternal) => {\n localDiagnosticNode.addData({ requestAttempNumber: retryContext.retryCount });\n if (!retryPolicies) {\n retryPolicies = {\n endpointDiscoveryRetryPolicy: new EndpointDiscoveryRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.operationType,\n requestContext.globalPartitionEndpointManager,\n ),\n resourceThrottleRetryPolicy: new ResourceThrottleRetryPolicy(\n requestContext.connectionPolicy.retryOptions ?? {},\n ),\n sessionReadRetryPolicy: new SessionRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.resourceType,\n requestContext.operationType,\n requestContext.connectionPolicy,\n ),\n defaultRetryPolicy: new DefaultRetryPolicy(requestContext.operationType),\n timeoutFailoverRetryPolicy: new TimeoutFailoverRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.headers,\n requestContext.method,\n requestContext.resourceType,\n requestContext.operationType,\n requestContext.connectionPolicy.enableEndpointDiscovery,\n requestContext.connectionPolicy.enablePartitionLevelFailover,\n requestContext.globalPartitionEndpointManager,\n ),\n };\n }\n if (retryContext && retryContext.clearSessionTokenNotAvailable) {\n requestContext.client.clearSessionToken(requestContext.path);\n delete requestContext.headers[\"x-ms-session-token\"];\n }\n if (retryContext && retryContext.retryLocationServerIndex) {\n requestContext.endpoint = await requestContext.globalEndpointManager.resolveServiceEndpoint(\n localDiagnosticNode,\n requestContext.resourceType,\n requestContext.operationType,\n retryContext.retryLocationServerIndex,\n );\n } else {\n requestContext.endpoint = await requestContext.globalEndpointManager.resolveServiceEndpoint(\n localDiagnosticNode,\n requestContext.resourceType,\n requestContext.operationType,\n );\n }\n const startTimeUTCInMs = getCurrentTimestampInMs();\n const correlatedActivityId =\n requestContext.headers[Constants.HttpHeaders.CorrelatedActivityId];\n\n if (requestContext.globalPartitionEndpointManager) {\n // Try partition level location override\n // This is used to override the partition level location for the request\n // if there has been a partition level failover\n requestContext =\n await requestContext.globalPartitionEndpointManager.tryAddPartitionLevelLocationOverride(\n requestContext,\n localDiagnosticNode,\n );\n }\n\n try {\n const response = await executeRequest(localDiagnosticNode, requestContext);\n response.headers[Constants.ThrottleRetryCount] =\n retryPolicies.resourceThrottleRetryPolicy.currentRetryAttemptCount;\n response.headers[Constants.ThrottleRetryWaitTimeInMs] =\n retryPolicies.resourceThrottleRetryPolicy.cummulativeWaitTimeinMs;\n if (correlatedActivityId) {\n response.headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;\n }\n return response;\n } catch (err: any) {\n // TODO: any error\n let retryPolicy: RetryPolicy = null;\n const headers = err.headers || {};\n if (correlatedActivityId) {\n headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;\n }\n\n if (\n err.code === \"REQUEST_SEND_ERROR\" ||\n (err.code === StatusCodes.Forbidden &&\n (err.substatus === SubStatusCodes.DatabaseAccountNotFound ||\n err.substatus === SubStatusCodes.WriteForbidden))\n ) {\n retryPolicy = retryPolicies.endpointDiscoveryRetryPolicy;\n } else if (err.code === StatusCodes.TooManyRequests && !isBulkRequest(requestContext)) {\n retryPolicy = retryPolicies.resourceThrottleRetryPolicy;\n } else if (\n err.code === StatusCodes.NotFound &&\n err.substatus === SubStatusCodes.ReadSessionNotAvailable\n ) {\n retryPolicy = retryPolicies.sessionReadRetryPolicy;\n } else if (err.code === StatusCodes.ServiceUnavailable || err.code === TimeoutErrorCode) {\n retryPolicy = retryPolicies.timeoutFailoverRetryPolicy;\n } else {\n retryPolicy = retryPolicies.defaultRetryPolicy;\n }\n const results = await retryPolicy.shouldRetry(\n err,\n localDiagnosticNode,\n retryContext,\n requestContext.endpoint,\n requestContext,\n );\n if (!results) {\n headers[Constants.ThrottleRetryCount] =\n retryPolicies.resourceThrottleRetryPolicy.currentRetryAttemptCount;\n headers[Constants.ThrottleRetryWaitTimeInMs] =\n retryPolicies.resourceThrottleRetryPolicy.cummulativeWaitTimeinMs;\n err.headers = { ...err.headers, ...headers };\n throw err;\n } else {\n requestContext.retryCount++;\n const newUrl = (results as any)[1]; // TODO: any hack\n if (newUrl !== undefined) {\n requestContext.endpoint = newUrl;\n }\n localDiagnosticNode.recordFailedNetworkCall(\n startTimeUTCInMs,\n requestContext,\n retryContext.retryCount,\n err.code,\n err.subsstatusCode,\n headers,\n );\n await sleep(retryPolicy.retryAfterInMs);\n return execute({\n diagnosticNode,\n executeRequest,\n requestContext,\n retryContext,\n retryPolicies,\n });\n }\n }\n },\n diagnosticNode,\n DiagnosticNodeType.HTTP_REQUEST,\n );\n}\n\n/**\n * @hidden\n */\nfunction isBulkRequest(requestContext: RequestContext): boolean {\n return (\n requestContext.operationType === \"batch\" &&\n !requestContext.headers[Constants.HttpHeaders.IsBatchAtomic]\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"retryUtility.js","sourceRoot":"","sources":["../../../src/retry/retryUtility.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAG9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,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ACR,GAAG,CAAC,cAAc,EAClB,OAAO,CACR,CAAC;gBACF,MAAM,KAAK,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;gBACxC,OAAO,OAAO,CAAC;oBACb,cAAc;oBACd,cAAc;oBACd,cAAc;oBACd,YAAY;oBACZ,aAAa;iBACd,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,EACD,cAAc,EACd,kBAAkB,CAAC,YAAY,CAChC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,cAA8B;IACnD,OAAO,CACL,cAAc,CAAC,aAAa,KAAK,OAAO;QACxC,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { Constants } from \"../common/constants.js\";\nimport { sleep } from \"../common/helper.js\";\nimport { StatusCodes, SubStatusCodes } from \"../common/statusCodes.js\";\nimport type { DiagnosticNodeInternal } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport { DiagnosticNodeType } from \"../diagnostics/DiagnosticNodeInternal.js\";\nimport type { Response } from \"../request/index.js\";\nimport type { RequestContext } from \"../request/RequestContext.js\";\nimport { TimeoutErrorCode } from \"../request/TimeoutError.js\";\nimport { addDiagnosticChild } from \"../utils/diagnostics.js\";\nimport { getCurrentTimestampInMs } from \"../utils/time.js\";\nimport { DefaultRetryPolicy } from \"./defaultRetryPolicy.js\";\nimport { EndpointDiscoveryRetryPolicy } from \"./endpointDiscoveryRetryPolicy.js\";\nimport { ResourceThrottleRetryPolicy } from \"./resourceThrottleRetryPolicy.js\";\nimport type { RetryContext } from \"./RetryContext.js\";\nimport type { RetryPolicy } from \"./RetryPolicy.js\";\nimport { SessionRetryPolicy } from \"./sessionRetryPolicy.js\";\nimport { TimeoutFailoverRetryPolicy } from \"./timeoutFailoverRetryPolicy.js\";\n\n/**\n * @hidden\n */\ninterface ExecuteArgs {\n retryContext?: RetryContext;\n diagnosticNode: DiagnosticNodeInternal;\n retryPolicies?: RetryPolicies;\n requestContext: RequestContext;\n executeRequest: (\n diagnosticNode: DiagnosticNodeInternal,\n requestContext: RequestContext,\n ) => Promise<Response<any>>;\n}\n\n/**\n * @hidden\n */\ninterface RetryPolicies {\n endpointDiscoveryRetryPolicy: EndpointDiscoveryRetryPolicy;\n resourceThrottleRetryPolicy: ResourceThrottleRetryPolicy;\n sessionReadRetryPolicy: SessionRetryPolicy;\n defaultRetryPolicy: DefaultRetryPolicy;\n timeoutFailoverRetryPolicy: TimeoutFailoverRetryPolicy;\n}\n\n/**\n * @hidden\n */\nexport async function execute({\n diagnosticNode,\n retryContext = { retryCount: 0 },\n retryPolicies,\n requestContext,\n executeRequest,\n}: ExecuteArgs): Promise<Response<any>> {\n // TODO: any response\n return addDiagnosticChild(\n async (localDiagnosticNode: DiagnosticNodeInternal) => {\n localDiagnosticNode.addData({ requestAttempNumber: retryContext.retryCount });\n if (!retryPolicies) {\n retryPolicies = {\n endpointDiscoveryRetryPolicy: new EndpointDiscoveryRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.resourceType,\n requestContext.operationType,\n requestContext.globalPartitionEndpointManager,\n ),\n resourceThrottleRetryPolicy: new ResourceThrottleRetryPolicy(\n requestContext.connectionPolicy.retryOptions ?? {},\n ),\n sessionReadRetryPolicy: new SessionRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.resourceType,\n requestContext.operationType,\n requestContext.connectionPolicy,\n ),\n defaultRetryPolicy: new DefaultRetryPolicy(requestContext.operationType),\n timeoutFailoverRetryPolicy: new TimeoutFailoverRetryPolicy(\n requestContext.globalEndpointManager,\n requestContext.headers,\n requestContext.method,\n requestContext.resourceType,\n requestContext.operationType,\n requestContext.connectionPolicy.enableEndpointDiscovery,\n requestContext.connectionPolicy.enablePartitionLevelFailover,\n requestContext.globalPartitionEndpointManager,\n ),\n };\n }\n if (retryContext && retryContext.clearSessionTokenNotAvailable) {\n requestContext.client.clearSessionToken(requestContext.path);\n delete requestContext.headers[\"x-ms-session-token\"];\n }\n if (retryContext && retryContext.retryLocationServerIndex) {\n requestContext.endpoint = await requestContext.globalEndpointManager.resolveServiceEndpoint(\n localDiagnosticNode,\n requestContext.resourceType,\n requestContext.operationType,\n retryContext.retryLocationServerIndex,\n );\n } else {\n requestContext.endpoint = await requestContext.globalEndpointManager.resolveServiceEndpoint(\n localDiagnosticNode,\n requestContext.resourceType,\n requestContext.operationType,\n );\n }\n const startTimeUTCInMs = getCurrentTimestampInMs();\n const correlatedActivityId =\n requestContext.headers[Constants.HttpHeaders.CorrelatedActivityId];\n\n if (requestContext.globalPartitionEndpointManager) {\n // Try partition level location override\n // This is used to override the partition level location for the request\n // if there has been a partition level failover\n requestContext =\n await requestContext.globalPartitionEndpointManager.tryAddPartitionLevelLocationOverride(\n requestContext,\n localDiagnosticNode,\n );\n }\n\n try {\n const response = await executeRequest(localDiagnosticNode, requestContext);\n response.headers[Constants.ThrottleRetryCount] =\n retryPolicies.resourceThrottleRetryPolicy.currentRetryAttemptCount;\n response.headers[Constants.ThrottleRetryWaitTimeInMs] =\n retryPolicies.resourceThrottleRetryPolicy.cummulativeWaitTimeinMs;\n if (correlatedActivityId) {\n response.headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;\n }\n return response;\n } catch (err: any) {\n // TODO: any error\n let retryPolicy: RetryPolicy = null;\n const headers = err.headers || {};\n if (correlatedActivityId) {\n headers[Constants.HttpHeaders.CorrelatedActivityId] = correlatedActivityId;\n }\n\n if (\n err.code === StatusCodes.ENOTFOUND ||\n err.code === \"REQUEST_SEND_ERROR\" ||\n (err.code === StatusCodes.Forbidden &&\n (err.substatus === SubStatusCodes.DatabaseAccountNotFound ||\n err.substatus === SubStatusCodes.WriteForbidden))\n ) {\n retryPolicy = retryPolicies.endpointDiscoveryRetryPolicy;\n } else if (err.code === StatusCodes.TooManyRequests && !isBulkRequest(requestContext)) {\n retryPolicy = retryPolicies.resourceThrottleRetryPolicy;\n } else if (\n err.code === StatusCodes.NotFound &&\n err.substatus === SubStatusCodes.ReadSessionNotAvailable\n ) {\n retryPolicy = retryPolicies.sessionReadRetryPolicy;\n } else if (err.code === StatusCodes.ServiceUnavailable || err.code === TimeoutErrorCode) {\n retryPolicy = retryPolicies.timeoutFailoverRetryPolicy;\n } else {\n retryPolicy = retryPolicies.defaultRetryPolicy;\n }\n const results = await retryPolicy.shouldRetry(\n err,\n localDiagnosticNode,\n retryContext,\n requestContext.endpoint,\n requestContext,\n );\n if (!results) {\n headers[Constants.ThrottleRetryCount] =\n retryPolicies.resourceThrottleRetryPolicy.currentRetryAttemptCount;\n headers[Constants.ThrottleRetryWaitTimeInMs] =\n retryPolicies.resourceThrottleRetryPolicy.cummulativeWaitTimeinMs;\n err.headers = { ...err.headers, ...headers };\n throw err;\n } else {\n requestContext.retryCount++;\n const newUrl = (results as any)[1]; // TODO: any hack\n if (newUrl !== undefined) {\n requestContext.endpoint = newUrl;\n }\n localDiagnosticNode.recordFailedNetworkCall(\n startTimeUTCInMs,\n requestContext,\n retryContext.retryCount,\n err.code,\n err.subsstatusCode,\n headers,\n );\n await sleep(retryPolicy.retryAfterInMs);\n return execute({\n diagnosticNode,\n executeRequest,\n requestContext,\n retryContext,\n retryPolicies,\n });\n }\n }\n },\n diagnosticNode,\n DiagnosticNodeType.HTTP_REQUEST,\n );\n}\n\n/**\n * @hidden\n */\nfunction isBulkRequest(requestContext: RequestContext): boolean {\n return (\n requestContext.operationType === \"batch\" &&\n !requestContext.headers[Constants.HttpHeaders.IsBatchAtomic]\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/cosmos",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"description": "Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"keywords": [
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"playwright": "^1.50.1",
|
|
75
75
|
"typescript": "~5.8.3",
|
|
76
76
|
"vitest": "^3.2.3",
|
|
77
|
-
"@azure/dev-tool": "^1.0.0",
|
|
78
77
|
"@azure-tools/test-utils-vitest": "^2.0.1",
|
|
78
|
+
"@azure/dev-tool": "^1.0.0",
|
|
79
79
|
"@azure/eslint-plugin-azure-sdk": "^3.0.0"
|
|
80
80
|
},
|
|
81
81
|
"//sampleConfiguration": {
|