All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.config.retry.storage-default-eligibility-strategy.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultStorageEligibilityStrategy = void 0;
const constants_1 = require("@grpc/grpc-js/build/src/constants");
const retryableGrpcStatusCodes = [
    // including all the status codes for reference, but
    // commenting out the ones we don't want to retry on for now.
    // Status.OK,
    // Status.CANCELLED,
    // Status.UNKNOWN,
    // Status.INVALID_ARGUMENT,
    constants_1.Status.DEADLINE_EXCEEDED,
    // Status.NOT_FOUND,
    // Status.ALREADY_EXISTS,
    // Status.PERMISSION_DENIED,
    // Status.RESOURCE_EXHAUSTED,
    // Status.FAILED_PRECONDITION,
    // Status.ABORTED,
    // Status.OUT_OF_RANGE,
    // Status.UNIMPLEMENTED,
    constants_1.Status.INTERNAL,
    constants_1.Status.UNAVAILABLE,
    // Status.DATA_LOSS,
    // Status.UNAUTHENTICATED
];
const retryableRequestTypes = [
    '/store.Store/Put',
    '/store.Store/Get',
    '/store.Store/Delete',
];
class DefaultStorageEligibilityStrategy {
    constructor(loggerFactory) {
        this.logger = loggerFactory.getLogger(this);
    }
    isEligibleForRetry(props) {
        if (!retryableGrpcStatusCodes.includes(props.grpcStatus.code)) {
            this.logger.debug(`Response with status code ${props.grpcStatus.code} is not retryable.`);
            return false;
        }
        // If retry disposition metadata is available and the value is "retryable",
        // it is safe to retry regardless of idempotency.
        const retryMetadata = this.getRetryDispositionMetadata(props.grpcStatus.metadata);
        if (retryMetadata === 'retryable') {
            return true;
        }
        // Otherwise, if there is no retry metadata or the retry disposition is
        // "possibly_retryable", it is safe to retry only idempotent commands.
        if (!retryableRequestTypes.includes(props.grpcRequest.path)) {
            this.logger.debug(`Request with type ${props.grpcRequest.path} is not retryable.`);
            return false;
        }
        return true;
    }
    getRetryDispositionMetadata(metadata) {
        const retryMetadata = metadata.get('retry_disposition');
        if (retryMetadata.length === 1) {
            return retryMetadata[0].toString();
        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