Skip to content

Bootstrap from backend position #19693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions contrib/raftexample/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ func (rc *raftNode) openWAL(snapshot *raftpb.Snapshot) *wal.WAL {
w.Close()
}

walsnap := walpb.Snapshot{}
pos := wal.Position{}
if snapshot != nil {
walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term
pos.Index, pos.Term = snapshot.Metadata.Index, snapshot.Metadata.Term
}
log.Printf("loading WAL at term %d and index %d", walsnap.Term, walsnap.Index)
w, err := wal.Open(zap.NewExample(), rc.waldir, walsnap)
log.Printf("loading WAL at term %d and index %d", pos.Term, pos.Index)
w, err := wal.Open(zap.NewExample(), rc.waldir, pos)
if err != nil {
log.Fatalf("raftexample: error loading wal (%v)", err)
}
Expand Down
2 changes: 1 addition & 1 deletion etcdutl/etcdutl/migrate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
if err != nil {
return fmt.Errorf("failed to get the lastest snapshot: %w", err)
}
w, err := wal.OpenForRead(c.lg, walPath, walSnap)
w, err := wal.OpenForRead(c.lg, walPath, wal.Position{Index: walSnap.Index, Term: walSnap.Term})

Check warning on line 111 in etcdutl/etcdutl/migrate_command.go

View check run for this annotation

Codecov / codecov/patch

etcdutl/etcdutl/migrate_command.go#L111

Added line #L111 was not covered by tests
if err != nil {
return fmt.Errorf(`failed to open wal: %w`, err)
}
Expand Down
14 changes: 1 addition & 13 deletions server/etcdserver/api/membership/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ type RaftCluster struct {
localID types.ID
cid types.ID

v2store v2store.Store
be MembershipBackend
be MembershipBackend

sync.Mutex // guards the fields below
version *semver.Version
Expand Down Expand Up @@ -116,7 +115,6 @@ func NewCluster(lg *zap.Logger, opts ...ClusterOption) *RaftCluster {
removed: make(map[types.ID]bool),
downgradeInfo: &serverversion.DowngradeInfo{Enabled: false},
maxLearners: clOpts.maxLearners,
v2store: v2store.New(),
}
}

Expand Down Expand Up @@ -246,8 +244,6 @@ func (c *RaftCluster) SetID(localID, cid types.ID) {
c.buildMembershipMetric()
}

func (c *RaftCluster) SetStore(st v2store.Store) { c.v2store = st }

func (c *RaftCluster) SetBackend(be MembershipBackend) {
c.be = be
c.be.MustCreateBackendBuckets()
Expand Down Expand Up @@ -312,8 +308,6 @@ func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange, shouldAp

if shouldApplyV3 {
membersMap, removedMap = c.be.MustReadMembersFromBackend()
} else {
membersMap, removedMap = membersFromStore(c.lg, c.v2store)
}

id := types.ID(cc.NodeID)
Expand Down Expand Up @@ -400,7 +394,6 @@ func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange, shouldAp
func (c *RaftCluster) AddMember(m *Member, shouldApplyV3 ShouldApplyV3) {
c.Lock()
defer c.Unlock()
mustSaveMemberToStore(c.lg, c.v2store, m)

if m.ID == c.localID {
setIsLearnerMetric(m)
Expand Down Expand Up @@ -436,7 +429,6 @@ func (c *RaftCluster) AddMember(m *Member, shouldApplyV3 ShouldApplyV3) {
func (c *RaftCluster) RemoveMember(id types.ID, shouldApplyV3 ShouldApplyV3) {
c.Lock()
defer c.Unlock()
mustDeleteMemberFromStore(c.lg, c.v2store, id)
if shouldApplyV3 {
c.be.MustDeleteMemberFromBackend(id)

Expand Down Expand Up @@ -478,7 +470,6 @@ func (c *RaftCluster) UpdateAttributes(id types.ID, attr Attributes, shouldApply

if m, ok := c.members[id]; ok {
m.Attributes = attr
mustUpdateMemberAttrInStore(c.lg, c.v2store, m)
if shouldApplyV3 {
c.be.MustSaveMemberToBackend(m)
}
Expand Down Expand Up @@ -511,7 +502,6 @@ func (c *RaftCluster) PromoteMember(id types.ID, shouldApplyV3 ShouldApplyV3) {
if _, ok := c.members[id]; ok {
m := *(c.members[id])
m.RaftAttributes.IsLearner = false
mustUpdateMemberInStore(c.lg, c.v2store, &m)
} else {
c.lg.Info("Skipped promoting non-existent member in v2store",
zap.String("cluster-id", c.cid.String()),
Expand Down Expand Up @@ -551,7 +541,6 @@ func (c *RaftCluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes,
if _, ok := c.members[id]; ok {
m := *(c.members[id])
m.RaftAttributes = raftAttr
mustUpdateMemberInStore(c.lg, c.v2store, &m)
} else {
c.lg.Info("Skipped updating non-existent member in v2store",
zap.String("cluster-id", c.cid.String()),
Expand Down Expand Up @@ -618,7 +607,6 @@ func (c *RaftCluster) SetVersion(ver *semver.Version, onSet func(*zap.Logger, *s
c.version = ver
sv := semver.Must(semver.NewVersion(version.Version))
serverversion.MustDetectDowngrade(c.lg, sv, c.version)
mustSaveClusterVersionToStore(c.lg, c.v2store, ver)

if shouldApplyV3 {
c.be.MustSaveClusterVersionToBackend(ver)
Expand Down
8 changes: 0 additions & 8 deletions server/etcdserver/api/membership/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func testClusterValidateConfigurationChange(t *testing.T, shouldApplyV3 ShouldAp
cl := NewCluster(zaptest.NewLogger(t), WithMaxLearners(1))
be := newMembershipBackend()
cl.SetBackend(be)
cl.SetStore(v2store.New())
for i := 1; i <= 4; i++ {
var isLearner bool
if i == 1 {
Expand Down Expand Up @@ -489,7 +488,6 @@ func TestClusterGenID(t *testing.T) {
}
previd := cs.ID()

cs.SetStore(mockstore.NewNop())
cs.AddMember(newTestMember(3, nil, "", nil), true)
cs.genID()
if cs.ID() == previd {
Expand Down Expand Up @@ -532,7 +530,6 @@ func TestNodeToMemberBad(t *testing.T) {
func TestClusterAddMember(t *testing.T) {
st := mockstore.NewRecorder()
c := newTestCluster(t, nil)
c.SetStore(st)
c.AddMember(newTestMember(1, nil, "node1", nil), true)

wactions := []testutil.Action{
Expand All @@ -555,7 +552,6 @@ func TestClusterAddMember(t *testing.T) {
func TestClusterAddMemberAsLearner(t *testing.T) {
st := mockstore.NewRecorder()
c := newTestCluster(t, nil)
c.SetStore(st)
c.AddMember(newTestMemberAsLearner(1, []string{}, "node1", []string{"http://node1"}), true)

wactions := []testutil.Action{
Expand Down Expand Up @@ -598,7 +594,6 @@ func TestClusterMembers(t *testing.T) {
func TestClusterRemoveMember(t *testing.T) {
st := mockstore.NewRecorder()
c := newTestCluster(t, nil)
c.SetStore(st)
c.RemoveMember(1, true)

wactions := []testutil.Action{
Expand Down Expand Up @@ -667,7 +662,6 @@ func newTestCluster(tb testing.TB, membs []*Member) *RaftCluster {
members: make(map[types.ID]*Member),
removed: make(map[types.ID]bool),
be: newMembershipBackend(),
v2store: v2store.New(),
}
for _, m := range membs {
c.members[m.ID] = m
Expand Down Expand Up @@ -1049,7 +1043,6 @@ func TestPromoteMember(t *testing.T) {
c := newTestCluster(t, tc.members)
st := v2store.New("/0", "/1")
c.Store(st)
c.SetStore(st)

c.PromoteMember(tc.promoteID, false)

Expand Down Expand Up @@ -1100,7 +1093,6 @@ func TestUpdateRaftAttributes(t *testing.T) {
c := newTestCluster(t, tc.members)
st := v2store.New("/0", "/1")
c.Store(st)
c.SetStore(st)

c.UpdateRaftAttributes(tc.updateMemberID, RaftAttributes{PeerURLs: newPeerURLs}, false)

Expand Down
Loading