Skip to content

Commit

Permalink
fix: retry writes that fail with status code ABORTED (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored and schmidt-sebastian committed Jan 3, 2020
1 parent 191d3b8 commit 96f085f
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 141 deletions.
1 change: 1 addition & 0 deletions .nycrc
Expand Up @@ -12,6 +12,7 @@
"**/scripts",
"**/protos",
"**/test",
"**/*.d.ts",
".jsdoc.js",
"**/.jsdoc.js",
"karma.conf.js",
Expand Down
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -15,7 +15,9 @@ This is the Node.js Server SDK for [Google Cloud Firestore](https://firebase.goo

This Cloud Firestore Server SDK uses Google’s Cloud Identity and Access Management for authentication and should only be used in trusted environments. Your Cloud Identity credentials allow you bypass all access restrictions and provide read and write access to all data in your Cloud Firestore project.

Applications that use Google's Server SDKs should not be used in end-user environments, such as on phones or on publicly hosted websites. If you are developing a Web or Node.js application that accesses Cloud Firestore on behalf of end users, use the Firebase Client SDK.
The Cloud Firestore Server SDKs are designed to manage the full set of data in your Cloud Firestore project and work best with reliable network connectivity. Data operations performed via these SDKs directly access the Cloud Firestore backend and all document reads and writes are optimized for high throughput.

Applications that use Google's Server SDKs should not be used in end-user environments, such as on phones or on publicly hosted websites. If you are developing a Web or Node.js application that accesses Cloud Firestore on behalf of end users, use the firebase Client SDK.

**Note:** This Cloud Firestore Server SDK does not support Firestore databases created in [Datastore mode](https://cloud.google.com/datastore/docs/firestore-or-datastore#in_datastore_mode). To access these databases, use the [Datastore SDK](https://www.npmjs.com/package/@google-cloud/datastore).

Expand Down
14 changes: 7 additions & 7 deletions dev/protos/protos.json
Expand Up @@ -1139,13 +1139,6 @@
}
}
},
"Direction": {
"values": {
"DIRECTION_UNSPECIFIED": 0,
"ASCENDING": 1,
"DESCENDING": 2
}
},
"FieldReference": {
"fields": {
"fieldPath": {
Expand All @@ -1162,6 +1155,13 @@
"id": 2
}
}
},
"Direction": {
"values": {
"DIRECTION_UNSPECIFIED": 0,
"ASCENDING": 1,
"DESCENDING": 2
}
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions dev/src/v1/firestore_admin_client.ts
Expand Up @@ -278,6 +278,9 @@ export class FirestoreAdminClient {
for (const methodName of firestoreAdminStubMethods) {
const innerCallPromise = this.firestoreAdminStub.then(
stub => (...args: Array<{}>) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return stub[methodName].apply(stub, args);
},
(err: Error | null | undefined) => () => {
Expand All @@ -298,9 +301,6 @@ export class FirestoreAdminClient {
callOptions?: CallOptions,
callback?: APICallback
) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return apiCall(argument, callOptions, callback);
};
}
Expand Down Expand Up @@ -1270,7 +1270,7 @@ export class FirestoreAdminClient {
* @param {string} collection
* @returns {string} Resource name string.
*/
collectiongroupPath(project: string, database: string, collection: string) {
collectionGroupPath(project: string, database: string, collection: string) {
return this._pathTemplates.collectiongroupPathTemplate.render({
project,
database,
Expand Down
26 changes: 9 additions & 17 deletions dev/src/v1/firestore_client.ts
Expand Up @@ -37,20 +37,12 @@ const version = require('../../../package.json').version;
/**
* The Cloud Firestore service.
*
* This service exposes several types of comparable timestamps:
*
* * `create_time` - The time at which a document was created. Changes only
* when a document is deleted, then re-created. Increases in a strict
* monotonic fashion.
* * `update_time` - The time at which a document was last updated. Changes
* every time a document is modified. Does not change when a write results
* in no modifications. Increases in a strict monotonic fashion.
* * `read_time` - The time at which a particular state was observed. Used
* to denote a consistent snapshot of the database or the time at which a
* Document was observed to not exist.
* * `commit_time` - The time at which the writes in a transaction were
* committed. Any read with an equal or greater `read_time` is guaranteed
* to see the effects of the transaction.
* Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL
* document database that simplifies storing, syncing, and querying data for
* your mobile, web, and IoT apps at global scale. Its client libraries provide
* live synchronization and offline support, while its security features and
* integrations with Firebase and Google Cloud Platform (GCP) accelerate
* building truly serverless apps.
* @class
* @memberof v1
*/
Expand Down Expand Up @@ -225,6 +217,9 @@ export class FirestoreClient {
for (const methodName of firestoreStubMethods) {
const innerCallPromise = this.firestoreStub.then(
stub => (...args: Array<{}>) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return stub[methodName].apply(stub, args);
},
(err: Error | null | undefined) => () => {
Expand All @@ -245,9 +240,6 @@ export class FirestoreClient {
callOptions?: CallOptions,
callback?: APICallback
) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return apiCall(argument, callOptions, callback);
};
}
Expand Down
21 changes: 11 additions & 10 deletions dev/src/v1/firestore_client_config.json
Expand Up @@ -7,8 +7,9 @@
"DEADLINE_EXCEEDED",
"UNAVAILABLE"
],
"deadline_exceeded_internal_unavailable": [
"deadline_exceeded_aborted_internal_unavailable": [
"DEADLINE_EXCEEDED",
"ABORTED",
"INTERNAL",
"UNAVAILABLE"
]
Expand All @@ -27,12 +28,12 @@
"methods": {
"GetDocument": {
"timeout_millis": 60000,
"retry_codes_name": "deadline_exceeded_internal_unavailable",
"retry_codes_name": "deadline_exceeded_aborted_internal_unavailable",
"retry_params_name": "default"
},
"ListDocuments": {
"timeout_millis": 60000,
"retry_codes_name": "deadline_exceeded_internal_unavailable",
"retry_codes_name": "deadline_exceeded_aborted_internal_unavailable",
"retry_params_name": "default"
},
"CreateDocument": {
Expand All @@ -47,17 +48,17 @@
},
"DeleteDocument": {
"timeout_millis": 60000,
"retry_codes_name": "deadline_exceeded_internal_unavailable",
"retry_codes_name": "deadline_exceeded_aborted_internal_unavailable",
"retry_params_name": "default"
},
"BatchGetDocuments": {
"timeout_millis": 300000,
"retry_codes_name": "deadline_exceeded_internal_unavailable",
"retry_codes_name": "deadline_exceeded_aborted_internal_unavailable",
"retry_params_name": "default"
},
"BeginTransaction": {
"timeout_millis": 60000,
"retry_codes_name": "deadline_exceeded_internal_unavailable",
"retry_codes_name": "deadline_exceeded_aborted_internal_unavailable",
"retry_params_name": "default"
},
"Commit": {
Expand All @@ -67,12 +68,12 @@
},
"Rollback": {
"timeout_millis": 60000,
"retry_codes_name": "deadline_exceeded_internal_unavailable",
"retry_codes_name": "deadline_exceeded_aborted_internal_unavailable",
"retry_params_name": "default"
},
"RunQuery": {
"timeout_millis": 300000,
"retry_codes_name": "deadline_exceeded_internal_unavailable",
"retry_codes_name": "deadline_exceeded_aborted_internal_unavailable",
"retry_params_name": "default"
},
"Write": {
Expand All @@ -82,12 +83,12 @@
},
"Listen": {
"timeout_millis": 86400000,
"retry_codes_name": "deadline_exceeded_internal_unavailable",
"retry_codes_name": "deadline_exceeded_aborted_internal_unavailable",
"retry_params_name": "default"
},
"ListCollectionIds": {
"timeout_millis": 60000,
"retry_codes_name": "deadline_exceeded_internal_unavailable",
"retry_codes_name": "deadline_exceeded_aborted_internal_unavailable",
"retry_params_name": "default"
}
}
Expand Down
6 changes: 3 additions & 3 deletions dev/src/v1beta1/firestore_client.ts
Expand Up @@ -225,6 +225,9 @@ export class FirestoreClient {
for (const methodName of firestoreStubMethods) {
const innerCallPromise = this.firestoreStub.then(
stub => (...args: Array<{}>) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return stub[methodName].apply(stub, args);
},
(err: Error | null | undefined) => () => {
Expand All @@ -245,9 +248,6 @@ export class FirestoreClient {
callOptions?: CallOptions,
callback?: APICallback
) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return apiCall(argument, callOptions, callback);
};
}
Expand Down

0 comments on commit 96f085f

Please sign in to comment.