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

feat: support recommended backup strategies and row backups #2786

Merged
merged 14 commits into from
Nov 29, 2024
Merged
20 changes: 20 additions & 0 deletions sqle/driver/mysql/backup_ce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//go:build !enterprise
// +build !enterprise

package mysql

import (
"context"
"fmt"
"github.com/actiontech/sqle/sqle/driver"
)

var ErrUnsupportedBackup error = fmt.Errorf("backup is unsupported for sqle community version")

func (i *MysqlDriverImpl) Backup(ctx context.Context, backupStrategy string, sql string) (BackupSql []string, ExecuteInfo string, err error) {
return nil, "", ErrUnsupportedBackup
}

func (i *MysqlDriverImpl) GetBackupStrategy(ctx context.Context, sql string) (*driver.GetBackupStrategyRes, error) {
return nil, ErrUnsupportedBackup
}
8 changes: 5 additions & 3 deletions sqle/driver/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (inspect *MysqlDriverImpl) applyConfig(cfg *driverV2.Config) {
inspect.isOfflineAudit = cfg.DSN == nil

inspect.cnf = &Config{
DMLRollbackMaxRows: 1000,// TODO 暂时将备份影响行数上限设置为1000,后续需要将对应该配置项的规则移除。备份影响行数上限设置将会在备份任务中设置。
DMLRollbackMaxRows: 1000,
DDLOSCMinSize: -1,
DDLGhostMinSize: -1,
}
Expand Down Expand Up @@ -631,7 +631,7 @@ func (p *PluginProcessor) GetDriverMetas() (*driverV2.DriverMetas, error) {
for i := range rulepkg.RuleHandlers {
allRules[i] = &rulepkg.RuleHandlers[i].Rule
}
return &driverV2.DriverMetas{
metas := &driverV2.DriverMetas{
PluginName: driverV2.DriverTypeMySQL,
DatabaseDefaultPort: 3306,
Logo: logo,
Expand All @@ -648,7 +648,9 @@ func (p *PluginProcessor) GetDriverMetas() (*driverV2.DriverMetas, error) {
driverV2.OptionalExecBatch,
driverV2.OptionalModuleI18n,
},
}, nil
}
addOptionModules(metas)
return metas, nil
}

func (p *PluginProcessor) Open(l *logrus.Entry, cfg *driverV2.Config) (driver.Plugin, error) {
Expand Down
2 changes: 2 additions & 0 deletions sqle/driver/mysql/mysql_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ func (i *MysqlDriverImpl) GetDatabaseDiffModifySQL(ctx context.Context, calibrat
func (i *MysqlDriverImpl) GetDatabaseObjectDDL(ctx context.Context, objInfos []*driverV2.DatabasSchemaInfo) ([]*driverV2.DatabaseSchemaObjectResult, error) {
return nil, fmt.Errorf("only support Query in enterprise edition")
}

func addOptionModules(metas *driverV2.DriverMetas) {}
winfredLIN marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions sqle/driver/plugin_adapter_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ type PluginImplV1 struct {
driverV1.DriverManager
}

func (d *PluginImplV1) Backup(ctx context.Context, backupStrategy string, sql string) (backupSql []string, executeInfo string, err error) {
return nil, "", nil
}

func (d *PluginImplV1) GetBackupStrategy(ctx context.Context, sql string) (*GetBackupStrategyRes, error) {
return nil, nil
}

func (p *PluginImplV1) Close(ctx context.Context) {
p.DriverManager.Close(ctx)
}
Expand Down
24 changes: 24 additions & 0 deletions sqle/driver/plugin_adapter_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,30 @@ type PluginImplV2 struct {
meta *driverV2.DriverMetas
}

func (s *PluginImplV2) Backup(ctx context.Context, backupStrategy string, sql string) (BackupSql []string, ExecuteInfo string, err error) {
api := "Backup"
s.preLog(api)
var strategy protoV2.BackupStrategy = protoV2.BackupStrategy_ReverseSql
switch backupStrategy {
case "reverse_sql":
strategy = protoV2.BackupStrategy_ReverseSql
}
resp, err := s.client.Backup(ctx, &protoV2.BackupReq{
Session: s.Session,
BackupStrategy: strategy,
Sql: sql,
})
s.afterLog(api, err)
if err != nil {
return nil, "", err
}
return resp.GetBackupSql(), resp.GetExecuteInfo(), nil
}

func (p *PluginImplV2) GetBackupStrategy(ctx context.Context, sql string) (*GetBackupStrategyRes, error) {
return nil, nil
winfredLIN marked this conversation as resolved.
Show resolved Hide resolved
}

func (s *PluginImplV2) preLog(ApiName string) {
s.l.Infof("starting call plugin interface [%s]", ApiName)
}
Expand Down
11 changes: 11 additions & 0 deletions sqle/driver/plugin_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ type Plugin interface {
GetDatabaseObjectDDL(ctx context.Context, objInfos []*driverV2.DatabasSchemaInfo) ([]*driverV2.DatabaseSchemaObjectResult, error)

GetDatabaseDiffModifySQL(ctx context.Context, calibratedDSN *driverV2.DSN, objInfos []*driverV2.DatabasCompareSchemaInfo) ([]*driverV2.DatabaseDiffModifySQLResult, error)

Backup(ctx context.Context, backupStrategy string, sql string) (BackupSql []string, ExecuteInfo string, err error)

GetBackupStrategy(ctx context.Context, sql string) (*GetBackupStrategyRes, error)
winfredLIN marked this conversation as resolved.
Show resolved Hide resolved
}

type GetBackupStrategyRes struct {
BackupStrategy string
BackupStrategyTip string
TablesRefer []string
SchemasRefer []string
}

type PluginProcessor interface {
Expand Down
8 changes: 8 additions & 0 deletions sqle/driver/v2/driver_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ func (d *DriverGrpcServer) getDriverBySession(session *protoV2.Session) (Driver,
return nil, fmt.Errorf("session %s not found", session.Id)
}
return driver, nil

}
func (d *DriverGrpcServer) Backup(ctx context.Context, req *protoV2.BackupReq) (*protoV2.BackupRes, error) {
return nil, nil
winfredLIN marked this conversation as resolved.
Show resolved Hide resolved
}

func (d *DriverGrpcServer) GetBackupStrategy(ctx context.Context, req *protoV2.GetBackupStrategyReq) (*protoV2.GetBackupStrategyRes, error) {
return nil, nil
winfredLIN marked this conversation as resolved.
Show resolved Hide resolved
}

func (d *DriverGrpcServer) Metas(ctx context.Context, req *protoV2.Empty) (*protoV2.MetasResponse, error) {
Expand Down
24 changes: 24 additions & 0 deletions sqle/driver/v2/driver_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ type Driver interface {
KillProcess(ctx context.Context) (*KillProcessInfo, error)
GetDatabaseObjectDDL(ctx context.Context, objInfos []*DatabasSchemaInfo) ([]*DatabaseSchemaObjectResult, error)
GetDatabaseDiffModifySQL(ctx context.Context, calibratedDSN *DSN, objInfos []*DatabasCompareSchemaInfo) ([]*DatabaseDiffModifySQLResult, error)

Backup(ctx context.Context, req *BackupReq) (*BackupRes, error)
GetBackupStrategy(ctx context.Context, req *GetBackupStrategyReq) (*GetBackupStrategyRes, error)
}

type BackupReq struct {
BackupStrategy string
Sql string
}

type BackupRes struct {
BackupSql []string
ExecuteInfo string
}

type GetBackupStrategyReq struct {
Sql string
}

type GetBackupStrategyRes struct {
BackupStrategy string
BackupStrategyTip string
TablesRefer []string
SchemasRefer []string
}

type Node struct {
Expand Down
Loading
Loading