From 80509e68b5130621f62ce10c1f9c72904f9d4591 Mon Sep 17 00:00:00 2001 From: YANGGMM Date: Wed, 21 Aug 2024 17:45:03 +0800 Subject: [PATCH] skip restore sub if pub not exists (#18261) skip restore sub if pub not exists Approved by: @heni02, @daviszhen --- pkg/frontend/snapshot.go | 16 +++-- .../snapshot/cluster/restore_pub_sub.result | 64 +++++++++++++++++++ .../snapshot/cluster/restore_pub_sub.sql | 57 +++++++++++++++++ 3 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 test/distributed/cases/snapshot/cluster/restore_pub_sub.result create mode 100644 test/distributed/cases/snapshot/cluster/restore_pub_sub.sql diff --git a/pkg/frontend/snapshot.go b/pkg/frontend/snapshot.go index df9467dbace1..c616410d227f 100644 --- a/pkg/frontend/snapshot.go +++ b/pkg/frontend/snapshot.go @@ -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 } @@ -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 } @@ -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 diff --git a/test/distributed/cases/snapshot/cluster/restore_pub_sub.result b/test/distributed/cases/snapshot/cluster/restore_pub_sub.result new file mode 100644 index 000000000000..25f31b5d8789 --- /dev/null +++ b/test/distributed/cases/snapshot/cluster/restore_pub_sub.result @@ -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; diff --git a/test/distributed/cases/snapshot/cluster/restore_pub_sub.sql b/test/distributed/cases/snapshot/cluster/restore_pub_sub.sql new file mode 100644 index 000000000000..5742be72cbab --- /dev/null +++ b/test/distributed/cases/snapshot/cluster/restore_pub_sub.sql @@ -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;