Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable retries for RESOURCE_EXHAUSTED an simplify error codes #1070

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
danieljbruce marked this conversation as resolved.
Show resolved Hide resolved
emitters = [
((stream: Writable) => {
stream.emit('error', unretriableError);
Expand Down