[java-spanner] Provide a mutation count estimation and document how mutations are calculated
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with the requested MutationCountEstimator scope and the Spanner quotas and commit-statistics documentation, then review the linked google-cloud-go issue 1721. Compare the requested coverage for INSERT, UPDATE, INSERT_OR_UPDATE, REPLACE, and DELETE, including STORING and generated columns and the index write-only phase. Done requires a decided implementation or documentation scope with validation criteria.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
The https://docs.cloud.google.com/spanner/quotas only describes how secondary indexes affect mutation counts for delete operations. For inserts and updates, the docs state that "operations count with the multiplicity of the number of columns they affect" but do not describe how secondary indexes contribute to the count.
The full formula for inserts (number of columns + sum of columns across all secondary indexes) was only confirmed informally by Google's backend team in https://github.com/googleapis/google-cloud-go/issues/1721.
Additionally, when creating a new index on an existing table, we observe an immediate increase in mutation counts for writes to that table during the schema change (write-only phase), before the index is fully backfilled. This behavior and its impact on mutation budgets is not documented.
This forces teams to reverse-engineer mutation counting logic, which is fragile and breaks when the internal counting rules change.
Describe the solution you'd like
- A utility class in the Java client (e.g. MutationCountEstimator) that can calculate the expected mutation count for a given set of mutations before committing
OR - Complete documentation of how mutations are actually calculated for all operation types (INSERT, UPDATE, INSERT_OR_UPDATE, REPLACE, DELETE),
including:
- Indexes with STORING clauses
- Computed/generated columns
- The impact on mutation counts during index creation (write-only phase before backfill completes)
Ideally both :D
Describe alternatives you've considered
- Reverse-engineering the count from schema metadata and secondary index definitions. This is error-prone and has caused production incidents when our
calculation diverged from Spanner's actual count. - Committing a single row first, reading getMutationCount() from CommitResponse, then using that to size remaining batches.
- Using a limit well below 80,000 (e.g. 75,000) to absorb miscalculations.
Additional context
- https://cloud.google.com/blog/products/databases/cloud-spanner-doubles-the-number-of-updates-per-transaction — references mutation counting but does not cover the index impact.
- https://github.com/googleapis/google-cloud-go/issues/1721 — open since 2019, requesting programmatic mutation calculation. The formula was confirmed informally but never made it into the docs.
- The https://docs.cloud.google.com/spanner/docs/commit-statistics provides post-commit mutation counts but not pre-commit estimation.
- Dominant language
- Java
- Stars
- 2.1k
- Forks
- 1.2k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 192
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleapis/google-cloud-java
-
[java-core] Timestamp.of(java.sql.Timestamp) is one second late for a time less than a second before the epochPossibly taken @Vcode2407 claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
googleapis/google-cloud-java#14636 ·
Maintainers usually reply within 1 day
-
[java-firestore] UserDataConverter encodes a pre-epoch Date with negative nanos, so the write is refusedPossibly taken @wu-hui claimed this 23 days ago. Openpriority: p2 type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
googleapis/google-cloud-java#14635 · 1 assignee ·
Maintainers usually reply within 1 day
-
[java-firestore] UserDataConverter throws IndexOutOfBoundsException on an empty __binary__ valuePossibly taken @wu-hui claimed this 23 days ago. Openpriority: p2 type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
googleapis/google-cloud-java#14634 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
[java-firestore] CustomClassMapper.convertBigDecimal calls .abs() on Double, unintentionally flipping negative values to positiveMay be free again @wu-hui claimed this 45 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
googleapis/google-cloud-java#14533 · 1 assignee ·
Maintainers usually reply within 1 day
-
Github CI failing when trying to install xmllintPossibly taken @blakeli0 claimed this 81 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
googleapis/google-cloud-java#14132 · 1 comment ·
Maintainers usually reply within 1 day
All issues in googleapis/google-cloud-java
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 Under an hour Newbie friendliness 84/100
cpp-best-practices/project_validator#251 ·
Maintainers usually reply within 1 day
-
backend enhancement
Difficulty 2/5 Half a day Newbie friendliness 70/100
damodharg6/payledger#16 ·
-
[Bug]: An initiative list with no current entry logs an error on every changePossibly taken @dwizard0 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day