github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/glue/glue.go (about) 1 // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0. 2 3 package glue 4 5 import ( 6 "context" 7 8 "github.com/pingcap/parser/model" 9 "github.com/pingcap/tidb/domain" 10 "github.com/pingcap/tidb/kv" 11 pd "github.com/tikv/pd/client" 12 ) 13 14 // Glue is an abstraction of TiDB function calls used in BR. 15 type Glue interface { 16 GetDomain(store kv.Storage) (*domain.Domain, error) 17 CreateSession(store kv.Storage) (Session, error) 18 Open(path string, option pd.SecurityOption) (kv.Storage, error) 19 20 // OwnsStorage returns whether the storage returned by Open() is owned 21 // If this method returns false, the connection manager will never close the storage. 22 OwnsStorage() bool 23 24 StartProgress(ctx context.Context, cmdName string, total int64, redirectLog bool) Progress 25 26 // Record records some information useful for log-less summary. 27 Record(name string, value uint64) 28 29 // GetVersion gets BR package version to run backup/restore job 30 GetVersion() string 31 } 32 33 // Session is an abstraction of the session.Session interface. 34 type Session interface { 35 Execute(ctx context.Context, sql string) error 36 CreateDatabase(ctx context.Context, schema *model.DBInfo) error 37 CreateTable(ctx context.Context, dbName model.CIStr, table *model.TableInfo) error 38 Close() 39 } 40 41 // Progress is an interface recording the current execution progress. 42 type Progress interface { 43 // Inc increases the progress. This method must be goroutine-safe, and can 44 // be called from any goroutine. 45 Inc() 46 // Close marks the progress as 100% complete and that Inc() can no longer be 47 // called. 48 Close() 49 }