Skip to content

fix(firestore): retry idempotent commits on DEADLINE_EXCEEDED - #15010

Draft
MarkDuckworth wants to merge 1 commit into
mainfrom
feat/retry-idempotent-commits
Draft

MarkDuckworth wants to merge 1 commit into
mainfrom
feat/retry-idempotent-commits

Conversation

@MarkDuckworth

Copy link
Copy Markdown
Contributor

Summary

Automatically enables DEADLINE_EXCEEDED retries on non-transactional Commit requests when all write operations in the commit are idempotent.

Background

The generated GAPIC FirestoreStubSettings (retry_policy_0) only retries Commit RPCs on RESOURCE_EXHAUSTED and UNAVAILABLE because a CommitRequest proto can contain non-idempotent operations (such as FieldValue.increment() or create() with exists: false). However, most standalone writes (docRef.set(), docRef.set(..., SetOptions.merge()), docRef.update() without increment or updateTime preconditions, docRef.delete() without preconditions, and WriteBatches composed of those operations) are idempotent and safe to retry when an attempt times out with DEADLINE_EXCEEDED.

Changes

  • FieldValue: Added package-private abstract boolean isIdempotent() so all current and future FieldValue implementations explicitly declare idempotency (false for FieldValue.increment(), true for delete(), serverTimestamp(), arrayUnion(), arrayRemove(), minimum(), maximum()).
  • DocumentTransform: Tracks idempotency across top-level and nested field transforms.
  • UpdateBuilder:
    • Evaluates whether a non-transactional Commit batch is idempotent based on DocumentTransform.isIdempotent(), write preconditions (excluding exists: false, updateTime, and delete with exists: true), and a fail-closed FieldTransform check.
    • Passes GrpcCallContext with retryableCodes = [RESOURCE_EXHAUSTED, UNAVAILABLE, DEADLINE_EXCEEDED] for idempotent non-transactional commits.
  • WriteBatchTest: Added unit tests for idempotency classification across write/precondition/transform combinations and end-to-end gRPC retry verification on DEADLINE_EXCEEDED.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces idempotency tracking for Firestore write operations and document transforms to safely retry idempotent commits on DEADLINE_EXCEEDED. It defines which FieldValue operations are idempotent (such as server timestamps, deletes, array unions/removes, and min/max numeric transforms) and which are not (such as increments). UpdateBuilder uses this classification to determine if a write batch or commit request is fully idempotent, enabling retries on DEADLINE_EXCEEDED for non-transactional, idempotent commits. Comprehensive unit tests have been added to validate the idempotency classification and retry behavior. No review comments were provided, so there is no additional feedback to address.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant