Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support restore cluster by pitr #17796

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions pkg/frontend/pitr.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,6 @@ func doRestorePitr(ctx context.Context, ses *Session, stmt *tree.RestorePitr) (e
return moerr.NewInternalError(ctx, "pitr %s does not exist", pitrName)
}

// check privilege
// only sys account can restore other account's pitr
if len(srcAccountName) != 0 && tenantInfo.GetTenant() != sysAccountName {
return moerr.NewInternalError(ctx, "only sys account can restore other account's pitr")
}

// check if the database can be restore
if len(dbName) != 0 && needSkipDb(dbName) {
return moerr.NewInternalError(ctx, "database %s can not be restore", dbName)
Expand Down Expand Up @@ -787,6 +781,10 @@ func doRestorePitr(ctx context.Context, ses *Session, stmt *tree.RestorePitr) (e

// restore according the restore level
switch restoreLevel {
case tree.RESTORELEVELCLUSTER:
if err = restoreToCluster(ctx, ses, bh, pitrName, ts); err != nil {
return
}
case tree.RESTORELEVELACCOUNT:
if err = restoreToAccountWithPitr(ctx, ses.GetService(), bh, pitrName, ts, fkTableMap, viewMap, tenantInfo.TenantID); err != nil {
return
Expand Down Expand Up @@ -1527,6 +1525,16 @@ func addTimeSpan(length int, unit string) (time.Time, error) {
func checkPitrValidOrNot(pitrRecord *pitrRecord, stmt *tree.RestorePitr, tenantInfo *TenantInfo) (err error) {
restoreLevel := stmt.Level
switch restoreLevel {
case tree.RESTORELEVELCLUSTER:
// check the level
// if the pitr level is account/ database/table, return err
if pitrRecord.level == tree.PITRLEVELACCOUNT.String() || pitrRecord.level == tree.PITRLEVELDATABASE.String() || pitrRecord.level == tree.PITRLEVELTABLE.String() {
return moerr.NewInternalErrorNoCtx("restore level %v is not allowed for cluster restore", pitrRecord.level)
}
// if the accout not sys account, return err
if tenantInfo.GetTenantID() != sysAccountID {
return moerr.NewInternalErrorNoCtx("account %s is not allowed to restore cluster level pitr %s", tenantInfo.GetTenant(), pitrRecord.pitrName)
}
case tree.RESTORELEVELACCOUNT:

if len(stmt.AccountName) == 0 { // restore self account
Expand All @@ -1537,8 +1545,16 @@ func checkPitrValidOrNot(pitrRecord *pitrRecord, stmt *tree.RestorePitr, tenantI
if pitrRecord.level == tree.PITRLEVELACCOUNT.String() && pitrRecord.accountId != uint64(tenantInfo.TenantID) {
return moerr.NewInternalErrorNoCtx("pitr %s is not allowed to restore account %v", pitrRecord.pitrName, tenantInfo.GetTenant())
}
// if the pitr level is cluster, the tenant must be sys account
if pitrRecord.level == tree.PITRLEVELCLUSTER.String() && tenantInfo.GetTenantID() != sysAccountID {
return moerr.NewInternalErrorNoCtx("account %s is not allowed to restore cluster level pitr %s", tenantInfo.GetTenant(), pitrRecord.pitrName)
}
} else {
// sys restore other account's pitr
// if the accout not sys account, return err
if tenantInfo.GetTenantID() != sysAccountID {
return moerr.NewInternalErrorNoCtx("account %s is not allowed to restore other account %s", tenantInfo.GetTenant(), string(stmt.AccountName))
}
// if the pitr level is cluster, the scource account can not be empty
if pitrRecord.level == tree.PITRLEVELCLUSTER.String() && len(stmt.SrcAccountName) == 0 {
return moerr.NewInternalErrorNoCtx("source account %s can not be empty when restore cluster level pitr %s", string(stmt.AccountName), pitrRecord.pitrName)
Expand Down
Loading
Loading