Skip to content
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

[3.4] etcdserver: fix memberID equals to zero in corruption alarm #14530

Merged
merged 1 commit into from
Sep 28, 2022
Merged
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
25 changes: 12 additions & 13 deletions etcdserver/corrupt.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ func (s *EtcdServer) checkHashKV() error {
}

alarmed := false
mismatch := func(id uint64) {
mismatch := func(id types.ID) {
if alarmed {
return
}
alarmed = true
a := &pb.AlarmRequest{
MemberID: id,
MemberID: uint64(id),
Action: pb.AlarmRequest_ACTIVATE,
Alarm: pb.AlarmType_CORRUPT,
}
Expand All @@ -231,7 +231,7 @@ func (s *EtcdServer) checkHashKV() error {
} else {
plog.Warningf("mismatched hashes %d and %d for revision %d", h, h2, rev)
}
mismatch(uint64(s.ID()))
mismatch(s.ID())
}

checkedCount := 0
Expand All @@ -240,7 +240,6 @@ func (s *EtcdServer) checkHashKV() error {
continue
}
checkedCount++
id := p.resp.Header.MemberId

// leader expects follower's latest revision less than or equal to leader's
if p.resp.Header.Revision > rev2 {
Expand All @@ -249,16 +248,16 @@ func (s *EtcdServer) checkHashKV() error {
"revision from follower must be less than or equal to leader's",
zap.Int64("leader-revision", rev2),
zap.Int64("follower-revision", p.resp.Header.Revision),
zap.String("follower-peer-id", types.ID(id).String()),
zap.String("follower-peer-id", p.id.String()),
)
} else {
plog.Warningf(
"revision %d from member %v, expected at most %d",
p.resp.Header.Revision,
types.ID(id),
p.id,
rev2)
}
mismatch(id)
mismatch(p.id)
}

// leader expects follower's latest compact revision less than or equal to leader's
Expand All @@ -268,17 +267,17 @@ func (s *EtcdServer) checkHashKV() error {
"compact revision from follower must be less than or equal to leader's",
zap.Int64("leader-compact-revision", crev2),
zap.Int64("follower-compact-revision", p.resp.CompactRevision),
zap.String("follower-peer-id", types.ID(id).String()),
zap.String("follower-peer-id", p.id.String()),
)
} else {
plog.Warningf(
"compact revision %d from member %v, expected at most %d",
p.resp.CompactRevision,
types.ID(id),
p.id,
crev2,
)
}
mismatch(id)
mismatch(p.id)
}

// follower's compact revision is leader's old one, then hashes must match
Expand All @@ -290,18 +289,18 @@ func (s *EtcdServer) checkHashKV() error {
zap.Uint32("leader-hash", h),
zap.Int64("follower-compact-revision", p.resp.CompactRevision),
zap.Uint32("follower-hash", p.resp.Hash),
zap.String("follower-peer-id", types.ID(id).String()),
zap.String("follower-peer-id", p.id.String()),
)
} else {
plog.Warningf(
"hash %d at revision %d from member %v, expected hash %d",
p.resp.Hash,
rev,
types.ID(id),
p.id,
h,
)
}
mismatch(id)
mismatch(p.id)
}
}
if lg != nil {
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/ctl_v3_alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package e2e

import (
"context"
"fmt"
"os"
"strings"
"testing"
Expand All @@ -36,6 +37,11 @@ func alarmTest(cx ctlCtx) {
cx.t.Fatal(err)
}

memberList, err := getMemberList(cx)
if err != nil {
cx.t.Fatalf("Unexpected error: %v", err)
}

// write some chunks to fill up the database
buf := strings.Repeat("b", os.Getpagesize())
for {
Expand All @@ -48,7 +54,7 @@ func alarmTest(cx ctlCtx) {
}

// quota alarm should now be on
if err := ctlV3Alarm(cx, "list", "alarm:NOSPACE"); err != nil {
if err := ctlV3Alarm(cx, "list", fmt.Sprintf("memberID:%d alarm:NOSPACE", memberList.Members[0].ID)); err != nil {
cx.t.Fatal(err)
}

Expand Down