mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: Fix typos in bootstrap
This commit is contained in:
parent
e1fa356fac
commit
9824cc96ed
@ -418,10 +418,10 @@ func (r *raftNode) advanceTicks(ticks int) {
|
||||
}
|
||||
}
|
||||
|
||||
func boostrapRaftFromCluster(cfg config.ServerConfig, cl *membership.RaftCluster, ids []types.ID) *boostrapRaft {
|
||||
func bootstrapRaftFromCluster(cfg config.ServerConfig, cl *membership.RaftCluster, ids []types.ID) *bootstrappedRaft {
|
||||
member := cl.MemberByName(cfg.Name)
|
||||
id := member.ID
|
||||
wal := boostrapNewWal(cfg, id, cl.ID())
|
||||
wal := bootstrapNewWAL(cfg, id, cl.ID())
|
||||
peers := make([]raft.Peer, len(ids))
|
||||
for i, id := range ids {
|
||||
var ctx []byte
|
||||
@ -437,7 +437,7 @@ func boostrapRaftFromCluster(cfg config.ServerConfig, cl *membership.RaftCluster
|
||||
zap.String("cluster-id", cl.ID().String()),
|
||||
)
|
||||
s := wal.MemoryStorage()
|
||||
return &boostrapRaft{
|
||||
return &bootstrappedRaft{
|
||||
lg: cfg.Logger,
|
||||
heartbeat: time.Duration(cfg.TickMs) * time.Millisecond,
|
||||
cl: cl,
|
||||
@ -448,8 +448,8 @@ func boostrapRaftFromCluster(cfg config.ServerConfig, cl *membership.RaftCluster
|
||||
}
|
||||
}
|
||||
|
||||
func boostrapRaftFromWal(cfg config.ServerConfig, snapshot *raftpb.Snapshot) *boostrapRaft {
|
||||
wal := boostrapWALFromSnapshot(cfg.Logger, cfg.WALDir(), snapshot, cfg.UnsafeNoFsync)
|
||||
func bootstrapRaftFromWal(cfg config.ServerConfig, snapshot *raftpb.Snapshot) *bootstrappedRaft {
|
||||
wal := bootstrapWALFromSnapshot(cfg.Logger, cfg.WALDir(), snapshot, cfg.UnsafeNoFsync)
|
||||
|
||||
cfg.Logger.Info(
|
||||
"restarting local member",
|
||||
@ -460,7 +460,7 @@ func boostrapRaftFromWal(cfg config.ServerConfig, snapshot *raftpb.Snapshot) *bo
|
||||
cl := membership.NewCluster(cfg.Logger)
|
||||
cl.SetID(wal.id, wal.cid)
|
||||
s := wal.MemoryStorage()
|
||||
return &boostrapRaft{
|
||||
return &bootstrappedRaft{
|
||||
lg: cfg.Logger,
|
||||
heartbeat: time.Duration(cfg.TickMs) * time.Millisecond,
|
||||
cl: cl,
|
||||
@ -470,8 +470,8 @@ func boostrapRaftFromWal(cfg config.ServerConfig, snapshot *raftpb.Snapshot) *bo
|
||||
}
|
||||
}
|
||||
|
||||
func boostrapRaftFromWalStandalone(cfg config.ServerConfig, snapshot *raftpb.Snapshot) *boostrapRaft {
|
||||
wal := boostrapWALFromSnapshot(cfg.Logger, cfg.WALDir(), snapshot, cfg.UnsafeNoFsync)
|
||||
func bootstrapRaftFromWalStandalone(cfg config.ServerConfig, snapshot *raftpb.Snapshot) *bootstrappedRaft {
|
||||
wal := bootstrapWALFromSnapshot(cfg.Logger, cfg.WALDir(), snapshot, cfg.UnsafeNoFsync)
|
||||
|
||||
// discard the previously uncommitted entries
|
||||
wal.ents = wal.CommitedEntries()
|
||||
@ -489,7 +489,7 @@ func boostrapRaftFromWalStandalone(cfg config.ServerConfig, snapshot *raftpb.Sna
|
||||
cl := membership.NewCluster(cfg.Logger)
|
||||
cl.SetID(wal.id, wal.cid)
|
||||
s := wal.MemoryStorage()
|
||||
return &boostrapRaft{
|
||||
return &bootstrappedRaft{
|
||||
lg: cfg.Logger,
|
||||
heartbeat: time.Duration(cfg.TickMs) * time.Millisecond,
|
||||
cl: cl,
|
||||
@ -513,7 +513,7 @@ func raftConfig(cfg config.ServerConfig, id uint64, s *raft.MemoryStorage) *raft
|
||||
}
|
||||
}
|
||||
|
||||
type boostrapRaft struct {
|
||||
type bootstrappedRaft struct {
|
||||
lg *zap.Logger
|
||||
heartbeat time.Duration
|
||||
|
||||
@ -521,10 +521,10 @@ type boostrapRaft struct {
|
||||
config *raft.Config
|
||||
cl *membership.RaftCluster
|
||||
storage *raft.MemoryStorage
|
||||
wal *boostrappedWAL
|
||||
wal *bootstrappedWAL
|
||||
}
|
||||
|
||||
func (b *boostrapRaft) newRaftNode(ss *snap.Snapshotter) *raftNode {
|
||||
func (b *bootstrappedRaft) newRaftNode(ss *snap.Snapshotter) *raftNode {
|
||||
var n raft.Node
|
||||
if len(b.peers) == 0 {
|
||||
n = raft.RestartNode(b.config)
|
||||
|
@ -330,7 +330,7 @@ func (bh *backendHooks) SetConfState(confState *raftpb.ConfState) {
|
||||
bh.confStateDirty = true
|
||||
}
|
||||
|
||||
func bootstrap(cfg config.ServerConfig) (b *boostrapResult, err error) {
|
||||
func bootstrap(cfg config.ServerConfig) (b *bootstrappedServer, err error) {
|
||||
st := v2store.New(StoreClusterPrefix, StoreKeysPrefix)
|
||||
|
||||
if cfg.MaxRequestBytes > recommendedMaxRequestBytes {
|
||||
@ -348,9 +348,9 @@ func bootstrap(cfg config.ServerConfig) (b *boostrapResult, err error) {
|
||||
}
|
||||
|
||||
haveWAL := wal.Exist(cfg.WALDir())
|
||||
ss := boostrapSnapshotter(cfg)
|
||||
ss := bootstrapSnapshot(cfg)
|
||||
|
||||
be, ci, beExist, beHooks, err := boostrapBackend(cfg)
|
||||
be, ci, beExist, beHooks, err := bootstrapBackend(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -369,9 +369,9 @@ func bootstrap(cfg config.ServerConfig) (b *boostrapResult, err error) {
|
||||
case !haveWAL && !cfg.NewCluster:
|
||||
b, err = bootstrapExistingClusterNoWAL(cfg, prt, st, be)
|
||||
case !haveWAL && cfg.NewCluster:
|
||||
b, err = boostrapNewClusterNoWAL(cfg, prt, st, be)
|
||||
b, err = bootstrapNewClusterNoWAL(cfg, prt, st, be)
|
||||
case haveWAL:
|
||||
b, err = boostrapWithWAL(cfg, st, be, ss, beExist, beHooks, ci)
|
||||
b, err = bootstrapWithWAL(cfg, st, be, ss, beExist, beHooks, ci)
|
||||
default:
|
||||
be.Close()
|
||||
return nil, fmt.Errorf("unsupported bootstrap config")
|
||||
@ -392,8 +392,8 @@ func bootstrap(cfg config.ServerConfig) (b *boostrapResult, err error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
type boostrapResult struct {
|
||||
raft *boostrapRaft
|
||||
type bootstrappedServer struct {
|
||||
raft *bootstrappedRaft
|
||||
remotes []*membership.Member
|
||||
prt http.RoundTripper
|
||||
ci cindex.ConsistentIndexer
|
||||
@ -403,7 +403,7 @@ type boostrapResult struct {
|
||||
beHooks *backendHooks
|
||||
}
|
||||
|
||||
func boostrapSnapshotter(cfg config.ServerConfig) *snap.Snapshotter {
|
||||
func bootstrapSnapshot(cfg config.ServerConfig) *snap.Snapshotter {
|
||||
if err := fileutil.TouchDirAll(cfg.SnapDir()); err != nil {
|
||||
cfg.Logger.Fatal(
|
||||
"failed to create snapshot directory",
|
||||
@ -424,7 +424,7 @@ func boostrapSnapshotter(cfg config.ServerConfig) *snap.Snapshotter {
|
||||
return snap.New(cfg.Logger, cfg.SnapDir())
|
||||
}
|
||||
|
||||
func boostrapBackend(cfg config.ServerConfig) (be backend.Backend, ci cindex.ConsistentIndexer, beExist bool, beHooks *backendHooks, err error) {
|
||||
func bootstrapBackend(cfg config.ServerConfig) (be backend.Backend, ci cindex.ConsistentIndexer, beExist bool, beHooks *backendHooks, err error) {
|
||||
beExist = fileutil.Exist(cfg.BackendPath())
|
||||
ci = cindex.NewConsistentIndex(nil)
|
||||
beHooks = &backendHooks{lg: cfg.Logger, indexer: ci}
|
||||
@ -442,7 +442,7 @@ func boostrapBackend(cfg config.ServerConfig) (be backend.Backend, ci cindex.Con
|
||||
return be, ci, beExist, beHooks, nil
|
||||
}
|
||||
|
||||
func bootstrapExistingClusterNoWAL(cfg config.ServerConfig, prt http.RoundTripper, st v2store.Store, be backend.Backend) (*boostrapResult, error) {
|
||||
func bootstrapExistingClusterNoWAL(cfg config.ServerConfig, prt http.RoundTripper, st v2store.Store, be backend.Backend) (*bootstrappedServer, error) {
|
||||
if err := cfg.VerifyJoinExisting(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -465,15 +465,15 @@ func bootstrapExistingClusterNoWAL(cfg config.ServerConfig, prt http.RoundTrippe
|
||||
cl.SetID(types.ID(0), existingCluster.ID())
|
||||
cl.SetStore(st)
|
||||
cl.SetBackend(buckets.NewMembershipStore(cfg.Logger, be))
|
||||
br := boostrapRaftFromCluster(cfg, cl, nil)
|
||||
br := bootstrapRaftFromCluster(cfg, cl, nil)
|
||||
cl.SetID(br.wal.id, existingCluster.ID())
|
||||
return &boostrapResult{
|
||||
return &bootstrappedServer{
|
||||
raft: br,
|
||||
remotes: remotes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func boostrapNewClusterNoWAL(cfg config.ServerConfig, prt http.RoundTripper, st v2store.Store, be backend.Backend) (*boostrapResult, error) {
|
||||
func bootstrapNewClusterNoWAL(cfg config.ServerConfig, prt http.RoundTripper, st v2store.Store, be backend.Backend) (*bootstrappedServer, error) {
|
||||
if err := cfg.VerifyBootstrap(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -505,15 +505,15 @@ func boostrapNewClusterNoWAL(cfg config.ServerConfig, prt http.RoundTripper, st
|
||||
}
|
||||
cl.SetStore(st)
|
||||
cl.SetBackend(buckets.NewMembershipStore(cfg.Logger, be))
|
||||
br := boostrapRaftFromCluster(cfg, cl, cl.MemberIDs())
|
||||
br := bootstrapRaftFromCluster(cfg, cl, cl.MemberIDs())
|
||||
cl.SetID(br.wal.id, cl.ID())
|
||||
return &boostrapResult{
|
||||
return &bootstrappedServer{
|
||||
remotes: nil,
|
||||
raft: br,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func boostrapWithWAL(cfg config.ServerConfig, st v2store.Store, be backend.Backend, ss *snap.Snapshotter, beExist bool, beHooks *backendHooks, ci cindex.ConsistentIndexer) (*boostrapResult, error) {
|
||||
func bootstrapWithWAL(cfg config.ServerConfig, st v2store.Store, be backend.Backend, ss *snap.Snapshotter, beExist bool, beHooks *backendHooks, ci cindex.ConsistentIndexer) (*bootstrappedServer, error) {
|
||||
if err := fileutil.IsDirWriteable(cfg.MemberDir()); err != nil {
|
||||
return nil, fmt.Errorf("cannot write to member directory: %v", err)
|
||||
}
|
||||
@ -586,11 +586,11 @@ func boostrapWithWAL(cfg config.ServerConfig, st v2store.Store, be backend.Backe
|
||||
cfg.Logger.Info("No snapshot found. Recovering WAL from scratch!")
|
||||
}
|
||||
|
||||
r := &boostrapResult{}
|
||||
r := &bootstrappedServer{}
|
||||
if !cfg.ForceNewCluster {
|
||||
r.raft = boostrapRaftFromWal(cfg, snapshot)
|
||||
r.raft = bootstrapRaftFromWal(cfg, snapshot)
|
||||
} else {
|
||||
r.raft = boostrapRaftFromWalStandalone(cfg, snapshot)
|
||||
r.raft = bootstrapRaftFromWalStandalone(cfg, snapshot)
|
||||
}
|
||||
|
||||
r.raft.cl.SetStore(st)
|
||||
|
@ -82,10 +82,10 @@ func (st *storage) Release(snap raftpb.Snapshot) error {
|
||||
return st.Snapshotter.ReleaseSnapDBs(snap)
|
||||
}
|
||||
|
||||
// boostrapWALFromSnapshot reads the WAL at the given snap and returns the wal, its latest HardState and cluster ID, and all entries that appear
|
||||
// bootstrapWALFromSnapshot reads the WAL at the given snap and returns the wal, its latest HardState and cluster ID, and all entries that appear
|
||||
// after the position of the given snap in the WAL.
|
||||
// The snap must have been previously saved to the WAL, or this call will panic.
|
||||
func boostrapWALFromSnapshot(lg *zap.Logger, waldir string, snapshot *raftpb.Snapshot, unsafeNoFsync bool) *boostrappedWAL {
|
||||
func bootstrapWALFromSnapshot(lg *zap.Logger, waldir string, snapshot *raftpb.Snapshot, unsafeNoFsync bool) *bootstrappedWAL {
|
||||
var walsnap walpb.Snapshot
|
||||
if snapshot != nil {
|
||||
walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term
|
||||
@ -118,7 +118,7 @@ func boostrapWALFromSnapshot(lg *zap.Logger, waldir string, snapshot *raftpb.Sna
|
||||
pbutil.MustUnmarshal(&metadata, wmetadata)
|
||||
id := types.ID(metadata.NodeID)
|
||||
cid := types.ID(metadata.ClusterID)
|
||||
return &boostrappedWAL{
|
||||
return &bootstrappedWAL{
|
||||
lg: lg,
|
||||
w: w,
|
||||
id: id,
|
||||
@ -130,7 +130,7 @@ func boostrapWALFromSnapshot(lg *zap.Logger, waldir string, snapshot *raftpb.Sna
|
||||
}
|
||||
}
|
||||
|
||||
func boostrapNewWal(cfg config.ServerConfig, nodeID, clusterID types.ID) *boostrappedWAL {
|
||||
func bootstrapNewWAL(cfg config.ServerConfig, nodeID, clusterID types.ID) *bootstrappedWAL {
|
||||
metadata := pbutil.MustMarshal(
|
||||
&pb.Metadata{
|
||||
NodeID: uint64(nodeID),
|
||||
@ -144,7 +144,7 @@ func boostrapNewWal(cfg config.ServerConfig, nodeID, clusterID types.ID) *boostr
|
||||
if cfg.UnsafeNoFsync {
|
||||
w.SetUnsafeNoFsync()
|
||||
}
|
||||
return &boostrappedWAL{
|
||||
return &bootstrappedWAL{
|
||||
lg: cfg.Logger,
|
||||
w: w,
|
||||
id: nodeID,
|
||||
@ -152,7 +152,7 @@ func boostrapNewWal(cfg config.ServerConfig, nodeID, clusterID types.ID) *boostr
|
||||
}
|
||||
}
|
||||
|
||||
type boostrappedWAL struct {
|
||||
type bootstrappedWAL struct {
|
||||
lg *zap.Logger
|
||||
|
||||
w *wal.WAL
|
||||
@ -162,7 +162,7 @@ type boostrappedWAL struct {
|
||||
snapshot *raftpb.Snapshot
|
||||
}
|
||||
|
||||
func (wal *boostrappedWAL) MemoryStorage() *raft.MemoryStorage {
|
||||
func (wal *bootstrappedWAL) MemoryStorage() *raft.MemoryStorage {
|
||||
s := raft.NewMemoryStorage()
|
||||
if wal.snapshot != nil {
|
||||
s.ApplySnapshot(*wal.snapshot)
|
||||
@ -176,7 +176,7 @@ func (wal *boostrappedWAL) MemoryStorage() *raft.MemoryStorage {
|
||||
return s
|
||||
}
|
||||
|
||||
func (wal *boostrappedWAL) CommitedEntries() []raftpb.Entry {
|
||||
func (wal *bootstrappedWAL) CommitedEntries() []raftpb.Entry {
|
||||
for i, ent := range wal.ents {
|
||||
if ent.Index > wal.st.Commit {
|
||||
wal.lg.Info(
|
||||
@ -191,7 +191,7 @@ func (wal *boostrappedWAL) CommitedEntries() []raftpb.Entry {
|
||||
return wal.ents
|
||||
}
|
||||
|
||||
func (wal *boostrappedWAL) ConfigChangeEntries() []raftpb.Entry {
|
||||
func (wal *bootstrappedWAL) ConfigChangeEntries() []raftpb.Entry {
|
||||
return createConfigChangeEnts(
|
||||
wal.lg,
|
||||
getIDs(wal.lg, wal.snapshot, wal.ents),
|
||||
@ -201,7 +201,7 @@ func (wal *boostrappedWAL) ConfigChangeEntries() []raftpb.Entry {
|
||||
)
|
||||
}
|
||||
|
||||
func (wal *boostrappedWAL) AppendAndCommitEntries(ents []raftpb.Entry) {
|
||||
func (wal *bootstrappedWAL) AppendAndCommitEntries(ents []raftpb.Entry) {
|
||||
wal.ents = append(wal.ents, ents...)
|
||||
err := wal.w.Save(raftpb.HardState{}, ents)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user