@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
99 lines (98 loc) • 3.69 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var endpointDiscoveryRetryPolicy_exports = {};
__export(endpointDiscoveryRetryPolicy_exports, {
EndpointDiscoveryRetryPolicy: () => EndpointDiscoveryRetryPolicy
});
module.exports = __toCommonJS(endpointDiscoveryRetryPolicy_exports);
var import_common = require("../common/index.js");
var import_helper = require("../common/helper.js");
class EndpointDiscoveryRetryPolicy {
/**
* @param globalEndpointManager - The GlobalEndpointManager instance.
*/
constructor(globalEndpointManager, resourceType, operationType, globalPartitionEndpointManager) {
this.globalEndpointManager = globalEndpointManager;
this.resourceType = resourceType;
this.operationType = operationType;
this.globalPartitionEndpointManager = globalPartitionEndpointManager;
this.maxTries = EndpointDiscoveryRetryPolicy.maxTries;
this.currentRetryAttemptCount = 0;
this.retryAfterInMs = EndpointDiscoveryRetryPolicy.retryAfterInMs;
}
/** Current retry attempt count. */
currentRetryAttemptCount;
/** Retry interval in milliseconds. */
retryAfterInMs;
/** Max number of retry attempts to perform. */
maxTries;
static maxTries = 120;
// TODO: Constant?
static retryAfterInMs = 1e3;
/**
* Determines whether the request should be retried or not.
* @param err - Error returned by the request.
*/
async shouldRetry(err, diagnosticNode, retryContext, locationEndpoint, requestContext) {
if (!err) {
return false;
}
if (!retryContext || !locationEndpoint) {
return false;
}
if (!this.globalEndpointManager.enableEndpointDiscovery) {
return false;
}
if (this.globalPartitionEndpointManager) {
const didFailover = await this.globalPartitionEndpointManager.tryPartitionLevelFailover(
requestContext,
diagnosticNode
);
if (didFailover) {
return true;
}
}
if (this.currentRetryAttemptCount >= this.maxTries) {
return false;
}
this.currentRetryAttemptCount++;
retryContext.retryCount = this.currentRetryAttemptCount;
retryContext.clearSessionTokenNotAvailable = false;
retryContext.retryRequestOnPreferredLocations = false;
diagnosticNode.addData({ successfulRetryPolicy: "endpointDiscovery" });
if (this.resourceType === import_common.ResourceType.none && this.operationType === import_common.OperationType.Read) {
return true;
}
if ((0, import_helper.isReadRequest)(this.operationType)) {
await this.globalEndpointManager.markCurrentLocationUnavailableForRead(
diagnosticNode,
locationEndpoint
);
} else {
await this.globalEndpointManager.markCurrentLocationUnavailableForWrite(
diagnosticNode,
locationEndpoint
);
}
return true;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
EndpointDiscoveryRetryPolicy
});