Skip to content

Conversation

@sm745052
Copy link
Contributor

@sm745052 sm745052 commented Dec 26, 2025

fixes b/460679219

Context:

  • if the AssignShardIdFn cannot provide a shardId, then we consider it to be permanent error.
  • to get the shardId we need the entire row (in multi-shard migration). However, in case of a DELETE, the ChangeStream doesnot provide the entire row. this requires a read from spanner.
  • if we cannot read from spanner, we set the shardId as NULL which causes the template to consider it as a permanent error.

Solution:
Using a sentinel shard_id to identify that it was a retryable error or severe error in SourceWriterFn.

Changes:

  • added constant shard ids to represent permanent and retryable errors.
  • Added a spanner to sourcedb exception classifier to use it in assignshardidfn and sourcewriterfn

Extra:

  • Chore: removed an unused import on AssignShardIdFn

@sm745052 sm745052 requested a review from a team as a code owner December 26, 2025 09:31
@gemini-code-assist
Copy link

Summary of Changes

Hello @sm745052, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the reverse replication pipeline by refining error handling during shard ID assignment. Previously, failures to determine a shard ID were uniformly treated as permanent errors. The changes introduce a distinction between retryable and severe errors, allowing the system to appropriately tag and potentially reprocess records affected by transient issues, thereby improving the overall resilience of the data flow.

Highlights

  • Improved Error Handling for Shard ID Assignment: Introduced a mechanism to differentiate between retryable and severe errors when the AssignShardIdFn fails to determine a shard ID, particularly during DELETE operations where a Spanner read is required.
  • Sentinel Shard IDs: Defined two new constants, RETRYABLE_SENTINEL_SHARD_ID and SEVERE_SENTINEL_SHARD_ID, to act as flags for different error types within the data records.
  • Updated Shard Assignment Logic: The AssignShardIdFn now checks if a SpannerException is retryable. If so, it assigns the RETRYABLE_SENTINEL_SHARD_ID; otherwise, it assigns the SEVERE_SENTINEL_SHARD_ID.
  • Refined Error Tagging in SourceWriterFn: The SourceWriterFn has been updated to process records with RETRYABLE_SENTINEL_SHARD_ID by outputting them to a RETRYABLE_ERROR_TAG, and records with SEVERE_SENTINEL_SHARD_ID to a PERMANENT_ERROR_TAG.
  • Comprehensive Test Coverage: New unit tests have been added and existing ones updated in AssignShardIdFnTest and SourceWriterFnTest to ensure correct handling of both retryable and severe Spanner exceptions and the new sentinel shard IDs.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sm745052 sm745052 changed the title handle retryable errors in reverse replication handle retryable errors in AssignShardIdFn [reverse replication] Dec 26, 2025
@codecov
Copy link

codecov bot commented Dec 26, 2025

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 50.80%. Comparing base (4a4a597) to head (f42fd5e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...es/utils/SpannerToSourceDbExceptionClassifier.java 95.23% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3157      +/-   ##
============================================
+ Coverage     50.79%   50.80%   +0.01%     
- Complexity     5106     5117      +11     
============================================
  Files           975      976       +1     
  Lines         59984    59994      +10     
  Branches       6552     6555       +3     
============================================
+ Hits          30468    30480      +12     
  Misses        27375    27375              
+ Partials       2141     2139       -2     
Components Coverage Δ
spanner-templates 71.00% <96.55%> (+0.02%) ⬆️
spanner-import-export 68.98% <ø> (-0.02%) ⬇️
spanner-live-forward-migration 80.02% <ø> (-0.02%) ⬇️
spanner-live-reverse-replication 77.72% <96.55%> (+0.07%) ⬆️
spanner-bulk-migration 88.47% <ø> (-0.02%) ⬇️
Files with missing lines Coverage Δ
...eport/v2/templates/transforms/AssignShardIdFn.java 78.38% <100.00%> (+0.24%) ⬆️
...leport/v2/templates/transforms/SourceWriterFn.java 86.66% <100.00%> (+2.10%) ⬆️
...es/utils/SpannerToSourceDbExceptionClassifier.java 95.23% <95.23%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@bharadwaj-aditya bharadwaj-aditya left a comment

Choose a reason for hiding this comment

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

LGTM

@bharadwaj-aditya
Copy link
Contributor

This logic should be made uniform in other templates/flows as well. Please create a follow up task to take up that exercise.

@sm745052
Copy link
Contributor Author

created b/472217883

@sm745052 sm745052 merged commit 9e360c9 into main Dec 29, 2025
32 of 33 checks passed
@sm745052 sm745052 deleted the retry_rev branch December 29, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants