This guide describes how to perform fallback and disaster recovery rollback from Spanner back to your source MySQL instances.
If you encounter unexpected performance degradation, unrecoverable application errors, or critical functional blockers after cutting over to Spanner, use the procedures in the following sections to roll back to your MySQL primary instances:
Before you begin
Before initiating fallback procedures, verify the following prerequisites:
- Active reverse replication: Verify that the reverse replication
Dataflow pipeline (
Spanner_to_SourceDb) is running and actively consuming Spanner change streams inforward_migrationfiltering mode. For more information, see Configure fallback to MySQL. - Source MySQL availability: Verify that your source MySQL database is online, reachable from Dataflow, and able to accept write connections.
- Maintenance window: Alert stakeholders that a planned downtime window is required while Spanner writes are paused and reverse replication drains.
Required roles
-
To get the permissions that you need to perform fallback to MySQL, ask your administrator to grant you the following IAM roles on the project:
- Cloud Spanner Database User (
roles/spanner.databaseUser) - Dataflow Admin (
roles/dataflow.admin) - Datastream Admin (
roles/datastream.admin) - Storage Admin (
roles/storage.admin) - Monitoring Viewer (
roles/monitoring.viewer) - Viewer (
roles/viewer)
- Cloud Spanner Database User (
Pause Spanner writes
- Pause all database write traffic to Spanner on your application.
- Allow active transactions on Spanner to fully commit and drain.
Allow reverse replication to drain
The following sections describe how to verify that all changes written to Spanner post-cutover replicate back to MySQL before switching application writes.
Monitor replication lag
Track replication lag to verify that all in-flight changes are written to MySQL:
- In the Google Cloud console, go to the Job details page for your reverse replication Dataflow job.
- On the Custom metrics tab, inspect the
replication_lag_in_seconds_LOGICAL_SHARD_NAME_MAXuser counter. For more information, see Configure fallback to MySQL. - Wait for the counter value to reach
0.
Alternatively, in Metrics Explorer, query the user counter by using Monitoring Query Language (MQL):
fetch dataflow_job | metric 'dataflow.googleapis.com/job/user_counter' | filter (metric.job_id == 'JOB_ID' && metric.metric_name == 'replication_lag_insecondsLOGICAL_SHARD_NAME_MAX') | group_by 1m, [value_p99_latency: percentile(value.user_counter, 99)] | every 1m
JOB_ID: the ID of your reverse replication
Dataflow job.
* LOGICAL_SHARD_NAME: the logical shard name
configured for your source database.
Verify MySQL write activity
Verify that reverse replication write operations have completed on your source database:
- In your source MySQL primary database, inspect active queries and database connection metrics.
- Verify that write traffic from the reverse replication pipeline has stopped.
Verify clean DLQ state
Inspect the dead-letter queues (DLQ) to verify that no unhandled errors occurred during reverse replication:
- In the Google Cloud console, go to the Job details page for your reverse
replication Dataflow job. On the Custom metrics tab,
inspect the
severe_error_countuser counter. Inspect both severe and retry reverse replication DLQ directories in Cloud Storage (for example,
gs://MIGRATION_BUCKET/ENV/SERVICE/reverse/DB_SCHEMA/severe/andgs://MIGRATION_BUCKET/ENV/SERVICE/reverse/DB_SCHEMA/retry/).You can list the contents of the severe DLQ directory by using the gcloud CLI CLI:
gcloud storage ls gs://MIGRATION_BUCKET/ENV/SERVICE/reverse/DB_SCHEMA/severe/
Replace the following:
MIGRATION_BUCKET: the name of your Cloud Storage bucket.ENV: your deployment environment name (for example,prod).SERVICE: your application or service name.DB_SCHEMA: your database schema name.
Verify that the DLQ directories remain completely empty.
If error files exist, resolve underlying issues and replay failed records before proceeding. For more information, see Monitor and resolve reverse replication errors.
Resume forward CDC streaming
If you plan to resume forward migration to Spanner in the future, resume the forward Datastream stream:
- In the Google Cloud console, go to the Stream details page for your stream.
- Click Resume, and wait for the stream status to change to
RUNNING. For more information, see Migrate your MySQL data.
Alternatively, to resume the stream by using the gcloud CLI CLI,
run the gcloud datastream streams resume command:
gcloud datastream streams resume STREAM_ID \
--location=LOCATION
Replace the following:
STREAM_ID: the ID of your Datastream stream.LOCATION: the Google Cloud region where your stream is located.
Reroute writes to MySQL
- Update application configuration and database connection strings to target your source MySQL primary database instances.
- Start application services and resume live read and write traffic against MySQL.
- Verify that application read and write operations run successfully against the MySQL database.