Skip to content

Commit

Permalink
Have 'firebase firestore:delete' retry on bandwidth RESOURCE_EXHAUSTE…
Browse files Browse the repository at this point in the history
…D errors (#7863)

* Add retry mechanisms for when firestore deletes are failing due to bandwidth limits

* Alias Commit

* Run the formatter
  • Loading branch information
NickChittle authored Oct 22, 2024
1 parent 2559645 commit 5c53ccd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Add support for deploying new blocking triggers. (#6384)
- Have the firestore:delete command retry on bandwidth exceeded errors. (#7845)
18 changes: 18 additions & 0 deletions src/firestore/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,24 @@ export class FirestoreDelete {
this.setDeleteBatchSize(newBatchSize);
}

// Retry this batch
queue.unshift(...toDelete);
} else if (
e.status === 429 &&
this.deleteBatchSize >= 10 &&
e.message.includes("database has exceeded their maximum bandwidth")
) {
logger.debug("Database has exceeded maximum write bandwidth", e);
const newBatchSize = Math.floor(toDelete.length / 2);

if (newBatchSize < this.deleteBatchSize) {
utils.logLabeledWarning(
"firestore",
`delete rate exceeding maximum bandwidth, reducing batch size from ${this.deleteBatchSize} to ${newBatchSize}`,
);
this.setDeleteBatchSize(newBatchSize);
}

// Retry this batch
queue.unshift(...toDelete);
} else if (e.status >= 500 && e.status < 600) {
Expand Down
6 changes: 5 additions & 1 deletion src/gcp/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ export async function deleteDocuments(
});
const data = { writes };

const res = await apiClient.post<any, { writeResults: any[] }>(url, data);
const res = await apiClient.post<any, { writeResults: any[] }>(url, data, {
retries: 10,
retryCodes: [429, 409, 503],
retryMaxTimeout: 20 * 1000,
});
return res.body.writeResults.length;
}

Expand Down

0 comments on commit 5c53ccd

Please sign in to comment.