etcdserver: Create raftnode based on boostrapRaft struct

dependabot/go_modules/go.uber.org/atomic-1.10.0
Marek Siarkowicz 2021-07-07 17:38:56 +02:00
parent 554777bba4
commit 08935247a8
2 changed files with 46 additions and 32 deletions

View File

@ -33,6 +33,7 @@ import (
"go.etcd.io/etcd/server/v3/config"
"go.etcd.io/etcd/server/v3/etcdserver/api/membership"
"go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp"
"go.etcd.io/etcd/server/v3/etcdserver/api/snap"
"go.etcd.io/etcd/server/v3/wal"
"go.etcd.io/etcd/server/v3/wal/walpb"
"go.uber.org/zap"
@ -463,11 +464,13 @@ func startNode(cfg config.ServerConfig, cl *membership.RaftCluster, ids []types.
raftStatusMu.Unlock()
return &boostrapRaft{
id: id,
cl: cl,
node: n,
storage: s,
wal: w,
lg: cfg.Logger,
heartbeat: time.Duration(cfg.TickMs) * time.Millisecond,
id: id,
cl: cl,
node: n,
storage: s,
wal: w,
}
}
@ -498,11 +501,13 @@ func restartNode(cfg config.ServerConfig, snapshot *raftpb.Snapshot) *boostrapRa
raftStatus = n.Status
raftStatusMu.Unlock()
return &boostrapRaft{
id: id,
cl: cl,
node: n,
storage: s,
wal: w,
lg: cfg.Logger,
heartbeat: time.Duration(cfg.TickMs) * time.Millisecond,
id: id,
cl: cl,
node: n,
storage: s,
wal: w,
}
}
@ -566,11 +571,13 @@ func restartAsStandaloneNode(cfg config.ServerConfig, snapshot *raftpb.Snapshot)
n := raft.RestartNode(c)
raftStatus = n.Status
return &boostrapRaft{
id: id,
cl: cl,
node: n,
storage: s,
wal: w,
lg: cfg.Logger,
heartbeat: time.Duration(cfg.TickMs) * time.Millisecond,
id: id,
cl: cl,
node: n,
storage: s,
wal: w,
}
}
@ -589,6 +596,9 @@ func raftConfig(cfg config.ServerConfig, id uint64, s *raft.MemoryStorage) *raft
}
type boostrapRaft struct {
lg *zap.Logger
heartbeat time.Duration
id types.ID
cl *membership.RaftCluster
node raft.Node
@ -596,6 +606,19 @@ type boostrapRaft struct {
wal *wal.WAL
}
func (b *boostrapRaft) newRaftNode(ss *snap.Snapshotter) *raftNode {
return newRaftNode(
raftNodeConfig{
lg: b.lg,
isIDRemoved: func(id uint64) bool { return b.cl.IsIDRemoved(types.ID(id)) },
Node: b.node,
heartbeat: b.heartbeat,
raftStorage: b.storage,
storage: NewStorage(b.wal, ss),
},
)
}
// getIDs returns an ordered set of IDs included in the given snapshot and
// the entries. The given snapshot/entries can contain three kinds of
// ID-related entry:

View File

@ -623,23 +623,14 @@ func NewServer(cfg config.ServerConfig) (srv *EtcdServer, err error) {
heartbeat := time.Duration(cfg.TickMs) * time.Millisecond
srv = &EtcdServer{
readych: make(chan struct{}),
Cfg: cfg,
lgMu: new(sync.RWMutex),
lg: cfg.Logger,
errorc: make(chan error, 1),
v2store: b.st,
snapshotter: b.ss,
r: *newRaftNode(
raftNodeConfig{
lg: cfg.Logger,
isIDRemoved: func(id uint64) bool { return b.raft.cl.IsIDRemoved(types.ID(id)) },
Node: b.raft.node,
heartbeat: heartbeat,
raftStorage: b.raft.storage,
storage: NewStorage(b.raft.wal, b.ss),
},
),
readych: make(chan struct{}),
Cfg: cfg,
lgMu: new(sync.RWMutex),
lg: cfg.Logger,
errorc: make(chan error, 1),
v2store: b.st,
snapshotter: b.ss,
r: *b.raft.newRaftNode(b.ss),
id: b.raft.id,
attributes: membership.Attributes{Name: cfg.Name, ClientURLs: cfg.ClientURLs.StringSlice()},
cluster: b.raft.cl,