server: Move member dir creation up and introduce Close method to bootstrap structs
This commit is contained in:
@ -63,16 +63,16 @@ func bootstrap(cfg config.ServerConfig) (b *bootstrappedServer, err error) {
|
||||
if terr := fileutil.TouchDirAll(cfg.DataDir); terr != nil {
|
||||
return nil, fmt.Errorf("cannot access data directory: %v", terr)
|
||||
}
|
||||
|
||||
if terr := fileutil.TouchDirAll(cfg.MemberDir()); terr != nil {
|
||||
return nil, fmt.Errorf("cannot access member directory: %v", terr)
|
||||
}
|
||||
ss := bootstrapSnapshot(cfg)
|
||||
prt, err := rafthttp.NewRoundTripper(cfg.PeerTLSInfo, cfg.PeerDialTimeout())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if terr := fileutil.TouchDirAll(cfg.MemberDir()); terr != nil {
|
||||
return nil, fmt.Errorf("cannot access member directory: %v", terr)
|
||||
}
|
||||
|
||||
haveWAL := wal.Exist(cfg.WALDir())
|
||||
st := v2store.New(StoreClusterPrefix, StoreKeysPrefix)
|
||||
backend, err := bootstrapBackend(cfg, haveWAL, st, ss)
|
||||
@ -92,19 +92,19 @@ func bootstrap(cfg config.ServerConfig) (b *bootstrappedServer, err error) {
|
||||
|
||||
cluster, err := bootstrapCluster(cfg, bwal, prt)
|
||||
if err != nil {
|
||||
backend.be.Close()
|
||||
backend.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s, err := bootstrapStorage(cfg, st, backend, bwal, cluster)
|
||||
if err != nil {
|
||||
backend.be.Close()
|
||||
backend.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = cluster.Finalize(cfg, s)
|
||||
if err != nil {
|
||||
backend.be.Close()
|
||||
backend.Close()
|
||||
return nil, err
|
||||
}
|
||||
raft := bootstrapRaft(cfg, cluster, s.wal)
|
||||
@ -125,12 +125,20 @@ type bootstrappedServer struct {
|
||||
ss *snap.Snapshotter
|
||||
}
|
||||
|
||||
func (s *bootstrappedServer) Close() {
|
||||
s.storage.Close()
|
||||
}
|
||||
|
||||
type bootstrappedStorage struct {
|
||||
backend *bootstrappedBackend
|
||||
wal *bootstrappedWAL
|
||||
st v2store.Store
|
||||
}
|
||||
|
||||
func (s *bootstrappedStorage) Close() {
|
||||
s.backend.Close()
|
||||
}
|
||||
|
||||
type bootstrappedBackend struct {
|
||||
beHooks *serverstorage.BackendHooks
|
||||
be backend.Backend
|
||||
@ -139,6 +147,10 @@ type bootstrappedBackend struct {
|
||||
snapshot *raftpb.Snapshot
|
||||
}
|
||||
|
||||
func (s *bootstrappedBackend) Close() {
|
||||
s.be.Close()
|
||||
}
|
||||
|
||||
type bootstrapedCluster struct {
|
||||
remotes []*membership.Member
|
||||
cl *membership.RaftCluster
|
||||
@ -343,7 +355,7 @@ func bootstrapClusterWithWAL(cfg config.ServerConfig, meta *snapshotMetadata) (*
|
||||
if cfg.ShouldDiscover() {
|
||||
cfg.Logger.Warn(
|
||||
"discovery token is ignored since cluster already initialized; valid logs are found",
|
||||
zap.String("bwal-dir", cfg.WALDir()),
|
||||
zap.String("wal-dir", cfg.WALDir()),
|
||||
)
|
||||
}
|
||||
cl := membership.NewCluster(cfg.Logger)
|
||||
|
Reference in New Issue
Block a user