Skip to content

test(Spanner): add SQL Server comprehensive integration tests for Datastream to Spanner pipeline - #4230

Merged
pratickchokhani merged 15 commits into
GoogleCloudPlatform:mainfrom
pratickchokhani:sqlserver-live-migration-integration
Nov 3, 2026
Merged

pratickchokhani merged 15 commits into
GoogleCloudPlatform:mainfrom
pratickchokhani:sqlserver-live-migration-integration

Conversation

@pratickchokhani

Copy link
Copy Markdown
Contributor

No description provided.

@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.86%. Comparing base (3edd1de) to head (d349ce5).

Files with missing lines Patch % Lines
...it/gcp/cloudsql/CloudSqlServerResourceManager.java 0.00% 9 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4230      +/-   ##
============================================
- Coverage     56.87%   56.86%   -0.01%     
+ Complexity     8087     8085       -2     
============================================
  Files          1164     1164              
  Lines         74114    74117       +3     
  Branches       8735     8735              
============================================
- Hits          42150    42147       -3     
- Misses        29164    29170       +6     
  Partials       2800     2800              
Components Coverage Δ
spanner-templates 83.70% <ø> (ø)
spanner-import-export 72.32% <ø> (-0.02%) ⬇️
spanner-live-forward-migration 86.93% <ø> (ø)
spanner-live-reverse-replication 79.21% <ø> (ø)
spanner-bulk-migration 87.88% <ø> (ø)
gcs-spanner-dv 85.71% <ø> (ø)
Files with missing lines Coverage Δ
...urce/sqlserver/SqlServerDsToSpSourceConnector.java 100.00% <ø> (ø)
...it/gcp/cloudsql/CloudSqlServerResourceManager.java 0.00% <0.00%> (ø)

... and 2 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.

@pratickchokhani pratickchokhani changed the title feat(Spanner): add SQL Server comprehensive integration tests for Datastream to Spanner pipeline test(Spanner): add SQL Server comprehensive integration tests for Datastream to Spanner pipeline Sep 8, 2026
@pratickchokhani pratickchokhani added the addition New feature or request label Sep 8, 2026
@pratickchokhani
pratickchokhani force-pushed the sqlserver-live-migration-integration branch 10 times, most recently from b63ef92 to 44c9998 Compare September 9, 2026 13:54
@pratickchokhani
pratickchokhani force-pushed the sqlserver-live-migration-integration branch 2 times, most recently from c7efd4a to 7c5cd31 Compare October 27, 2026 10:17
@pratickchokhani
pratickchokhani marked this pull request as ready for review October 28, 2026 05:07
@pratickchokhani
pratickchokhani requested a review from a team as a code owner October 28, 2026 05:07
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 introduces critical stability improvements for the SQL Server resource manager by serializing CDC enablement to avoid deadlocks. Additionally, it significantly expands the test coverage for the Datastream to Spanner pipeline by adding a suite of integration tests that validate complex migration scenarios, including schema evolution, reserved keyword handling, and sharded data replication.

Highlights

  • Concurrency Fix: Added a synchronization lock (CDC_ENABLE_LOCK) in CloudSqlServerResourceManager to prevent deadlocks when enabling CDC on multiple tables concurrently.
  • New Integration Tests: Added comprehensive integration tests for SQL Server to Spanner pipeline, covering DLQ retries, reserved keywords, DDL migrations, event handling (INSERT/UPDATE/DELETE), timezone handling, sharded migrations, and shadow table database configurations.
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 the 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 counterproductive. 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.

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. ↩

@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 a comprehensive suite of integration tests for SQL Server to Spanner migrations using Datastream, covering various scenarios such as retry DLQ, reserved keywords, DDL conversions, events, sessions, timezones, sharded migrations, and separate shadow table databases. Additionally, it resolves a potential concurrent deadlock issue (SQL Server error 1205) in CloudSqlServerResourceManager by introducing a static lock (CDC_ENABLE_LOCK) to serialize CDC enablement. The reviewer feedback highlights a critical improvement opportunity across all the newly added integration tests: wrapping the Datastream resource manager cleanup in a try-finally block to guarantee that expensive cloud resources (like Spanner and Cloud SQL instances) are always cleaned up even if the Datastream cleanup fails.

@pratickchokhani
pratickchokhani force-pushed the sqlserver-live-migration-integration branch 2 times, most recently from 860b41a to c83c174 Compare October 28, 2026 11:12

@dhwanilpatel dhwanilpatel 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.

Let's trigger ITs couple of time to validate multiple ITs are working well against static testcontainer.

…o Spanner pipeline and update timestamp conversion logic
Pratick Chokhani added 14 commits November 2, 2026 11:27
- Rebase on main after GoogleCloudPlatform#4244 (static SQL Server container, shared datatype IT).
- Align existing SQL Server ITs with the merged approach (enableCdcOnAllTables,
  shared SQLServerITContainer, resilient teardown); base class unchanged from main.
- Add live-Datastream ports of the manifest scenarios: Events, DDL (custom
  transformation, size conversion, identity), Timezone, Session (rename/drop,
  synthetic PK), SeparateShadowTable PK-focused, SingleDF sharded (@ignore until
  migration_shard_id is populated for sqlserver sources).
- Drop ITs not listed in manifest.yaml (RetryAllDLQ, sharded RetryDLQ,
  TableAndIndexLimits) and the onboarding report.
- EventsIT: quote reserved keyword [plan] in SQL Server DDL/DML.
- SQLServerDataStreamToSpannerIT: drop manual sp_cdc_* statements from the
  schema script; enableCdcOnAllTables() owns CDC setup.
- RetryDLQIT: AllDataTypes.datetime_col -> DATETIMEOFFSET (datetime is routed
  to the DLQ), which left a second permanent event in the severe bucket.
- SeparateShadowTablePKFocusedIT: render the expected string via
  Value.string(..).toString(), which elides values longer than 36 chars.
With several ITs enabling CDC concurrently on the shared SQL Server container,
the first sp_cdc_enable_table per database deadlocks in msdb.dbo.sp_add_job
(error 1205) and SQL Server asks to rerun the transaction.

- CloudSqlServerResourceManager.enableCdcOnAllTables(): retry on deadlock with
  backoff; the cursor only visits untracked tables so reruns resume safely.
- Add enableCdcOnTable(schema, table, uniqueIndexName) with the same retry for
  tables without a primary key.
- SessionIT: enable CDC on the PK-less Books table through the resource manager
  instead of a raw EXEC in the DDL script.
Hold a static lock while enabling CDC so concurrent ITs on the shared SQL
Server container never race on msdb job creation; keep the deadlock retry as a
fallback for contention from outside the JVM.
enableCdcOnAllTables() now uses a table's first unique index as @index_name
when it has no primary key, so the separate enableCdcOnTable helper and the
capture-job helper are folded away.
Only the lock is needed for the deadlock; the PK-less Books table in the
Session IT gets a primary key on the source side instead.
… row count

The CDC wave's row count is also satisfied by transient states before the
UPDATE of id 3 is applied, which made the final assertion racy.
- DDLIT / SessionIT: wait for the updated rows, not just the row count, after
  the CDC wave (same race as EventsIT).
- RetryDLQIT: restore the 'wait for fixed rows' step from the MySQL reference
  before the final assertions.
- Pass only the generated session content in SQLServerDataStreamToSpannerIT.
- Delete Datastream streams before dropping the source database in the three
  ITs that cleaned up in the other order.
…stead

Each CDC wait now describes the exact end state of the wave (updated rows
visible, deleted rows gone, inserted rows present), so the fixed cutover sleep
before assertions is no longer needed.
Datastream resource manager is passed first so streams are still deleted
before the CDC-enabled source database is dropped.
- Cancel the Dataflow job (tearDownBase) before deleting its resources in the
  per-test ITs (ReservedKeywords, SQLServerDataStreamToSpannerIT, Timezone).
- SQLServerDataStreamToSpannerIT: verify UPDATE and DELETE in addition to
  INSERT, like the MySQL reference.
- DDLIT: port DatatypeSizeReducedConversion (oversized values rejected, not
  truncated) and SequenceColumns (SQL Server SEQUENCE key default).
SQL Server pads CHAR(n) to n characters, so the 'fits' row never fit the
reduced STRING(5) column either. Keep char_column at full width and apply the
size reduction to the NVARCHAR column; drop the varbinary column from the table.
@pratickchokhani
pratickchokhani force-pushed the sqlserver-live-migration-integration branch from 0688f84 to d349ce5 Compare November 2, 2026 05:57

@dhwanilpatel dhwanilpatel 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.

LGTM

Let's trigger tests couple of more time to confirm these are not flaky with shared testcontainer.

@pratickchokhani
pratickchokhani merged commit 86063bb into GoogleCloudPlatform:main Nov 3, 2026
61 of 62 checks passed
@pratickchokhani
pratickchokhani deleted the sqlserver-live-migration-integration branch November 3, 2026 05:47
pratickchokhani added a commit to pratickchokhani/DataflowTemplates that referenced this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addition New feature or request size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants