Skip to content

Instantly share code, notes, and snippets.

@robrich
Created August 3, 2020 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save robrich/8329734851906945dd40ddf92eb7c08d to your computer and use it in GitHub Desktop.
Save robrich/8329734851906945dd40ddf92eb7c08d to your computer and use it in GitHub Desktop.
MemSQL Disaster Recovery - failback to primary cluster demo
-- Step_1: setup
Create database testDB;
use testDB;
Create table t( a int, b varchar(70));
insert into t values (1, now(6));
insert into t select a+(select max(a) from t), now(6) from t;
select count(*) from t; -- 262144
-- Step_3: updates on primary
insert into t values (-1, now(6));
-- Step_7 Cluster_1 is fixed and alive, its time to catch up
-- replicate database testDB_full from root:'memsqltest'@52.207.57.173:3306/testDB;
replicate database testDB with force differential from root:'memsqltest'@34.229.56.194:3306/testDB;
use testDB;
select count(*) from t; -- 262149
select * from t where a < 0 order by a;
-- Step_8 If you are happy with Cluster_2 serving the traffic, nothing more to do.
-- If you prefer cluster_1 to be the new primary cluster again, ...
-- Step_10 After cluster_2 flushes out chnages, make Cluster_1 the primary cluster again
stop replicating testDB;
-- Step_11: Redirect SQL traffic to Cluster_2
delete from t where a < 0;
-- Please reference details in the blog: https://www.memsql.com/blog/fast-disaster-recovery-failback-memsql-7-1/
-- Step_2: replicate from primary
replicate database testDB from root:'memsqltest'@100.26.142.81:3306/testDB;
-- Step_4: Verify that new updates are replicated
use testDB;
select * from t where a = -1;
select count(*) from t; -- 262145
-- Step_5: Assuming Cluster_1 is down
stop replicating testDB;
-- Step_6: Redirect SQL traffic to Cluster_2
insert into t values (-2, now(6));
insert into t values (-3, now(6));
insert into t values (-4, now(6));
insert into t values (-5, now(6));
-- Step_9: Fail new WRITE TXNs and flush out current TXNs
flush tables with read only;
-- Step_12: Make Cluster_2 the secondary cluster
unlock tables;
select * from t where a < 0;
replicate database testDB with force differential from root:'memsqltest'@100.26.142.81:3306/testDB;
select * from t where a < 0;
-- Please reference details in the blog: https://www.memsql.com/blog/fast-disaster-recovery-failback-memsql-7-1/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment