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

Display ids as decimal, not hexa #20

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment.

}
return ctrl, nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/membership/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/membership/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/membership/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions internal/raftengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/raftengine/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
16 changes: 8 additions & 8 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,15 @@ 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)
}

leader := rs.Progress[rs.Lead].Match
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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down