Skip to content

Commit

Permalink
fix: fix retry logic in mutate and read (#980)
Browse files Browse the repository at this point in the history
* fix: fix retry logic in mutate

* fix format

* add todos

* fix the same issue in read
  • Loading branch information
mutianf authored Jan 12, 2022
1 parent b058d3b commit bfa84e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,6 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);

activeRequestStream = requestStream!;

requestStream!.on('request', () => numRequestsMade++);

const toRowStream = new Transform({
transform: (rowData, _, next) => {
if (
Expand Down Expand Up @@ -945,6 +943,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
}
});
rowStream.pipe(userStream);
numRequestsMade++;
};

makeNewRequest();
Expand Down Expand Up @@ -1502,6 +1501,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
const onBatchResponse = (
err: ServiceError | PartialFailureError | null
) => {
// TODO: enable retries when the entire RPC fails
if (err) {
// The error happened before a request was even made, don't retry.
callback(err);
Expand Down Expand Up @@ -1545,8 +1545,9 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
gaxOpts: options.gaxOptions,
retryOpts,
})
.on('request', () => numRequestsMade++)
.on('error', (err: ServiceError) => {
// TODO: this check doesn't actually do anything, onBatchResponse
// currently doesn't retry RPC errors, only entry failures
if (numRequestsMade === 0) {
callback(err); // Likely a "projectId not detected" error.
return;
Expand Down Expand Up @@ -1575,6 +1576,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
});
})
.on('end', onBatchResponse);
numRequestsMade++;
};

makeNextBatchRequest();
Expand Down
4 changes: 0 additions & 4 deletions test/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,6 @@ describe('Bigtable/Table', () => {
(stream as any).abort = () => {};

setImmediate(() => {
stream.emit('request');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(emitters!.shift() as any)(stream);
});
Expand Down Expand Up @@ -2372,7 +2371,6 @@ describe('Bigtable/Table', () => {
});

setImmediate(() => {
stream.emit('request');
stream.emit('error', error);
});

Expand Down Expand Up @@ -2471,7 +2469,6 @@ describe('Bigtable/Table', () => {
});

setImmediate(() => {
stream.emit('request');
stream.end({entries: fakeStatuses});
});

Expand Down Expand Up @@ -2526,7 +2523,6 @@ describe('Bigtable/Table', () => {
});

setImmediate(() => {
stream.emit('request');
stream.end({entries: fakeStatuses.shift()});
});

Expand Down

0 comments on commit bfa84e1

Please sign in to comment.