Skip to content

Commit

Permalink
feat: enable retries for RESOURCE_EXHAUSTED an simplify error codes (#…
Browse files Browse the repository at this point in the history
…1070)

Unify retriable status codes for ReadRows and MutateRows to be DEADLINE_EXCEEDED -  RESOURCE_EXHAUSTED, ABORTED, UNAVAILABLE.
  • Loading branch information
igorbernstein2 authored Apr 13, 2022
1 parent ab0d52b commit 6832df7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ import {google} from '../protos/protos';
import {Duplex} from 'stream';

// See protos/google/rpc/code.proto
// (4=DEADLINE_EXCEEDED, 10=ABORTED, 14=UNAVAILABLE)
const RETRYABLE_STATUS_CODES = new Set([4, 10, 14]);
const IDEMPOTENT_RETRYABLE_STATUS_CODES = new Set([4, 14]);
// (4=DEADLINE_EXCEEDED, 8=RESOURCE_EXHAUSTED, 10=ABORTED, 14=UNAVAILABLE)
const RETRYABLE_STATUS_CODES = new Set([4, 8, 10, 14]);
// (1=CANCELLED)
const IGNORED_STATUS_CODES = new Set([1]);

Expand Down Expand Up @@ -1564,7 +1563,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
// If the error is empty but there are still outstanding mutations,
// it means that there are retryable errors in the mutate response
// even when the RPC succeeded
return !err || IDEMPOTENT_RETRYABLE_STATUS_CODES.has(err.code);
return !err || RETRYABLE_STATUS_CODES.has(err.code);
};

const onBatchResponse = (err: ServiceError | null) => {
Expand Down Expand Up @@ -1648,7 +1647,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
mutationErrorsByEntryIndex.delete(originalEntriesIndex);
return;
}
if (!IDEMPOTENT_RETRYABLE_STATUS_CODES.has(entry.status!.code!)) {
if (!RETRYABLE_STATUS_CODES.has(entry.status!.code!)) {
pendingEntryIndices.delete(originalEntriesIndex);
}
const errorDetails = entry.status;
Expand Down
10 changes: 5 additions & 5 deletions test/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2485,8 +2485,8 @@ describe('Bigtable/Table', () => {
{
index: 1,
status: {
code: 10,
message: 'ABORTED',
code: 3,
message: 'INVALID_ARGUMENT',
},
},
];
Expand Down Expand Up @@ -2652,14 +2652,14 @@ describe('Bigtable/Table', () => {
});

describe('rpc level retries', () => {
let emitters: EventEmitter[] | null; // = [((stream: Writable) => { stream.push([{ key: 'a' }]);
let emitters: EventEmitter[]; // = [((stream: Writable) => { stream.push([{ key: 'a' }]);
let requestArgs: RequestOptions[] = [];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let entryRequests: any;

beforeEach(() => {
emitters = null; // This needs to be assigned in each test case.
emitters = []; // This needs to be assigned in each test case.

requestArgs = [];
entryRequests = [];
Expand All @@ -2682,7 +2682,7 @@ describe('Bigtable/Table', () => {

it('should not retry unretriable errors', done => {
const unretriableError = new Error('not retryable') as ServiceError;
unretriableError.code = 10; // Aborted
unretriableError.code = 3; // INVALID_ARGUMENT
emitters = [
((stream: Writable) => {
stream.emit('error', unretriableError);
Expand Down

0 comments on commit 6832df7

Please sign in to comment.