From 7a275a77bb5c746b23a4e409cdc002ca6bcf5552 Mon Sep 17 00:00:00 2001 From: disksing Date: Wed, 3 Feb 2021 00:59:57 -0600 Subject: [PATCH] store/tikv: move EtcdBackend out (#22676) Signed-off-by: disksing --- domain/domain.go | 2 +- executor/infoschema_reader.go | 3 ++- executor/split.go | 2 +- infoschema/tables.go | 2 +- kv/kv.go | 8 ++++++++ server/http_handler.go | 2 +- session/session.go | 2 +- session/session_test.go | 4 ++-- store/helper/helper.go | 8 ++++---- store/tikv/kv.go | 7 ------- 10 files changed, 21 insertions(+), 19 deletions(-) diff --git a/domain/domain.go b/domain/domain.go index ac0ddc2ea73bc..d74dd3c1762b4 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -700,7 +700,7 @@ const serverIDForStandalone = 1 // serverID for standalone deployment. // Init initializes a domain. func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.Resource, error)) error { perfschema.Init() - if ebd, ok := do.store.(tikv.EtcdBackend); ok { + if ebd, ok := do.store.(kv.EtcdBackend); ok { var addrs []string var err error if addrs, err = ebd.EtcdAddrs(); err != nil { diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index 83969ea3991b9..0691b748fc1eb 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -36,6 +36,7 @@ import ( "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/domain/infosync" "github.com/pingcap/tidb/infoschema" + "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" plannercore "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/privilege" @@ -1971,7 +1972,7 @@ type tiflashInstanceInfo struct { func (e *TiFlashSystemTableRetriever) initialize(sctx sessionctx.Context, tiflashInstances set.StringSet) error { store := sctx.GetStore() - if etcd, ok := store.(tikv.EtcdBackend); ok { + if etcd, ok := store.(kv.EtcdBackend); ok { var addrs []string var err error if addrs, err = etcd.EtcdAddrs(); err != nil { diff --git a/executor/split.go b/executor/split.go index afc549a60d139..b88bde7a343f7 100644 --- a/executor/split.go +++ b/executor/split.go @@ -801,7 +801,7 @@ func getRegionMeta(tikvStore tikv.Storage, regionMetas []*tikv.Region, uniqueReg func getRegionInfo(store tikv.Storage, regions []regionMeta) ([]regionMeta, error) { // check pd server exists. - etcd, ok := store.(tikv.EtcdBackend) + etcd, ok := store.(kv.EtcdBackend) if !ok { return regions, nil } diff --git a/infoschema/tables.go b/infoschema/tables.go index 049a5901731cb..ba33719ba1a3a 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1459,7 +1459,7 @@ func FormatVersion(TiDBVersion string, isDefaultVersion bool) string { func GetPDServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) { // Get PD servers info. store := ctx.GetStore() - etcd, ok := store.(tikv.EtcdBackend) + etcd, ok := store.(kv.EtcdBackend) if !ok { return nil, errors.Errorf("%T not an etcd backend", store) } diff --git a/kv/kv.go b/kv/kv.go index 52e23dc7f49d7..67373047acd37 100644 --- a/kv/kv.go +++ b/kv/kv.go @@ -15,6 +15,7 @@ package kv import ( "context" + "crypto/tls" "sync" "time" @@ -495,6 +496,13 @@ type Storage interface { GetMemCache() MemManager } +// EtcdBackend is used for judging a storage is a real TiKV. +type EtcdBackend interface { + EtcdAddrs() ([]string, error) + TLSConfig() *tls.Config + StartGCWorker() error +} + // FnKeyCmp is the function for iterator the keys type FnKeyCmp func(key Key) bool diff --git a/server/http_handler.go b/server/http_handler.go index 8bc6cd31c9241..ce5884d95e994 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -1110,7 +1110,7 @@ func (h ddlResignOwnerHandler) ServeHTTP(w http.ResponseWriter, req *http.Reques } func (h tableHandler) getPDAddr() ([]string, error) { - etcd, ok := h.Store.(tikv.EtcdBackend) + etcd, ok := h.Store.(kv.EtcdBackend) if !ok { return nil, errors.New("not implemented") } diff --git a/session/session.go b/session/session.go index fc4794fcb1a15..1533995b45624 100644 --- a/session/session.go +++ b/session/session.go @@ -2352,7 +2352,7 @@ func BootstrapSession(store kv.Storage) (*domain.Domain, error) { if err != nil { return nil, err } - if raw, ok := store.(tikv.EtcdBackend); ok { + if raw, ok := store.(kv.EtcdBackend); ok { err = raw.StartGCWorker() if err != nil { return nil, err diff --git a/session/session_test.go b/session/session_test.go index 5fc06a9e72d4d..332f64465a1a1 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -123,7 +123,7 @@ func clearStorage(store kv.Storage) error { return txn.Commit(context.Background()) } -func clearETCD(ebd tikv.EtcdBackend) error { +func clearETCD(ebd kv.EtcdBackend) error { endpoints, err := ebd.EtcdAddrs() if err != nil { return err @@ -187,7 +187,7 @@ func (s *testSessionSuiteBase) SetUpSuite(c *C) { c.Assert(err, IsNil) err = clearStorage(store) c.Assert(err, IsNil) - err = clearETCD(store.(tikv.EtcdBackend)) + err = clearETCD(store.(kv.EtcdBackend)) c.Assert(err, IsNil) session.ResetStoreForWithTiKVTest(store) s.store = store diff --git a/store/helper/helper.go b/store/helper/helper.go index ebb56158f95ce..98ad35b8852c5 100644 --- a/store/helper/helper.go +++ b/store/helper/helper.go @@ -118,7 +118,7 @@ func (h *Helper) ScrapeHotInfo(rw string, allSchemas []*model.DBInfo) ([]HotTabl // FetchHotRegion fetches the hot region information from PD's http api. func (h *Helper) FetchHotRegion(rw string) (map[uint64]RegionMetric, error) { - etcd, ok := h.Store.(tikv.EtcdBackend) + etcd, ok := h.Store.(kv.EtcdBackend) if !ok { return nil, errors.WithStack(errors.New("not implemented")) } @@ -639,7 +639,7 @@ func (h *Helper) GetRegionInfoByID(regionID uint64) (*RegionInfo, error) { // request PD API, decode the response body into res func (h *Helper) requestPD(method, uri string, body io.Reader, res interface{}) error { - etcd, ok := h.Store.(tikv.EtcdBackend) + etcd, ok := h.Store.(kv.EtcdBackend) if !ok { return errors.WithStack(errors.New("not implemented")) } @@ -725,7 +725,7 @@ type StoreDetailStat struct { // GetStoresStat gets the TiKV store information by accessing PD's api. func (h *Helper) GetStoresStat() (*StoresStat, error) { - etcd, ok := h.Store.(tikv.EtcdBackend) + etcd, ok := h.Store.(kv.EtcdBackend) if !ok { return nil, errors.WithStack(errors.New("not implemented")) } @@ -760,7 +760,7 @@ func (h *Helper) GetStoresStat() (*StoresStat, error) { // GetPDAddr return the PD Address. func (h *Helper) GetPDAddr() ([]string, error) { - etcd, ok := h.Store.(tikv.EtcdBackend) + etcd, ok := h.Store.(kv.EtcdBackend) if !ok { return nil, errors.New("not implemented") } diff --git a/store/tikv/kv.go b/store/tikv/kv.go index 3432d7d4fbec9..691f6ccc214bf 100644 --- a/store/tikv/kv.go +++ b/store/tikv/kv.go @@ -53,13 +53,6 @@ func createEtcdKV(addrs []string, tlsConfig *tls.Config) (*clientv3.Client, erro return cli, nil } -// EtcdBackend is used for judging a storage is a real TiKV. -type EtcdBackend interface { - EtcdAddrs() ([]string, error) - TLSConfig() *tls.Config - StartGCWorker() error -} - // update oracle's lastTS every 2000ms. var oracleUpdateInterval = 2000