From 32ef503e738b0f2e7388b2d5b994cb782fb425e9 Mon Sep 17 00:00:00 2001 From: Matthieu Rakotojaona Date: Fri, 16 Jun 2023 11:03:34 +0200 Subject: [PATCH] Display ids as decimal, not hexa --- controller.go | 2 +- internal/membership/pool.go | 6 +++--- internal/membership/pool_test.go | 2 +- internal/membership/remote.go | 8 ++++---- internal/raftengine/engine.go | 12 ++++++------ internal/raftengine/mux.go | 10 +++++----- node.go | 16 ++++++++-------- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/controller.go b/controller.go index 3f4ce1b..c8c075c 100644 --- a/controller.go +++ b/controller.go @@ -80,7 +80,7 @@ func (r *router) get(gid uint64) (transport.Controller, error) { defer r.mu.Unlock() ctrl, ok := r.ctrls[gid] if !ok { - return nil, fmt.Errorf("raft: unknown group id %x", gid) + return nil, fmt.Errorf("raft: unknown group id %d", gid) } return ctrl, nil } diff --git a/internal/membership/pool.go b/internal/membership/pool.go index a2bcb02..2a5f78d 100644 --- a/internal/membership/pool.go +++ b/internal/membership/pool.go @@ -98,7 +98,7 @@ func (p *pool) Update(m raftpb.Member) error { func (p *pool) Remove(m raftpb.Member) error { mem, ok := p.Get(m.ID) if !ok { - return fmt.Errorf("raft/membership: member %x not found", m.ID) + return fmt.Errorf("raft/membership: member %d not found", m.ID) } if mem.Type() == m.Type { @@ -109,7 +109,7 @@ func (p *pool) Remove(m raftpb.Member) error { defer p.mu.Unlock() if err := mem.Close(); err != nil { - p.logger.Warningf("raft.membership: closing member %x: %v", m.ID, err) + p.logger.Warningf("raft.membership: closing member %d: %v", m.ID, err) } mem, err := p.newMember(m) @@ -134,7 +134,7 @@ func (p *pool) Snapshot() []raftpb.Member { func (p *pool) Restore(membs []raftpb.Member) { for _, m := range membs { if err := p.Add(m); err != nil { - p.logger.Errorf("raft.membership: adding member %x: %v", m.ID, err) + p.logger.Errorf("raft.membership: adding member %d: %v", m.ID, err) } } } diff --git a/internal/membership/pool_test.go b/internal/membership/pool_test.go index deaab6f..39c16f6 100644 --- a/internal/membership/pool_test.go +++ b/internal/membership/pool_test.go @@ -75,7 +75,7 @@ func TestPoolRestore(t *testing.T) { for id := range ids { _, ok := p.Get(id) if !ok { - t.Errorf("pool have'nt add member %x during the restore", id) + t.Errorf("pool have'nt add member %d during the restore", id) } } } diff --git a/internal/membership/remote.go b/internal/membership/remote.go index 2a8babc..b4e89b0 100644 --- a/internal/membership/remote.go +++ b/internal/membership/remote.go @@ -45,7 +45,7 @@ func newRemote(cfg Config, m raftpb.Member) (Member, error) { r.raw.Store(m) cfg.Logger().V(5).Infof( - "raft.membership: setup pipelining for remote member %x [pipelines: %d, PipelineBufSize: %d]", + "raft.membership: setup pipelining for remote member %d [pipelines: %d, PipelineBufSize: %d]", m.ID, connPerPipeline, pipelineBufSize, @@ -103,7 +103,7 @@ func (r *remote) Send(msg etcdraftpb.Message) (err error) { case <-r.ctx.Done(): return r.ctx.Err() default: - return fmt.Errorf("cluster member %x, buffer is full (overloaded network)", r.ID()) + return fmt.Errorf("cluster member %d, buffer is full (overloaded network)", r.ID()) } return @@ -210,9 +210,9 @@ func (r *remote) process(ctx context.Context) { rpc := r.client() err := rpc.Message(ctx, msg) if err != nil && !errors.Is(err, perr) || err != nil && r.logger.V(3).Enabled() { - r.logger.Errorf("raft.membership: sending message to member %x: %v", r.ID(), err) + r.logger.Errorf("raft.membership: sending message to member %d: %v", r.ID(), err) } else if err == nil && perr != nil { - r.logger.Infof("raft.membership: sending message to member %x succeed", r.ID()) + r.logger.Infof("raft.membership: sending message to member %d succeed", r.ID()) } perr = err r.report(msg, err) diff --git a/internal/raftengine/engine.go b/internal/raftengine/engine.go index 2b3489c..43f5bd0 100644 --- a/internal/raftengine/engine.go +++ b/internal/raftengine/engine.go @@ -271,7 +271,7 @@ func (eng *engine) TransferLeadership(ctx context.Context, transferee uint64) er eng.propwg.Add(1) defer eng.propwg.Done() - eng.logger.Infof("raft.engine: start transfer leadership %x -> %x", eng.node.Status().Lead, transferee) + eng.logger.Infof("raft.engine: start transfer leadership %d -> %d", eng.node.Status().Lead, transferee) eng.node.TransferLeadership(ctx, eng.node.Status().Lead, transferee) ticker := time.NewTicker(eng.cfg.TickInterval() / 10) @@ -592,7 +592,7 @@ func (eng *engine) publishConfChange(ent etcdraftpb.Entry) { // to make sure the commit ack sent before closing connection. case <-time.After(eng.cfg.TickInterval() * 2): if err := eng.pool.Remove(mem); err != nil { - eng.logger.Errorf("raft.engine: removing member %x: %v", mem.ID, err) + eng.logger.Errorf("raft.engine: removing member %d: %v", mem.ID, err) } case <-eng.ctx.Done(): return @@ -625,7 +625,7 @@ func (eng *engine) process(c chan etcdraftpb.Message) { func (eng *engine) send(msgs []etcdraftpb.Message) { lg := func(m etcdraftpb.Message, str string) { eng.logger.Warningf( - "raft.engine: sending message %s to member %x: %v", + "raft.engine: sending message %s to member %d: %v", m.Type, m.To, str, @@ -694,11 +694,11 @@ func (eng *engine) promotions() { } for _, m := range promotions { - eng.logger.Infof("raft.engine: promoting staging member %x", m.ID) + eng.logger.Infof("raft.engine: promoting staging member %d", m.ID) ctx, cancel := context.WithTimeout(eng.ctx, eng.cfg.TickInterval()*5) _, err := eng.proposeConfChange(ctx, &m, etcdraftpb.ConfChangeAddNode) if err != nil { - eng.logger.Warningf("raft.engine: promoting staging member %x: %v", m.ID, err) + eng.logger.Warningf("raft.engine: promoting staging member %d: %v", m.ID, err) } cancel() } @@ -735,7 +735,7 @@ func (eng *engine) forceSnapshot(msg etcdraftpb.Message) bool { return false } - eng.logger.V(1).Infof("raft.engine: force new snapshot %x it is not in the ConfState", msg.To) + eng.logger.V(1).Infof("raft.engine: force new snapshot %d it is not in the ConfState", msg.To) // report snapshot failure, to re-send the new snapshot. defer eng.ReportSnapshot(msg.To, raft.SnapshotFailure) diff --git a/internal/raftengine/mux.go b/internal/raftengine/mux.go index f923ee2..d24abb9 100644 --- a/internal/raftengine/mux.go +++ b/internal/raftengine/mux.go @@ -92,12 +92,12 @@ func (m *mux) Start() { if n.lead != st.Lead { if st.Lead != 0 { if n.lead == 0 { - n.cfg.Logger.Infof("raft.node: %x elected leader %x at term %d", st.ID, st.Lead, st.Term) + n.cfg.Logger.Infof("raft.node: %d elected leader %d at term %d", st.ID, st.Lead, st.Term) } else { - n.cfg.Logger.Infof("raft.node: %x changed leader from %x to %x at term %d", st.ID, n.lead, st.Lead, st.Term) + n.cfg.Logger.Infof("raft.node: %d changed leader from %d to %d at term %d", st.ID, n.lead, st.Lead, st.Term) } } else { - n.cfg.Logger.Infof("raft.node: %x lost leader %x at term %d", st.ID, n.lead, st.Term) + n.cfg.Logger.Infof("raft.node: %d lost leader %d at term %d", st.ID, n.lead, st.Term) } n.lead = st.Lead } @@ -116,7 +116,7 @@ func (m *mux) Start() { case op := <-m.operationc: node = nodes[op.gid] if node == nil && op.ot != add { - raftlog.Warningf("raft: unknown group %x", op.gid) + raftlog.Warningf("raft: unknown group %d", op.gid) close(op.done) continue } @@ -560,7 +560,7 @@ func (h *heartbeats) fanout(nodes map[uint64]*nodeState, msg etcdraftpb.Message) } if node == nil { - raftlog.Warningf("raft: ignored heartbeat from unknown member %x", msg.From) + raftlog.Warningf("raft: ignored heartbeat from unknown member %d", msg.From) return } diff --git a/node.go b/node.go index b064e1e..d7a1f3f 100644 --- a/node.go +++ b/node.go @@ -570,7 +570,7 @@ func (n *Node) promoteMember(ctx context.Context, id uint64, forwarded bool) err return err } - n.cfg.logger.V(3).Infof("raft.node: forwarding member %x promotion to %x", id, lmem.ID()) + n.cfg.logger.V(3).Infof("raft.node: forwarding member %d promotion to %d", id, lmem.ID()) return client.PromoteMember(ctx, raw) } @@ -578,7 +578,7 @@ func (n *Node) promoteMember(ctx context.Context, id uint64, forwarded bool) err learner := rs.Progress[id].Match // the learner's Match not caught up with the leader yet. if float64(learner) < float64(leader)*0.9 { - return fmt.Errorf("raft: promotion failed, memebr %x not synced with the leader yet", id) + return fmt.Errorf("raft: promotion failed, memebr %d not synced with the leader yet", id) } (&raw).Type = VoterMember @@ -615,7 +615,7 @@ func available() func(c *Node) error { func notMember(id uint64) func(c *Node) error { return func(c *Node) error { if _, ok := c.GetMemebr(id); !ok { - return fmt.Errorf("raft: unknown member %x", id) + return fmt.Errorf("raft: unknown member %d", id) } return nil } @@ -625,7 +625,7 @@ func memberRemoved(id uint64) func(c *Node) error { return func(c *Node) error { m, ok := c.GetMemebr(id) if ok && m.Type() == RemovedMember { - return fmt.Errorf("raft: member %x removed", id) + return fmt.Errorf("raft: member %d removed", id) } return nil } @@ -638,7 +638,7 @@ func addressInUse(mid uint64, addr string) func(c *Node) error { }) if len(membs) > 0 { - return fmt.Errorf("raft: address used by member %x", membs[0].ID()) + return fmt.Errorf("raft: address used by member %d", membs[0].ID()) } return nil } @@ -656,7 +656,7 @@ func notLeader() func(c *Node) error { func leader(id uint64) func(c *Node) error { return func(c *Node) error { if id == c.Leader() { - return fmt.Errorf("raft: operation not permitted, member %x is the leader, transfer leadership first", id) + return fmt.Errorf("raft: operation not permitted, member %d is the leader, transfer leadership first", id) } return nil } @@ -665,7 +665,7 @@ func leader(id uint64) func(c *Node) error { func idInUse(id uint64) func(c *Node) error { return func(c *Node) error { if _, ok := c.GetMemebr(id); ok { - return fmt.Errorf("raft: id used by member %x", id) + return fmt.Errorf("raft: id used by member %d", id) } return nil } @@ -694,7 +694,7 @@ func notType(id uint64, t MemberType) func(c *Node) error { return func(c *Node) error { mem, _ := c.GetMemebr(id) if mt := mem.Type(); mt != t { - return fmt.Errorf("raft: memebr (%x) is a %s not a %s", id, mt, t) + return fmt.Errorf("raft: memebr (%d) is a %s not a %s", id, mt, t) } return nil }