Skip to content

Commit

Permalink
skip restore sub if pub not exists (matrixorigin#18261)
Browse files Browse the repository at this point in the history
skip restore sub if pub not exists

Approved by: @heni02, @daviszhen
  • Loading branch information
YANGGMM authored Aug 21, 2024
1 parent 0486f90 commit 80509e6
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/frontend/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func restoreToAccount(
return
}
}
getLogger(sid).Info(fmt.Sprintf("[%s]skip drop db: %v", snapshotName, dbName))
// getLogger(sid).Info(fmt.Sprintf("[%s]skip drop db: %v", snapshotName, dbName))
continue
}

Expand Down Expand Up @@ -1836,11 +1836,17 @@ func checkPubExistOrNot(
bh,
subInfo.PubAccountName,
subInfo.PubName)

if err != nil {
return false, err
} else if !isPubValid {
return false, moerr.NewInternalError(ctx, "there is no publication %s", subInfo.PubName)
getLogger(sid).Info(fmt.Sprintf("[%s] check pub exist or not error: %v", snapshotName, err))
return false, nil
}

if !isPubValid {
getLogger(sid).Info(fmt.Sprintf("[%s] pub %s is not valid", snapshotName, subInfo.PubName))
return false, nil
}

return true, nil
}

Expand Down Expand Up @@ -1904,7 +1910,7 @@ func checkSubscriptionExist(
return
}

getLogger(sid).Info(fmt.Sprintf("[%s] check subscription exist or not: get account id sql: %s", pubName, sql))
getLogger(sid).Info(fmt.Sprintf("check subscription %s exist or not: get account id sql: %s", pubName, sql))
bh.ClearExecResultSet()
if err = bh.Exec(newCtx, sql); err != nil {
return
Expand Down
64 changes: 64 additions & 0 deletions test/distributed/cases/snapshot/cluster/restore_pub_sub.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
drop account if exists acc01;
create account acc01 admin_name = 'test_account' identified by '111';
drop database if exists test02;
create database test02;
use test02;
drop table if exists rs02;
create table rs02 (col1 int primary key , col2 datetime);
insert into rs02 values (1, '2020-10-13 10:10:10');
insert into rs02 values (2, null);
insert into rs02 values (3, '2021-10-10 00:00:00');
insert into rs02 values (4, '2023-01-01 12:12:12');
insert into rs02 values (5, null);
insert into rs02 values (6, null);
insert into rs02 values (7, '2023-11-27 01:02:03');
select * from rs02;
col1 col2
1 2020-10-13 10:10:10
2 null
3 2021-10-10 00:00:00
4 2023-01-01 12:12:12
5 null
6 null
7 2023-11-27 01:02:03
drop table if exists rs03;
create table rs03 (col1 int, col2 float, col3 decimal, col4 enum('1','2','3','4'));
insert into rs03 values (1, 12.21, 32324.32131, 1);
insert into rs03 values (2, null, null, 2);
insert into rs03 values (2, -12.1, 34738, null);
insert into rs03 values (1, 90.2314, null, 4);
insert into rs03 values (1, 43425.4325, -7483.432, 2);
drop publication if exists pub02;
create publication pub02 database test02 table rs02 account acc01;
show publications;
publication database tables sub_account subscribed_accounts create_time update_time comments
pub02 test02 rs02 acc01 2024-08-21 14:51:51 null
show subscriptions all;
pub_name pub_account pub_database pub_tables pub_comment pub_time sub_name sub_time status
pub02 sys test02 rs02 2024-08-21 14:51:51 null null 0
drop database if exists sub02;
create database sub02 from sys publication pub02;
show subscriptions;
pub_name pub_account pub_database pub_tables pub_comment pub_time sub_name sub_time status
pub02 sys test02 rs02 2024-08-21 14:51:51 sub02 2024-08-21 14:51:52 0
drop snapshot if exists sp02;
create snapshot sp02 for account acc01;
show snapshots;
SNAPSHOT_NAME TIMESTAMP SNAPSHOT_LEVEL ACCOUNT_NAME DATABASE_NAME TABLE_NAME
sp02 2024-08-21 06:51:52.016381 account acc01
drop database sub02;
drop publication pub02;
show subscriptions;
pub_name pub_account pub_database pub_tables pub_comment pub_time sub_name sub_time status
restore account acc01 from snapshot sp02;
show subscriptions;
pub_name pub_account pub_database pub_tables pub_comment pub_time sub_name sub_time status
show databases;
Database
information_schema
mo_catalog
mysql
system
system_metrics
drop account acc01;
drop database if exists test02;
57 changes: 57 additions & 0 deletions test/distributed/cases/snapshot/cluster/restore_pub_sub.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
drop account if exists acc01;
create account acc01 admin_name = 'test_account' identified by '111';

drop database if exists test02;
create database test02;
use test02;
drop table if exists rs02;
create table rs02 (col1 int primary key , col2 datetime);
insert into rs02 values (1, '2020-10-13 10:10:10');
insert into rs02 values (2, null);
insert into rs02 values (3, '2021-10-10 00:00:00');
insert into rs02 values (4, '2023-01-01 12:12:12');
insert into rs02 values (5, null);
insert into rs02 values (6, null);
insert into rs02 values (7, '2023-11-27 01:02:03');
select * from rs02;
drop table if exists rs03;
create table rs03 (col1 int, col2 float, col3 decimal, col4 enum('1','2','3','4'));
insert into rs03 values (1, 12.21, 32324.32131, 1);
insert into rs03 values (2, null, null, 2);
insert into rs03 values (2, -12.1, 34738, null);
insert into rs03 values (1, 90.2314, null, 4);
insert into rs03 values (1, 43425.4325, -7483.432, 2);

drop publication if exists pub02;
create publication pub02 database test02 table rs02 account acc01;
-- @ignore:5,6
show publications;

-- @session:id=1&user=acc01:test_account&password=111
-- @ignore:5,7
show subscriptions all;
drop database if exists sub02;
create database sub02 from sys publication pub02;
-- @ignore:5,7
show subscriptions;

drop snapshot if exists sp02;
create snapshot sp02 for account acc01;
-- @ignore:1
show snapshots;
drop database sub02;
-- @session

drop publication pub02;

-- @session:id=1&user=acc01:test_account&password=111
-- @ignore:5,7
show subscriptions;
restore account acc01 from snapshot sp02;
-- @ignore:5,7
show subscriptions;
show databases;
-- @session

drop account acc01;
drop database if exists test02;

0 comments on commit 80509e6

Please sign in to comment.