From 29911e9a5b6bbe636b921637abf2e8558927f69c Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Wed, 28 Sep 2022 11:01:26 +0800 Subject: [PATCH] etcdserver: fix memberID equals to zero in corruption alarm Signed-off-by: Benjamin Wang --- etcdserver/corrupt.go | 25 ++++++++++++------------- tests/e2e/ctl_v3_alarm_test.go | 8 +++++++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/etcdserver/corrupt.go b/etcdserver/corrupt.go index e243d98ba6d..0c696cefbc9 100644 --- a/etcdserver/corrupt.go +++ b/etcdserver/corrupt.go @@ -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, } @@ -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 @@ -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 { @@ -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 @@ -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 @@ -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 { diff --git a/tests/e2e/ctl_v3_alarm_test.go b/tests/e2e/ctl_v3_alarm_test.go index a8bc38483d1..d8bdabf9437 100644 --- a/tests/e2e/ctl_v3_alarm_test.go +++ b/tests/e2e/ctl_v3_alarm_test.go @@ -16,6 +16,7 @@ package e2e import ( "context" + "fmt" "os" "strings" "testing" @@ -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 { @@ -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) }