mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: Create raftnode based on boostrapRaft struct
This commit is contained in:
parent
554777bba4
commit
08935247a8
@ -33,6 +33,7 @@ import (
|
|||||||
"go.etcd.io/etcd/server/v3/config"
|
"go.etcd.io/etcd/server/v3/config"
|
||||||
"go.etcd.io/etcd/server/v3/etcdserver/api/membership"
|
"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/rafthttp"
|
||||||
|
"go.etcd.io/etcd/server/v3/etcdserver/api/snap"
|
||||||
"go.etcd.io/etcd/server/v3/wal"
|
"go.etcd.io/etcd/server/v3/wal"
|
||||||
"go.etcd.io/etcd/server/v3/wal/walpb"
|
"go.etcd.io/etcd/server/v3/wal/walpb"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@ -463,6 +464,8 @@ func startNode(cfg config.ServerConfig, cl *membership.RaftCluster, ids []types.
|
|||||||
raftStatusMu.Unlock()
|
raftStatusMu.Unlock()
|
||||||
|
|
||||||
return &boostrapRaft{
|
return &boostrapRaft{
|
||||||
|
lg: cfg.Logger,
|
||||||
|
heartbeat: time.Duration(cfg.TickMs) * time.Millisecond,
|
||||||
id: id,
|
id: id,
|
||||||
cl: cl,
|
cl: cl,
|
||||||
node: n,
|
node: n,
|
||||||
@ -498,6 +501,8 @@ func restartNode(cfg config.ServerConfig, snapshot *raftpb.Snapshot) *boostrapRa
|
|||||||
raftStatus = n.Status
|
raftStatus = n.Status
|
||||||
raftStatusMu.Unlock()
|
raftStatusMu.Unlock()
|
||||||
return &boostrapRaft{
|
return &boostrapRaft{
|
||||||
|
lg: cfg.Logger,
|
||||||
|
heartbeat: time.Duration(cfg.TickMs) * time.Millisecond,
|
||||||
id: id,
|
id: id,
|
||||||
cl: cl,
|
cl: cl,
|
||||||
node: n,
|
node: n,
|
||||||
@ -566,6 +571,8 @@ func restartAsStandaloneNode(cfg config.ServerConfig, snapshot *raftpb.Snapshot)
|
|||||||
n := raft.RestartNode(c)
|
n := raft.RestartNode(c)
|
||||||
raftStatus = n.Status
|
raftStatus = n.Status
|
||||||
return &boostrapRaft{
|
return &boostrapRaft{
|
||||||
|
lg: cfg.Logger,
|
||||||
|
heartbeat: time.Duration(cfg.TickMs) * time.Millisecond,
|
||||||
id: id,
|
id: id,
|
||||||
cl: cl,
|
cl: cl,
|
||||||
node: n,
|
node: n,
|
||||||
@ -589,6 +596,9 @@ func raftConfig(cfg config.ServerConfig, id uint64, s *raft.MemoryStorage) *raft
|
|||||||
}
|
}
|
||||||
|
|
||||||
type boostrapRaft struct {
|
type boostrapRaft struct {
|
||||||
|
lg *zap.Logger
|
||||||
|
heartbeat time.Duration
|
||||||
|
|
||||||
id types.ID
|
id types.ID
|
||||||
cl *membership.RaftCluster
|
cl *membership.RaftCluster
|
||||||
node raft.Node
|
node raft.Node
|
||||||
@ -596,6 +606,19 @@ type boostrapRaft struct {
|
|||||||
wal *wal.WAL
|
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
|
// getIDs returns an ordered set of IDs included in the given snapshot and
|
||||||
// the entries. The given snapshot/entries can contain three kinds of
|
// the entries. The given snapshot/entries can contain three kinds of
|
||||||
// ID-related entry:
|
// ID-related entry:
|
||||||
|
@ -630,16 +630,7 @@ func NewServer(cfg config.ServerConfig) (srv *EtcdServer, err error) {
|
|||||||
errorc: make(chan error, 1),
|
errorc: make(chan error, 1),
|
||||||
v2store: b.st,
|
v2store: b.st,
|
||||||
snapshotter: b.ss,
|
snapshotter: b.ss,
|
||||||
r: *newRaftNode(
|
r: *b.raft.newRaftNode(b.ss),
|
||||||
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),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
id: b.raft.id,
|
id: b.raft.id,
|
||||||
attributes: membership.Attributes{Name: cfg.Name, ClientURLs: cfg.ClientURLs.StringSlice()},
|
attributes: membership.Attributes{Name: cfg.Name, ClientURLs: cfg.ClientURLs.StringSlice()},
|
||||||
cluster: b.raft.cl,
|
cluster: b.raft.cl,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user