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

conn: support not shutting down the storage when closing the connection #185

Merged
merged 2 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 13 additions & 8 deletions pkg/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Mgr struct {
mu sync.Mutex
clis map[uint64]*grpc.ClientConn
}
ownsStorage bool
}

type pdHTTPRequest func(context.Context, string, string, *http.Client, string, io.Reader) ([]byte, error)
Expand Down Expand Up @@ -165,10 +166,11 @@ func NewMgr(
}

mgr := &Mgr{
pdClient: pdClient,
storage: storage,
dom: dom,
tlsConf: tlsConf,
pdClient: pdClient,
storage: storage,
dom: dom,
tlsConf: tlsConf,
ownsStorage: g.OwnsStorage(),
}
mgr.pdHTTP.addrs = processedAddrs
mgr.pdHTTP.cli = cli
Expand Down Expand Up @@ -386,11 +388,14 @@ func (mgr *Mgr) Close() {

// Gracefully shutdown domain so it does not affect other TiDB DDL.
// Must close domain before closing storage, otherwise it gets stuck forever.
if mgr.dom != nil {
mgr.dom.Close()
if mgr.ownsStorage {
if mgr.dom != nil {
mgr.dom.Close()
}

atomic.StoreUint32(&tikv.ShuttingDown, 1)
mgr.storage.Close()
}

atomic.StoreUint32(&tikv.ShuttingDown, 1)
mgr.storage.Close()
mgr.pdClient.Close()
}
4 changes: 4 additions & 0 deletions pkg/glue/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ 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)

// OwnsStorage returns whether the storage returned by Open() is owned
// If this method returns false, the connection manager will never close the storage.
OwnsStorage() bool
}

// Session is an abstraction of the session.Session interface.
Expand Down
5 changes: 5 additions & 0 deletions pkg/gluetidb/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func (Glue) Open(path string, option pd.SecurityOption) (kv.Storage, error) {
return tikv.Driver{}.Open(path)
}

// OwnsStorage implements glue.Glue
func (Glue) OwnsStorage() bool {
return true
}

// Execute implements glue.Session
func (gs *tidbSession) Execute(ctx context.Context, sql string) error {
_, err := gs.se.Execute(ctx, sql)
Expand Down