Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
move tikv.driver to glue
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer committed Feb 24, 2020
1 parent 927fca9 commit 8e7df8e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pkg/glue/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/pingcap/parser/model"
pd "github.com/pingcap/pd/client"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta/autoid"
Expand All @@ -13,6 +14,7 @@ import (
type Glue interface {
BootstrapSession(store kv.Storage) (*domain.Domain, error)
CreateSession(store kv.Storage) (Session, error)
Open(path string, option pd.SecurityOption) (kv.Storage, error)
}

// Session is an abstraction of the session.Session interface.
Expand Down
15 changes: 15 additions & 0 deletions pkg/gluetidb/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"context"

"github.com/pingcap/parser/model"
pd "github.com/pingcap/pd/client"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/tikv"

"github.com/pingcap/br/pkg/glue"
)
Expand All @@ -35,6 +38,18 @@ func (Glue) CreateSession(store kv.Storage) (glue.Session, error) {
return &tidbSession{se: se}, nil
}

// Open implements glue.Glue
func (Glue) Open(path string, option pd.SecurityOption) (kv.Storage, error) {
if option.CAPath != "" {
conf := config.GetGlobalConfig()
conf.Security.ClusterSSLCA = option.CAPath
conf.Security.ClusterSSLCert = option.CertPath
conf.Security.ClusterSSLKey = option.KeyPath
config.StoreGlobalConfig(conf)
}
return tikv.Driver{}.Open(path)
}

// Execute implements glue.Session
func (gs *tidbSession) Execute(ctx context.Context, sql string) error {
_, err := gs.se.Execute(ctx, sql)
Expand Down
9 changes: 1 addition & 8 deletions pkg/task/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/pingcap/kvproto/pkg/backup"
pd "github.com/pingcap/pd/client"
"github.com/pingcap/tidb-tools/pkg/filter"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/store/tikv"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -214,12 +213,6 @@ func newMgr(ctx context.Context, g glue.Glue, pds []string, tlsConfig TLSConfig)

securityOption := pd.SecurityOption{}
if tlsConfig.IsEnabled() {
conf := config.GetGlobalConfig()
conf.Security.ClusterSSLCA = tlsConfig.CA
conf.Security.ClusterSSLCert = tlsConfig.Cert
conf.Security.ClusterSSLKey = tlsConfig.Key
config.StoreGlobalConfig(conf)

securityOption.CAPath = tlsConfig.CA
securityOption.CertPath = tlsConfig.Cert
securityOption.KeyPath = tlsConfig.Key
Expand All @@ -230,7 +223,7 @@ func newMgr(ctx context.Context, g glue.Glue, pds []string, tlsConfig TLSConfig)
}

// Disable GC because TiDB enables GC already.
store, err := tikv.Driver{}.Open(fmt.Sprintf("tikv://%s?disableGC=true", pdAddress))
store, err := g.Open(fmt.Sprintf("tikv://%s?disableGC=true", pdAddress), securityOption)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 8e7df8e

Please sign in to comment.