diff --git a/pkg/bootstrap/versions/v2_0_2/cluster_upgrade_list.go b/pkg/bootstrap/versions/v2_0_2/cluster_upgrade_list.go index 6e6d0fdc1b3b8..3e3b5123206ae 100644 --- a/pkg/bootstrap/versions/v2_0_2/cluster_upgrade_list.go +++ b/pkg/bootstrap/versions/v2_0_2/cluster_upgrade_list.go @@ -22,6 +22,9 @@ import ( var clusterUpgEntries = []versions.UpgradeEntry{ upg_mo_cdc_watermark, + upg_mo_pubs_add_account_name, + upg_mo_subs_add_sub_account_name, + upg_mo_subs_add_pub_account_id, } var upg_mo_cdc_watermark = versions.UpgradeEntry{ @@ -37,3 +40,48 @@ var upg_mo_cdc_watermark = versions.UpgradeEntry{ return !colInfo.IsExits, nil }, } + +var upg_mo_pubs_add_account_name = versions.UpgradeEntry{ + Schema: catalog.MO_CATALOG, + TableName: catalog.MO_PUBS, + UpgType: versions.ADD_COLUMN, + UpgSql: "alter table mo_catalog.mo_pubs add column account_name varchar(300) after account_id", + CheckFunc: func(txn executor.TxnExecutor, accountId uint32) (bool, error) { + colInfo, err := versions.CheckTableColumn(txn, accountId, catalog.MO_CATALOG, catalog.MO_PUBS, "account_name") + if err != nil { + return false, err + } + return colInfo.IsExits, nil + }, + PostSql: "UPDATE mo_catalog.mo_pubs t1 INNER JOIN mo_catalog.mo_account t2 ON t1.account_id = t2.account_id SET t1.account_name = t2.account_name", +} + +var upg_mo_subs_add_sub_account_name = versions.UpgradeEntry{ + Schema: catalog.MO_CATALOG, + TableName: catalog.MO_SUBS, + UpgType: versions.ADD_COLUMN, + UpgSql: "alter table mo_catalog.mo_subs add column sub_account_name VARCHAR(300) NOT NULL after sub_account_id", + CheckFunc: func(txn executor.TxnExecutor, accountId uint32) (bool, error) { + colInfo, err := versions.CheckTableColumn(txn, accountId, catalog.MO_CATALOG, catalog.MO_SUBS, "sub_account_name") + if err != nil { + return false, err + } + return colInfo.IsExits, nil + }, + PostSql: "UPDATE mo_catalog.mo_subs t1 INNER JOIN mo_catalog.mo_account t2 ON t1.sub_account_id = t2.account_id SET t1.sub_account_name = t2.account_name", +} + +var upg_mo_subs_add_pub_account_id = versions.UpgradeEntry{ + Schema: catalog.MO_CATALOG, + TableName: catalog.MO_SUBS, + UpgType: versions.ADD_COLUMN, + UpgSql: "alter table mo_catalog.mo_subs add column pub_account_id INT NOT NULL after sub_time", + CheckFunc: func(txn executor.TxnExecutor, accountId uint32) (bool, error) { + colInfo, err := versions.CheckTableColumn(txn, accountId, catalog.MO_CATALOG, catalog.MO_SUBS, "pub_account_id") + if err != nil { + return false, err + } + return colInfo.IsExits, nil + }, + PostSql: "UPDATE mo_catalog.mo_subs t1 INNER JOIN mo_catalog.mo_account t2 ON t1.pub_account_name = t2.account_name SET t1.pub_account_id = t2.account_id", +} diff --git a/pkg/common/pubsub/types.go b/pkg/common/pubsub/types.go index f8028c411361a..f25841b1687d0 100644 --- a/pkg/common/pubsub/types.go +++ b/pkg/common/pubsub/types.go @@ -92,8 +92,10 @@ func (pubInfo *PubInfo) GetCreateSql() string { type SubInfo struct { SubAccountId int32 + SubAccountName string SubName string SubTime string + PubAccountId int32 PubAccountName string PubName string PubDbName string diff --git a/pkg/frontend/authenticate.go b/pkg/frontend/authenticate.go index c2f9db14ce95c..09a9315f2e3c4 100644 --- a/pkg/frontend/authenticate.go +++ b/pkg/frontend/authenticate.go @@ -3613,24 +3613,46 @@ func doDropAccount(ctx context.Context, bh BackgroundExec, ses *Session, da *dro return moerr.NewInternalErrorf(ctx, "can not delete the account %s", da.Name) } + checkAccount := func(accountName string) (accountId int64, version uint64, ok bool, err error) { + if sql, err = getSqlForCheckTenant(ctx, da.Name); err != nil { + return + } + + bh.ClearExecResultSet() + if err = bh.Exec(ctx, sql); err != nil { + return + } + + if erArray, err = getResultSet(ctx, bh); err != nil { + return + } + + if execResultArrayHasData(erArray) { + if accountId, err = erArray[0].GetInt64(ctx, 0, 0); err != nil { + return + } + if version, err = erArray[0].GetUint64(ctx, 0, 3); err != nil { + return + } + ok = true + } + + return + } + dropAccountFunc := func() (rtnErr error) { ses.Infof(ctx, "dropAccount %s sql: %s", da.Name, getAccountIdNamesSql) - _, nameInfoMap, rtnErr := getAccounts(ctx, bh, true) - if rtnErr != nil { - return rtnErr + if accountId, version, hasAccount, rtnErr = checkAccount(da.Name); rtnErr != nil { + return } - - //check the account exists or not - if _, ok := nameInfoMap[da.Name]; !ok { - //no such account - if !da.IfExists { //when the "IF EXISTS" is set, just skip it. + // check the account exists or not + if !hasAccount { + // when the "IF EXISTS" is set, just skip it. + if !da.IfExists { rtnErr = moerr.NewInternalErrorf(ctx, "there is no account %s", da.Name) } - hasAccount = false return } - accountId = int64(nameInfoMap[da.Name].Id) - version = nameInfoMap[da.Name].Version //drop tables of the tenant //NOTE!!!: single DDL drop statement per single transaction @@ -3661,7 +3683,7 @@ func doDropAccount(ctx context.Context, bh BackgroundExec, ses *Session, da *dro } for _, pubInfo := range pubInfos { ses.Infof(ctx, "dropAccount %s sql: %s", da.Name, pubInfo.PubName) - if rtnErr = dropPublication(deleteCtx, bh, true, pubInfo.PubName); rtnErr != nil { + if rtnErr = dropPublication(deleteCtx, bh, true, pubInfo.PubAccountName, pubInfo.PubName); rtnErr != nil { return } } @@ -3721,13 +3743,8 @@ func doDropAccount(ctx context.Context, bh BackgroundExec, ses *Session, da *dro return rtnErr } for _, subInfo := range subInfos { - pubAccInfo, ok := nameInfoMap[subInfo.PubAccountName] - if !ok { - continue - } - ses.Infof(ctx, "dropAccount %s sql: %s %s", da.Name, updatePubInfoAccountListFormat, subInfo.PubName) - if rtnErr = dropSubAccountNameInSubAccounts(deleteCtx, bh, pubAccInfo.Id, subInfo.PubName, da.Name); rtnErr != nil { + if rtnErr = dropSubAccountNameInSubAccounts(deleteCtx, bh, subInfo.PubAccountId, subInfo.PubName, da.Name); rtnErr != nil { return rtnErr } } @@ -7691,6 +7708,8 @@ func createSubscription(ctx context.Context, bh BackgroundExec, newTenant *Tenan for _, pubInfo := range pubInfos { subInfo := &pubsub.SubInfo{ SubAccountId: int32(newTenant.TenantID), + SubAccountName: newTenant.Tenant, + PubAccountId: accountId, PubAccountName: accIdInfoMap[accountId].Name, PubName: pubInfo.PubName, PubDbName: pubInfo.DbName, diff --git a/pkg/frontend/authenticate_test.go b/pkg/frontend/authenticate_test.go index b3aef63ec8023..fa3f1e102c747 100644 --- a/pkg/frontend/authenticate_test.go +++ b/pkg/frontend/authenticate_test.go @@ -7126,9 +7126,8 @@ func Test_doDropAccount(t *testing.T) { bh.sql2result["commit;"] = nil bh.sql2result["rollback;"] = nil - sql := getAccountIdNamesSql + " for update" + sql, _ := getSqlForCheckTenant(ctx, "acc") mrs := newMrsForGetAllAccounts([][]interface{}{ - {uint64(0), "sys", "open", uint64(1), nil}, {uint64(1), "acc", "open", uint64(1), nil}, }) bh.sql2result[sql] = mrs @@ -7187,7 +7186,7 @@ func Test_doDropAccount(t *testing.T) { bh.sql2result["commit;"] = nil bh.sql2result["rollback;"] = nil - sql := getAccountIdNamesSql + " for update" + sql, _ := getSqlForCheckTenant(ctx, "acc") bh.sql2result[sql] = newMrsForGetAllAccounts([][]interface{}{}) sql, _ = getSqlForDeleteAccountFromMoAccount(context.TODO(), mustUnboxExprStr(stmt.Name)) diff --git a/pkg/frontend/predefined.go b/pkg/frontend/predefined.go index b82cc16f32dea..977a31c731df9 100644 --- a/pkg/frontend/predefined.go +++ b/pkg/frontend/predefined.go @@ -163,6 +163,7 @@ var ( MoCatalogMoPubsDDL = `create table mo_catalog.mo_pubs ( account_id int not null, + account_name varchar(300), pub_name varchar(64), database_name varchar(5000), database_id bigint unsigned, @@ -179,8 +180,10 @@ var ( MoCatalogMoSubsDDL = `create table mo_catalog.mo_subs ( sub_account_id INT NOT NULL, + sub_account_name VARCHAR(300) NOT NULL, sub_name VARCHAR(5000) DEFAULT NULL, sub_time TIMESTAMP DEFAULT NULL, + pub_account_id INT NOT NULL, pub_account_name VARCHAR(300) NOT NULL, pub_name VARCHAR(64) NOT NULL, pub_database VARCHAR(5000) NOT NULL, diff --git a/pkg/frontend/publication_subscription.go b/pkg/frontend/publication_subscription.go index 35b0468578062..b09dfce7b031f 100644 --- a/pkg/frontend/publication_subscription.go +++ b/pkg/frontend/publication_subscription.go @@ -36,19 +36,19 @@ const ( // account getAccountIdNamesSql = "select account_id, account_name, status, version, suspended_time from mo_catalog.mo_account where 1=1" // pub - insertIntoMoPubsFormat = `insert into mo_catalog.mo_pubs (account_id, pub_name, database_name, database_id, all_table, table_list, account_list, created_time, owner, creator, comment) values (%d, '%s', '%s', %d, %t, '%s', '%s', now(), %d, %d, '%s');` - getAllPubInfoSql = "select account_id, pub_name, database_name, database_id, table_list, account_list, created_time, update_time, owner, creator, comment from mo_catalog.mo_pubs" - getPubInfoSql = "select account_id, pub_name, database_name, database_id, table_list, account_list, created_time, update_time, owner, creator, comment from mo_catalog.mo_pubs where account_id = %d" + insertIntoMoPubsFormat = `insert into mo_catalog.mo_pubs (account_id, account_name, pub_name, database_name, database_id, all_table, table_list, account_list, created_time, owner, creator, comment) values (%d, '%s', '%s', '%s', %d, %t, '%s', '%s', now(), %d, %d, '%s');` + getAllPubInfoSql = "select account_id, account_name, pub_name, database_name, database_id, table_list, account_list, created_time, update_time, owner, creator, comment from mo_catalog.mo_pubs" + getPubInfoSql = "select account_id, account_name, pub_name, database_name, database_id, table_list, account_list, created_time, update_time, owner, creator, comment from mo_catalog.mo_pubs where account_id = %d" updatePubInfoFormat = `update mo_catalog.mo_pubs set account_list = '%s', comment = '%s', database_name = '%s', database_id = %d, update_time = now(), table_list = '%s' where account_id = %d and pub_name = '%s';` updatePubInfoAccountListFormat = `update mo_catalog.mo_pubs set account_list = '%s' where account_id = %d and pub_name = '%s';` dropPubFormat = `delete from mo_catalog.mo_pubs where account_id = %d and pub_name = '%s';` getDbPubCountFormat = `select count(1) from mo_catalog.mo_pubs where account_id = %d and database_name = '%s';` // sub - insertIntoMoSubsFormat = "insert into mo_catalog.mo_subs (sub_account_id, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status) values (%d, '%s', '%s', '%s', '%s', now(), '%s', %d)" - batchInsertIntoMoSubsFormat = "insert into mo_catalog.mo_subs (sub_account_id, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status) values %s" + insertIntoMoSubsFormat = "insert into mo_catalog.mo_subs (sub_account_id, sub_account_name, pub_account_id, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status) values (%d, '%s', %d, '%s', '%s', '%s', '%s', now(), '%s', %d)" + batchInsertIntoMoSubsFormat = "insert into mo_catalog.mo_subs (sub_account_id, sub_account_name, pub_account_id, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status) values %s" batchUpdateMoSubsFormat = "update mo_catalog.mo_subs set pub_database='%s', pub_tables='%s', pub_time=now(), pub_comment='%s', status=%d where pub_account_name = '%s' and pub_name = '%s' and sub_account_id in (%s)" batchDeleteMoSubsFormat = "delete from mo_catalog.mo_subs where pub_account_name = '%s' and pub_name = '%s' and sub_account_id in (%s)" - getSubsSql = "select sub_account_id, sub_name, sub_time, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status from mo_catalog.mo_subs where 1=1" + getSubsSql = "select sub_account_id, sub_account_name, sub_name, sub_time, pub_account_id, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status from mo_catalog.mo_subs where 1=1" deleteMoSubsRecordsBySubAccountIdFormat = "delete from mo_catalog.mo_subs where sub_account_id = %d" // database getDbIdAndTypFormat = `select dat_id,dat_type from mo_catalog.mo_database where datname = '%s' and account_id = %d;` @@ -246,7 +246,7 @@ func createPublication(ctx context.Context, bh BackgroundExec, cp *tree.CreatePu } } - sql, err = getSqlForInsertIntoMoPubs(ctx, pubName, dbName, dbId, len(cp.Table) == 0, tablesStr, accountNamesStr, comment, true) + sql, err = getSqlForInsertIntoMoPubs(ctx, accountId, accountName, pubName, dbName, dbId, len(cp.Table) == 0, tablesStr, accountNamesStr, comment, true) if err != nil { return } @@ -306,9 +306,9 @@ func createPublication(ctx context.Context, bh BackgroundExec, cp *tree.CreatePu } if err = batchInsertMoSubs( ctx, bh, - dbName, tablesStr, comment, - accountName, pubName, - insertSubAccounts, + int32(accountId), accountName, + pubName, dbName, tablesStr, comment, + insertSubAccounts, accIdInfoMap, ); err != nil { return } @@ -516,9 +516,9 @@ func doAlterPublication(ctx context.Context, ses *Session, ap *tree.AlterPublica } if err = batchInsertMoSubs( ctx, bh, - dbName, tablesStr, comment, - accountName, pubName, - insertSubAccounts, + int32(accountId), accountName, + pubName, dbName, tablesStr, comment, + insertSubAccounts, accIdInfoMap, ); err != nil { return } @@ -547,23 +547,13 @@ func doDropPublication(ctx context.Context, ses *Session, dp *tree.DropPublicati err = finishTxn(ctx, bh, err) }() - return dropPublication(ctx, bh, dp.IfExists, string(dp.Name)) + return dropPublication(ctx, bh, dp.IfExists, tenantInfo.Tenant, string(dp.Name)) } // dropPublication drops a publication, bh should be in a transaction -func dropPublication(ctx context.Context, bh BackgroundExec, ifExists bool, pubName string) (err error) { +func dropPublication(ctx context.Context, bh BackgroundExec, ifExists bool, accountName string, pubName string) (err error) { var sql string - accIdInfoMap, _, err := getAccounts(ctx, bh, false) - if err != nil { - return - } - accountId, err := defines.GetAccountId(ctx) - if err != nil { - return err - } - accountName := accIdInfoMap[int32(accountId)].Name - pub, err := getPubInfo(ctx, bh, pubName) if err != nil { return err @@ -583,7 +573,7 @@ func dropPublication(ctx context.Context, bh BackgroundExec, ifExists bool, pubN } // subAccountName -> SubInfo map - subInfos, err := getSubInfosFromPub(ctx, bh, accIdInfoMap[int32(accountId)].Name, pubName, false) + subInfos, err := getSubInfosFromPub(ctx, bh, accountName, pubName, false) if err != nil { return err } @@ -697,6 +687,7 @@ func getAccounts(ctx context.Context, bh BackgroundExec, forUpdate bool) (idInfo func extractPubInfosFromExecResult(ctx context.Context, erArray []ExecResult) (pubInfos []*pubsub.PubInfo, err error) { var ( accountId int64 + accountName string pubName string dbName string dbId uint64 @@ -714,45 +705,49 @@ func extractPubInfosFromExecResult(ctx context.Context, erArray []ExecResult) (p if accountId, err = result.GetInt64(ctx, i, 0); err != nil { return } - if pubName, err = result.GetString(ctx, i, 1); err != nil { + if accountName, err = result.GetString(ctx, i, 1); err != nil { return } - if dbName, err = result.GetString(ctx, i, 2); err != nil { + if pubName, err = result.GetString(ctx, i, 2); err != nil { return } - if dbId, err = result.GetUint64(ctx, i, 3); err != nil { + if dbName, err = result.GetString(ctx, i, 3); err != nil { return } - if tablesStr, err = result.GetString(ctx, i, 4); err != nil { + if dbId, err = result.GetUint64(ctx, i, 4); err != nil { return } - if accountNamesStr, err = result.GetString(ctx, i, 5); err != nil { + if tablesStr, err = result.GetString(ctx, i, 5); err != nil { return } - if createTime, err = result.GetString(ctx, i, 6); err != nil { + if accountNamesStr, err = result.GetString(ctx, i, 6); err != nil { return } - if isNull, err = result.ColumnIsNull(ctx, i, 7); err != nil { + if createTime, err = result.GetString(ctx, i, 7); err != nil { + return + } + if isNull, err = result.ColumnIsNull(ctx, i, 8); err != nil { return } else if !isNull { - if updateTime, err = result.GetString(ctx, i, 7); err != nil { + if updateTime, err = result.GetString(ctx, i, 8); err != nil { return } } else { updateTime = "" } - if owner, err = result.GetUint64(ctx, i, 8); err != nil { + if owner, err = result.GetUint64(ctx, i, 9); err != nil { return } - if creator, err = result.GetUint64(ctx, i, 9); err != nil { + if creator, err = result.GetUint64(ctx, i, 10); err != nil { return } - if comment, err = result.GetString(ctx, i, 10); err != nil { + if comment, err = result.GetString(ctx, i, 11); err != nil { return } pubInfos = append(pubInfos, &pubsub.PubInfo{ PubAccountId: uint32(accountId), + PubAccountName: accountName, PubName: pubName, DbName: dbName, DbId: dbId, @@ -880,8 +875,10 @@ func getAllPubInfosBySnapshotName(ctx context.Context, bh BackgroundExec, snapsh func extractSubInfosFromExecResult(ctx context.Context, erArray []ExecResult) (subInfos []*pubsub.SubInfo, err error) { var ( subAccountId int64 + subAccountName string subName string subTime string + pubAccountId int64 pubAccountName string pubName string pubDbName string @@ -896,50 +893,58 @@ func extractSubInfosFromExecResult(ctx context.Context, erArray []ExecResult) (s if subAccountId, err = result.GetInt64(ctx, i, 0); err != nil { return } - if isNull, err = result.ColumnIsNull(ctx, i, 1); err != nil { + if subAccountName, err = result.GetString(ctx, i, 1); err != nil { + return + } + if isNull, err = result.ColumnIsNull(ctx, i, 2); err != nil { return } else if !isNull { - if subName, err = result.GetString(ctx, i, 1); err != nil { + if subName, err = result.GetString(ctx, i, 2); err != nil { return } } else { subName = "" } - if isNull, err = result.ColumnIsNull(ctx, i, 2); err != nil { + if isNull, err = result.ColumnIsNull(ctx, i, 3); err != nil { return } else if !isNull { - if subTime, err = result.GetString(ctx, i, 2); err != nil { + if subTime, err = result.GetString(ctx, i, 3); err != nil { return } } else { subTime = "" } - if pubAccountName, err = result.GetString(ctx, i, 3); err != nil { + if pubAccountId, err = result.GetInt64(ctx, i, 4); err != nil { + return + } + if pubAccountName, err = result.GetString(ctx, i, 5); err != nil { return } - if pubName, err = result.GetString(ctx, i, 4); err != nil { + if pubName, err = result.GetString(ctx, i, 6); err != nil { return } - if pubDbName, err = result.GetString(ctx, i, 5); err != nil { + if pubDbName, err = result.GetString(ctx, i, 7); err != nil { return } - if pubTables, err = result.GetString(ctx, i, 6); err != nil { + if pubTables, err = result.GetString(ctx, i, 8); err != nil { return } - if pubTime, err = result.GetString(ctx, i, 7); err != nil { + if pubTime, err = result.GetString(ctx, i, 9); err != nil { return } - if pubComment, err = result.GetString(ctx, i, 8); err != nil { + if pubComment, err = result.GetString(ctx, i, 10); err != nil { return } - if status, err = result.GetInt64(ctx, i, 9); err != nil { + if status, err = result.GetInt64(ctx, i, 11); err != nil { return } subInfos = append(subInfos, &pubsub.SubInfo{ SubAccountId: int32(subAccountId), + SubAccountName: subAccountName, SubName: subName, SubTime: subTime, + PubAccountId: int32(pubAccountId), PubAccountName: pubAccountName, PubName: pubName, PubDbName: pubDbName, @@ -1352,16 +1357,17 @@ func getSqlForUpdatePubInfo(ctx context.Context, pubName string, accountList str func insertMoSubs(ctx context.Context, bh BackgroundExec, subInfo *pubsub.SubInfo) (err error) { ctx = defines.AttachAccountId(ctx, catalog.System_Account) - sql := fmt.Sprintf(insertIntoMoSubsFormat, subInfo.SubAccountId, subInfo.PubAccountName, subInfo.PubName, subInfo.PubDbName, subInfo.PubTables, subInfo.PubComment, subInfo.Status) + sql := fmt.Sprintf(insertIntoMoSubsFormat, subInfo.SubAccountId, subInfo.SubAccountName, subInfo.PubAccountId, subInfo.PubAccountName, subInfo.PubName, subInfo.PubDbName, subInfo.PubTables, subInfo.PubComment, subInfo.Status) return bh.Exec(ctx, sql) } func batchInsertMoSubs( ctx context.Context, bh BackgroundExec, - pubDbName, pubTables, pubComment string, - pubAccountName, pubName string, + pubAccountId int32, pubAccountName, + pubName, pubDbName, pubTables, pubComment string, accIds []int32, + accIdInfoMap map[int32]*pubsub.AccountInfo, ) (err error) { if len(accIds) == 0 { return @@ -1369,13 +1375,13 @@ func batchInsertMoSubs( ctx = defines.AttachAccountId(ctx, catalog.System_Account) values := make([]string, 0, len(accIds)) - // sub_account_id, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status - valuesFormat := "(%d, '%s', '%s', '%s', '%s', now(), '%s', %d)" + // sub_account_id, sub_account_name, pub_account_id, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status + valuesFormat := "(%d, '%s', %d, '%s', '%s', '%s', '%s', now(), '%s', %d)" for _, accId := range accIds { values = append(values, fmt.Sprintf(valuesFormat, - accId, - pubAccountName, pubName, - pubDbName, pubTables, pubComment, + accId, accIdInfoMap[accId].Name, + pubAccountId, pubAccountName, + pubName, pubDbName, pubTables, pubComment, pubsub.SubStatusNormal, )) } @@ -1608,18 +1614,14 @@ func dropSubAccountNameInSubAccounts(ctx context.Context, bh BackgroundExec, pub return bh.Exec(defines.AttachAccountId(ctx, catalog.System_Account), sql) } -func getSqlForInsertIntoMoPubs(ctx context.Context, pubName, databaseName string, databaseId uint64, allTable bool, tableList, accountList string, comment string, checkNameValid bool) (string, error) { +func getSqlForInsertIntoMoPubs(ctx context.Context, accountId uint32, accountName string, pubName, databaseName string, databaseId uint64, allTable bool, tableList, accountList string, comment string, checkNameValid bool) (string, error) { if checkNameValid { if err := inputNameIsInvalid(ctx, pubName, databaseName); err != nil { return "", err } } - accountId, err := defines.GetAccountId(ctx) - if err != nil { - return "", err - } - return fmt.Sprintf(insertIntoMoPubsFormat, accountId, pubName, databaseName, databaseId, allTable, tableList, accountList, defines.GetRoleId(ctx), defines.GetUserId(ctx), comment), nil + return fmt.Sprintf(insertIntoMoPubsFormat, accountId, accountName, pubName, databaseName, databaseId, allTable, tableList, accountList, defines.GetRoleId(ctx), defines.GetUserId(ctx), comment), nil } func getSqlForGetDbIdAndType(ctx context.Context, dbName string, checkNameValid bool, accountId uint64) (string, error) { diff --git a/pkg/frontend/publication_subscription_test.go b/pkg/frontend/publication_subscription_test.go index 0848910e95653..29e78cf149ec7 100644 --- a/pkg/frontend/publication_subscription_test.go +++ b/pkg/frontend/publication_subscription_test.go @@ -133,16 +133,17 @@ func Test_doAlterPublication(t *testing.T) { er := mock_frontend.NewMockExecResult(ctrl) er.EXPECT().GetRowCount().Return(uint64(1)).AnyTimes() er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(0)).Return(int64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("pub1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(2)).Return("db1", nil).AnyTimes() - er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(3)).Return(uint64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(4)).Return("*", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("sys", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(2)).Return("pub1", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(3)).Return("db1", nil).AnyTimes() + er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(4)).Return(uint64(0), nil).AnyTimes() er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(5)).Return("*", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("", nil).AnyTimes() - er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(7)).Return(true, nil).AnyTimes() - er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(8)).Return(uint64(0), nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("*", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(7)).Return("", nil).AnyTimes() + er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(8)).Return(true, nil).AnyTimes() er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(9)).Return(uint64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(10)).Return("", nil).AnyTimes() + er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(10)).Return(uint64(0), nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(11)).Return("", nil).AnyTimes() return []interface{}{er} } @@ -166,15 +167,17 @@ func Test_doAlterPublication(t *testing.T) { er := mock_frontend.NewMockExecResult(ctrl) er.EXPECT().GetRowCount().Return(uint64(1)).AnyTimes() er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(0)).Return(int64(1), nil).AnyTimes() - er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(1)).Return(true, nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("acc1", nil).AnyTimes() er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(2)).Return(true, nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(3)).Return("sys", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(4)).Return("pub1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(5)).Return("db1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("*", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(7)).Return("", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(8)).Return("", nil).AnyTimes() - er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(9)).Return(int64(0), nil).AnyTimes() + er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(3)).Return(true, nil).AnyTimes() + er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(4)).Return(int64(0), nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(5)).Return("sys", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("pub1", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(7)).Return("db1", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(8)).Return("*", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(9)).Return("", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(10)).Return("", nil).AnyTimes() + er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(11)).Return(int64(0), nil).AnyTimes() return []interface{}{er} } @@ -260,16 +263,17 @@ func Test_doAlterPublication2(t *testing.T) { er := mock_frontend.NewMockExecResult(ctrl) er.EXPECT().GetRowCount().Return(uint64(1)).AnyTimes() er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(0)).Return(int64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("pub1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(2)).Return("db1", nil).AnyTimes() - er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(3)).Return(uint64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(4)).Return("*", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("sys", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(2)).Return("pub1", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(3)).Return("db1", nil).AnyTimes() + er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(4)).Return(uint64(0), nil).AnyTimes() er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(5)).Return("*", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("", nil).AnyTimes() - er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(7)).Return(true, nil).AnyTimes() - er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(8)).Return(uint64(0), nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("*", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(7)).Return("", nil).AnyTimes() + er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(8)).Return(true, nil).AnyTimes() er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(9)).Return(uint64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(10)).Return("", nil).AnyTimes() + er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(10)).Return(uint64(0), nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(11)).Return("", nil).AnyTimes() return []interface{}{er} } @@ -332,37 +336,21 @@ func Test_doAlterPublication2(t *testing.T) { } func Test_doDropPublication(t *testing.T) { - mockedAccountsResults := func(ctrl *gomock.Controller) []interface{} { - er := mock_frontend.NewMockExecResult(ctrl) - er.EXPECT().GetRowCount().Return(uint64(2)).AnyTimes() - er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(0)).Return(int64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("sys", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(2)).Return("open", nil).AnyTimes() - er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(3)).Return(uint64(1), nil).AnyTimes() - er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(4)).Return(true, nil).AnyTimes() - - er.EXPECT().GetInt64(gomock.Any(), uint64(1), uint64(0)).Return(int64(1), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(1), uint64(1)).Return("acc1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(1), uint64(2)).Return("open", nil).AnyTimes() - er.EXPECT().GetUint64(gomock.Any(), uint64(1), uint64(3)).Return(uint64(1), nil).AnyTimes() - er.EXPECT().ColumnIsNull(gomock.Any(), uint64(1), uint64(4)).Return(true, nil).AnyTimes() - return []interface{}{er} - } - mockedPubInfoResults := func(ctrl *gomock.Controller) []interface{} { er := mock_frontend.NewMockExecResult(ctrl) er.EXPECT().GetRowCount().Return(uint64(1)).AnyTimes() er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(0)).Return(int64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("pub1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(2)).Return("db1", nil).AnyTimes() - er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(3)).Return(uint64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(4)).Return("*", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("sys", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(2)).Return("pub1", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(3)).Return("db1", nil).AnyTimes() + er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(4)).Return(uint64(0), nil).AnyTimes() er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(5)).Return("*", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("", nil).AnyTimes() - er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(7)).Return(true, nil).AnyTimes() - er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(8)).Return(uint64(0), nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("*", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(7)).Return("", nil).AnyTimes() + er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(8)).Return(true, nil).AnyTimes() er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(9)).Return(uint64(0), nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(10)).Return("", nil).AnyTimes() + er.EXPECT().GetUint64(gomock.Any(), uint64(0), uint64(10)).Return(uint64(0), nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(11)).Return("", nil).AnyTimes() return []interface{}{er} } @@ -370,15 +358,17 @@ func Test_doDropPublication(t *testing.T) { er := mock_frontend.NewMockExecResult(ctrl) er.EXPECT().GetRowCount().Return(uint64(1)).AnyTimes() er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(0)).Return(int64(1), nil).AnyTimes() - er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(1)).Return(true, nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("acc1", nil).AnyTimes() er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(2)).Return(true, nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(3)).Return("sys", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(4)).Return("pub1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(5)).Return("db1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("*", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(7)).Return("", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(8)).Return("", nil).AnyTimes() - er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(9)).Return(int64(0), nil).AnyTimes() + er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(3)).Return(true, nil).AnyTimes() + er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(4)).Return(int64(0), nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(5)).Return("sys", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("pub1", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(7)).Return("db1", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(8)).Return("*", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(9)).Return("", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(10)).Return("", nil).AnyTimes() + er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(11)).Return(int64(0), nil).AnyTimes() return []interface{}{er} } @@ -396,9 +386,6 @@ func Test_doDropPublication(t *testing.T) { bh := mock_frontend.NewMockBackgroundExec(ctrl) bh.EXPECT().Close().Return().AnyTimes() bh.EXPECT().ClearExecResultSet().Return().AnyTimes() - // get all accounts - bh.EXPECT().Exec(gomock.Any(), getAccountIdNamesSql).Return(nil).AnyTimes() - bh.EXPECT().GetExecResultSet().Return(mockedAccountsResults(ctrl)) // get pub info bh.EXPECT().Exec(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() bh.EXPECT().GetExecResultSet().Return(mockedPubInfoResults(ctrl)) @@ -408,7 +395,7 @@ func Test_doDropPublication(t *testing.T) { // deleteMoSubs bh.EXPECT().Exec(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() - err := dropPublication(ctx, bh, true, "pub") + err := dropPublication(ctx, bh, true, "acc1", "pub") convey.So(err, convey.ShouldBeNil) }) } @@ -437,7 +424,7 @@ func TestGetSqlForInsertIntoMoPubs(t *testing.T) { }, } for _, k := range kases { - _, err := getSqlForInsertIntoMoPubs(ctx, k.pubName, k.databaseName, 0, false, "", "", "", true) + _, err := getSqlForInsertIntoMoPubs(ctx, 0, "sys", k.pubName, k.databaseName, 0, false, "", "", "", true) require.Equal(t, k.err, err != nil) } } @@ -499,15 +486,17 @@ func Test_doShowSubscriptions(t *testing.T) { er := mock_frontend.NewMockExecResult(ctrl) er.EXPECT().GetRowCount().Return(uint64(1)).AnyTimes() er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(0)).Return(int64(1), nil).AnyTimes() - er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(1)).Return(true, nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(1)).Return("acc1", nil).AnyTimes() er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(2)).Return(true, nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(3)).Return("sys", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(4)).Return("pub1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(5)).Return("db1", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("*", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(7)).Return("2024-10-10 11:12:00", nil).AnyTimes() - er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(8)).Return("", nil).AnyTimes() - er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(9)).Return(int64(0), nil).AnyTimes() + er.EXPECT().ColumnIsNull(gomock.Any(), uint64(0), uint64(3)).Return(true, nil).AnyTimes() + er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(4)).Return(int64(0), nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(5)).Return("sys", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(6)).Return("pub1", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(7)).Return("db1", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(8)).Return("*", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(9)).Return("2024-10-10 11:12:00", nil).AnyTimes() + er.EXPECT().GetString(gomock.Any(), uint64(0), uint64(10)).Return("", nil).AnyTimes() + er.EXPECT().GetInt64(gomock.Any(), uint64(0), uint64(11)).Return(int64(0), nil).AnyTimes() return []interface{}{er} } diff --git a/pkg/frontend/snapshot.go b/pkg/frontend/snapshot.go index 967b451b8a3aa..5404d22137221 100644 --- a/pkg/frontend/snapshot.go +++ b/pkg/frontend/snapshot.go @@ -72,7 +72,7 @@ var ( getCurrentExistsAccountsFmt = "select account_id, account_name from mo_catalog.mo_account;" - getSubsSqlFmt = "select sub_account_id, sub_name, sub_time, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status from mo_catalog.mo_subs %s where 1=1" + getSubsSqlFmt = "select sub_account_id, sub_account_name, sub_name, sub_time, pub_account_id, pub_account_name, pub_name, pub_database, pub_tables, pub_time, pub_comment, status from mo_catalog.mo_subs %s where 1=1" checkTableIsMasterFormat = "select db_name, table_name from mo_catalog.mo_foreign_keys where refer_db_name = '%s' and refer_table_name = '%s'" @@ -2310,7 +2310,7 @@ func dropDb(ctx context.Context, bh BackgroundExec, dbName string) (err error) { return err } for _, pubInfo := range pubInfos { - if err = dropPublication(ctx, bh, true, pubInfo.PubName); err != nil { + if err = dropPublication(ctx, bh, true, pubInfo.PubAccountName, pubInfo.PubName); err != nil { return } } diff --git a/test/distributed/cases/foreign_key/fk_show_columns.result b/test/distributed/cases/foreign_key/fk_show_columns.result index ecacd9e9776c7..c01ae47fce366 100644 --- a/test/distributed/cases/foreign_key/fk_show_columns.result +++ b/test/distributed/cases/foreign_key/fk_show_columns.result @@ -203,6 +203,7 @@ partition_table_name VARCHAR(1024) NO null desc mo_catalog.mo_pubs ; Field Type Null Key Default Extra Comment account_id INT(32) NO PRI null +account_name VARCHAR(300) YES null pub_name VARCHAR(64) NO PRI null database_name VARCHAR(5000) YES null database_id BIGINT UNSIGNED(64) YES null @@ -526,6 +527,7 @@ partition_table_name VARCHAR(1024) NO null show columns from mo_catalog.mo_pubs ; Field Type Null Key Default Extra Comment account_id INT(32) NO PRI null +account_name VARCHAR(300) YES null pub_name VARCHAR(64) NO PRI null database_name VARCHAR(5000) YES null database_id BIGINT UNSIGNED(64) YES null diff --git a/test/distributed/cases/publication_subscription/pub_sub3.result b/test/distributed/cases/publication_subscription/pub_sub3.result index 286abb34d3e8a..37c463487aafb 100644 --- a/test/distributed/cases/publication_subscription/pub_sub3.result +++ b/test/distributed/cases/publication_subscription/pub_sub3.result @@ -69,11 +69,11 @@ create publication pub03 database db02 table t1, t2 account acc02 comment 'publi drop database if exists sub02; create database sub02 from acc01 publication pub01; select * from mo_catalog.mo_subs; -sub_account_id sub_name sub_time pub_account_name pub_name pub_database pub_tables pub_time pub_comment status -67 null null acc01 pub02 db02 * 2024-08-14 18:34:52 publish to acc01 and acc03 0 -66 null null acc01 pub02 db02 * 2024-08-14 18:34:52 publish to acc01 and acc03 0 -66 null null acc01 pub03 db02 t1,t2 2024-08-14 18:34:52 publish to acc02 0 -66 sub02 2024-08-14 18:34:52 acc01 pub01 db02 * 2024-08-14 18:34:52 publish to acc01 0 +sub_account_id sub_account_name sub_name sub_time pub_account_id pub_account_name pub_name pub_database pub_tables pub_time pub_comment status +4 acc02 null null 3 acc01 pub02 db02 * 2024-12-31 18:14:15 publish to acc01 and acc03 0 +5 acc03 null null 3 acc01 pub02 db02 * 2024-12-31 18:14:15 publish to acc01 and acc03 0 +4 acc02 null null 3 acc01 pub03 db02 t1,t2 2024-12-31 18:14:15 publish to acc02 0 +4 acc02 sub02 2024-12-31 18:14:15 3 acc01 pub01 db02 * 2024-12-31 18:14:15 publish to acc01 0 drop database sub02; drop publication pub01; drop publication pub02; diff --git a/test/distributed/cases/publication_subscription/pub_sub3.sql b/test/distributed/cases/publication_subscription/pub_sub3.sql index 8241e2521b31f..1fd3fca27044e 100644 --- a/test/distributed/cases/publication_subscription/pub_sub3.sql +++ b/test/distributed/cases/publication_subscription/pub_sub3.sql @@ -81,7 +81,7 @@ drop database if exists sub02; create database sub02 from acc01 publication pub01; -- @session --- @ignore:0,2,7 +-- @ignore:0,3,4,9 select * from mo_catalog.mo_subs; -- @session:id=2&user=acc02:test_account&password=111 diff --git a/test/distributed/cases/snapshot/cluster_level_snapshot_restore_cluster.sql b/test/distributed/cases/snapshot/cluster_level_snapshot_restore_cluster.sql index 45c4144982672..f250702ad7707 100644 --- a/test/distributed/cases/snapshot/cluster_level_snapshot_restore_cluster.sql +++ b/test/distributed/cases/snapshot/cluster_level_snapshot_restore_cluster.sql @@ -199,7 +199,7 @@ drop publication if exists pub02; create publication pub02 database repub02 account acc02 comment 'publish before creating snapshot'; -- @ignore:5,6 show publications; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; drop database if exists procedure_test; diff --git a/test/distributed/cases/snapshot/cluster_level_snapshot_restore_pubsub.result b/test/distributed/cases/snapshot/cluster_level_snapshot_restore_pubsub.result index 309a89b1d2126..040bcc292f5d7 100644 --- a/test/distributed/cases/snapshot/cluster_level_snapshot_restore_pubsub.result +++ b/test/distributed/cases/snapshot/cluster_level_snapshot_restore_pubsub.result @@ -15,13 +15,13 @@ show publications; publication database tables sub_account subscribed_accounts create_time update_time comments publication01 republication01 * acc01 2024-11-14 16:28:52 null publish before creating snapshot select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 publication01 republication01 273171 true * acc01 2024-11-14 16:28:52 null 0 1 publish before creating snapshot +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys publication01 republication01 272993 true * acc01 2024-12-31 18:15:27 null 0 1 publish before creating snapshot drop publication publication01; drop database republication01; restore account sys from snapshot sp01; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment use republication01; select * from repub01; col1 @@ -72,8 +72,8 @@ show publications; publication database tables sub_account subscribed_accounts create_time update_time comments pub02 repub02 * acc01 2024-11-14 16:28:52 null publish before creating snapshot select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 pub02 repub02 273197 true * acc01 2024-11-14 16:28:52 null 0 1 publish before creating snapshot +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys pub02 repub02 273019 true * acc01 2024-12-31 18:15:27 null 0 1 publish before creating snapshot drop database if exists sub01; create database sub01 from sys publication pub02; show databases; @@ -106,7 +106,7 @@ restore account sys from snapshot sp02; show publications; publication database tables sub_account subscribed_accounts create_time update_time comments select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment use repub02; select * from pri01; deptno dname loc @@ -208,8 +208,8 @@ system system_metrics drop snapshot sp01; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 pub03 repub03 273225 true * acc01 2024-11-14 16:28:53 null 0 1 create repub03 +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys pub03 repub03 273048 true * acc01 2024-12-31 18:15:28 null 0 1 create repub03 show publications; publication database tables sub_account subscribed_accounts create_time update_time comments pub03 repub03 * acc01 2024-11-14 16:28:53 null create repub03 @@ -230,8 +230,8 @@ create snapshot sp02 for cluster; drop publication if exists pub04; create publication pub04 database db01 account acc01 comment 'create pub04'; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 pub04 db01 273243 true * acc01 2024-11-14 16:28:53 null 0 1 create pub04 +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys pub04 db01 273066 true * acc01 2024-12-31 18:15:28 null 0 1 create pub04 show publications; publication database tables sub_account subscribed_accounts create_time update_time comments pub04 db01 * acc01 2024-11-14 16:28:53 null create pub04 @@ -458,8 +458,8 @@ create snapshot sp100 for cluster; drop publication if exists pub07; create publication pub07 database test01 account acc01 comment 'publish test01'; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 pub07 test01 273400 true * acc01 2024-11-14 16:28:55 null 0 1 publish test01 +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys pub07 test01 273223 true * acc01 2024-12-31 18:15:31 null 0 1 publish test01 drop snapshot if exists sp101; create snapshot sp101 for cluster; drop database if exists sub07; @@ -481,7 +481,7 @@ use sub07; internal error: there is no publication pub07 restore account sys from snapshot sp101; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment show databases; Database information_schema diff --git a/test/distributed/cases/snapshot/cluster_level_snapshot_restore_pubsub.sql b/test/distributed/cases/snapshot/cluster_level_snapshot_restore_pubsub.sql index 21feca626a49d..c3ad3136248d2 100644 --- a/test/distributed/cases/snapshot/cluster_level_snapshot_restore_pubsub.sql +++ b/test/distributed/cases/snapshot/cluster_level_snapshot_restore_pubsub.sql @@ -17,13 +17,13 @@ drop publication if exists publication01; create publication publication01 database republication01 account acc01 comment 'publish before creating snapshot'; -- @ignore:5,6 show publications; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; drop publication publication01; drop database republication01; restore account sys from snapshot sp01; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; use republication01; select * from repub01; @@ -81,7 +81,7 @@ drop publication if exists pub02; create publication pub02 database repub02 account acc01 comment 'publish before creating snapshot'; -- @ignore:5,6 show publications; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session:id=1&user=acc01:test_account&password=111 @@ -97,7 +97,7 @@ select * from aff01; restore account sys from snapshot sp02; -- @ignore:5,6 show publications; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; use repub02; select * from pri01; @@ -163,7 +163,7 @@ show subscriptions; show databases; -- @session drop snapshot sp01; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @ignore:5,6 show publications; @@ -190,7 +190,7 @@ create snapshot sp02 for cluster; drop publication if exists pub04; create publication pub04 database db01 account acc01 comment 'create pub04'; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @ignore:5,6 show publications; @@ -419,7 +419,7 @@ create snapshot sp100 for cluster; drop publication if exists pub07; create publication pub07 database test01 account acc01 comment 'publish test01'; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; drop snapshot if exists sp101; @@ -440,7 +440,7 @@ use sub07; -- @session restore account sys from snapshot sp101; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session:id=1&user=acc01:test_account&password=111 @@ -605,7 +605,7 @@ create snapshot sp105 for cluster; -- @session:id=1&user=acc01:test_account&password=111 drop publication if exists pub10; create publication pub10 database test04 account acc02 comment 'publish test03'; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session diff --git a/test/distributed/cases/snapshot/sys_restore_pubsub_to_sys_account.result b/test/distributed/cases/snapshot/sys_restore_pubsub_to_sys_account.result index 112f355b9b8a6..c018bea0b4252 100644 --- a/test/distributed/cases/snapshot/sys_restore_pubsub_to_sys_account.result +++ b/test/distributed/cases/snapshot/sys_restore_pubsub_to_sys_account.result @@ -15,13 +15,13 @@ show publications; publication database tables sub_account subscribed_accounts create_time update_time comments publication01 republication01 * acc01 2024-12-31 11:10:09 null publish before creating snapshot select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 publication01 republication01 276733 true * acc01 2024-12-31 11:10:09 null 0 1 publish before creating snapshot +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys publication01 republication01 272592 true * acc01 2025-01-03 12:59:36 null 0 1 publish before creating snapshot drop publication publication01; drop database republication01; restore account sys from snapshot sp01; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment show databases; Database information_schema @@ -83,8 +83,8 @@ show publications; publication database tables sub_account subscribed_accounts create_time update_time comments pub02 repub02 * acc01 2024-12-31 11:10:10 null publish before creating snapshot select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 pub02 repub02 276760 true * acc01 2024-12-31 11:10:10 null 0 1 publish before creating snapshot +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys pub02 repub02 272618 true * acc01 2025-01-03 12:59:37 null 0 1 publish before creating snapshot drop database if exists sub01; create database sub01 from sys publication pub02; show databases; @@ -117,7 +117,7 @@ restore account sys from snapshot sp02; show publications; publication database tables sub_account subscribed_accounts create_time update_time comments select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment show databases; Database information_schema @@ -230,8 +230,8 @@ system system_metrics drop snapshot sp01; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 pub03 repub03 276791 true * acc01 2024-12-31 11:10:12 null 0 1 create repub03 +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys pub03 repub03 272647 true * acc01 2025-01-03 12:59:38 null 0 1 create repub03 show databases; Database information_schema @@ -263,8 +263,8 @@ create snapshot sp02 for account acc01; drop publication if exists pub03; create publication pub04 database db01 account acc01 comment 'create pub04'; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 pub04 db01 276809 true * acc01 2024-12-31 11:10:15 null 0 1 create pub04 +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys pub04 db01 272665 true * acc01 2025-01-03 12:59:39 null 0 1 create pub04 show publications; publication database tables sub_account subscribed_accounts create_time update_time comments pub04 db01 * acc01 2024-12-31 11:10:15 null create pub04 @@ -472,8 +472,8 @@ create snapshot sp100 for account; drop publication if exists pub07; create publication pub07 database test01 account acc01 comment 'publish test01'; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -0 pub07 test01 276965 true * acc01 2024-12-31 11:10:22 null 0 1 publish test01 +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +0 sys pub07 test01 272822 true * acc01 2025-01-03 12:59:40 null 0 1 publish test01 drop snapshot if exists sp101; create snapshot sp101 for account; drop database if exists sub07; @@ -495,7 +495,7 @@ use sub07; internal error: there is no publication pub07 restore account sys from snapshot sp101; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment show databases; Database information_schema @@ -696,8 +696,8 @@ a b 3 2 restore account acc02 from snapshot sp105 to account acc03; select * from mo_catalog.mo_pubs; -account_id pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment -20 pub10 test04 277227 true * acc02 2024-12-31 11:10:31 null 2 2 publish test03 +account_id account_name pub_name database_name database_id all_table table_list account_list created_time update_time owner creator comment +1 acc01 pub10 test04 273081 true * acc02 2025-01-03 12:59:43 null 2 2 publish test03 show databases; Database information_schema diff --git a/test/distributed/cases/snapshot/sys_restore_pubsub_to_sys_account.sql b/test/distributed/cases/snapshot/sys_restore_pubsub_to_sys_account.sql index 7a2f4848c2387..3f581bf2e066c 100644 --- a/test/distributed/cases/snapshot/sys_restore_pubsub_to_sys_account.sql +++ b/test/distributed/cases/snapshot/sys_restore_pubsub_to_sys_account.sql @@ -17,13 +17,13 @@ drop publication if exists publication01; create publication publication01 database republication01 account acc01 comment 'publish before creating snapshot'; -- @ignore:5,6 show publications; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; drop publication publication01; drop database republication01; restore account sys from snapshot sp01; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; show databases; use republication01; @@ -82,7 +82,7 @@ drop publication if exists pub02; create publication pub02 database repub02 account acc01 comment 'publish before creating snapshot'; -- @ignore:5,6 show publications; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session:id=1&user=acc01:test_account&password=111 @@ -98,7 +98,7 @@ select * from aff01; restore account sys from snapshot sp02; -- @ignore:5,6 show publications; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; show databases; use repub02; @@ -161,7 +161,7 @@ show subscriptions; show databases; drop snapshot sp01; -- @session --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; show databases; -- @ignore:5,6 @@ -190,7 +190,7 @@ create snapshot sp02 for account acc01; drop publication if exists pub03; create publication pub04 database db01 account acc01 comment 'create pub04'; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @ignore:5,6 show publications; @@ -336,7 +336,7 @@ create snapshot sp11 for account acc01; drop publication if exists pub06; create publication pub06 database db10 account acc02 comment 'publish db10'; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session @@ -357,7 +357,7 @@ restore account acc01 from snapshot sp11; show publications; show databases; drop database db10; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session @@ -386,7 +386,7 @@ create snapshot sp100 for account; drop publication if exists pub07; create publication pub07 database test01 account acc01 comment 'publish test01'; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; drop snapshot if exists sp101; @@ -407,7 +407,7 @@ use sub07; -- @session restore account sys from snapshot sp101; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session:id=1&user=acc01:test_account&password=111 @@ -571,7 +571,7 @@ create snapshot sp105 for account acc02; -- @session:id=1&user=acc01:test_account&password=111 drop publication if exists pub10; create publication pub10 database test04 account acc02 comment 'publish test03'; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session @@ -584,7 +584,7 @@ select * from t1; -- @session restore account acc02 from snapshot sp105 to account acc03; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session:id=4&user=acc03:test_account&password=111 @@ -594,7 +594,7 @@ select * from t1; -- @ignore:5,6 show publications; drop database sub09; --- @ignore:0,3,7 +-- @ignore:0,4,8,9 select * from mo_catalog.mo_pubs; -- @session