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

store/tikv: move EtcdBackend out #22676

Merged
merged 5 commits into from
Feb 3, 2021
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
2 changes: 1 addition & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion executor/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package kv

import (
"context"
"crypto/tls"
"sync"
"time"

Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why StartGCWorker is part of EtcdBackend?

}

// FnKeyCmp is the function for iterator the keys
type FnKeyCmp func(key Key) bool

Expand Down
2 changes: 1 addition & 1 deletion server/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions store/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down Expand Up @@ -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"))
}
Expand Down Expand Up @@ -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"))
}
Expand Down Expand Up @@ -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")
}
Expand Down
7 changes: 0 additions & 7 deletions store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down