Skip to content

Commit

Permalink
Merge pull request #9176 from dvonthenen/feature/issue9123
Browse files Browse the repository at this point in the history
Expose Raft Applied Index through to "etcdctl endpoint status"
  • Loading branch information
xiang90 committed Jan 22, 2018
2 parents 5cce650 + 25cdf4e commit 202cc9a
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 241 deletions.
5 changes: 5 additions & 0 deletions Documentation/dev-guide/apispec/swagger/rpc.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,11 @@
"type": "string",
"format": "uint64"
},
"raftAppliedIndex": {
"description": "appliedIndex is the current raft applied index of the responding member.",
"type": "string",
"format": "uint64"
},
"raftIndex": {
"description": "raftIndex is the current raft index of the responding member.",
"type": "string",
Expand Down
3 changes: 2 additions & 1 deletion etcdctl/ctlv3/command/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func makeMemberListTable(r v3.MemberListResponse) (hdr []string, rows [][]string
}

func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]string) {
hdr = []string{"endpoint", "ID", "version", "db size", "is leader", "raft term", "raft index"}
hdr = []string{"endpoint", "ID", "version", "db size", "is leader", "raft term", "raft index", "raft applied index"}
for _, status := range statusList {
rows = append(rows, []string{
status.Ep,
Expand All @@ -183,6 +183,7 @@ func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]stri
fmt.Sprint(status.Resp.Leader == status.Resp.Header.MemberId),
fmt.Sprint(status.Resp.RaftTerm),
fmt.Sprint(status.Resp.RaftIndex),
fmt.Sprint(status.Resp.RaftAppliedIndex),
})
}
return hdr, rows
Expand Down
1 change: 1 addition & 0 deletions etcdctl/ctlv3/command/printer_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (p *fieldsPrinter) EndpointStatus(eps []epStatus) {
fmt.Println(`"Leader" :`, ep.Resp.Leader)
fmt.Println(`"RaftIndex" :`, ep.Resp.RaftIndex)
fmt.Println(`"RaftTerm" :`, ep.Resp.RaftTerm)
fmt.Println(`"RaftAppliedIndex" :`, ep.Resp.RaftAppliedIndex)
fmt.Printf("\"Endpoint\" : %q\n", ep.Ep)
fmt.Println()
}
Expand Down
13 changes: 7 additions & 6 deletions etcdserver/api/v3rpc/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,13 @@ func (ms *maintenanceServer) Alarm(ctx context.Context, ar *pb.AlarmRequest) (*p

func (ms *maintenanceServer) Status(ctx context.Context, ar *pb.StatusRequest) (*pb.StatusResponse, error) {
resp := &pb.StatusResponse{
Header: &pb.ResponseHeader{Revision: ms.hdr.rev()},
Version: version.Version,
DbSize: ms.bg.Backend().Size(),
Leader: uint64(ms.rg.Leader()),
RaftIndex: ms.rg.Index(),
RaftTerm: ms.rg.Term(),
Header: &pb.ResponseHeader{Revision: ms.hdr.rev()},
Version: version.Version,
DbSize: ms.bg.Backend().Size(),
Leader: uint64(ms.rg.Leader()),
RaftIndex: ms.rg.Index(),
RaftTerm: ms.rg.Term(),
RaftAppliedIndex: ms.rg.AppliedIndex(),
}
ms.hdr.fill(resp.Header)
return resp, nil
Expand Down
499 changes: 268 additions & 231 deletions etcdserver/etcdserverpb/rpc.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions etcdserver/etcdserverpb/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,8 @@ message StatusResponse {
uint64 raftIndex = 5;
// raftTerm is the current raft term of the responding member.
uint64 raftTerm = 6;
// raftAppliedIndex is the current raft applied index of the responding member.
uint64 raftAppliedIndex = 7;
}

message AuthEnableRequest {
Expand Down
8 changes: 5 additions & 3 deletions etcdserver/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func init() {

type RaftTimer interface {
Index() uint64
AppliedIndex() uint64
Term() uint64
}

Expand All @@ -91,9 +92,10 @@ type raftNode struct {
// Cache of the latest raft index and raft term the server has seen.
// These three unit64 fields must be the first elements to keep 64-bit
// alignment for atomic access to the fields.
index uint64
term uint64
lead uint64
index uint64
appliedindex uint64
term uint64
lead uint64

raftNodeConfig

Expand Down
3 changes: 3 additions & 0 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,8 @@ func (s *EtcdServer) UpdateMember(ctx context.Context, memb membership.Member) (

func (s *EtcdServer) Index() uint64 { return atomic.LoadUint64(&s.r.index) }

func (s *EtcdServer) AppliedIndex() uint64 { return atomic.LoadUint64(&s.r.appliedindex) }

func (s *EtcdServer) Term() uint64 { return atomic.LoadUint64(&s.r.term) }

// Lead is only for testing purposes.
Expand Down Expand Up @@ -1667,6 +1669,7 @@ func (s *EtcdServer) getAppliedIndex() uint64 {

func (s *EtcdServer) setAppliedIndex(v uint64) {
atomic.StoreUint64(&s.appliedIndex, v)
atomic.StoreUint64(&s.r.appliedindex, v)
}

func (s *EtcdServer) getCommittedIndex() uint64 {
Expand Down

0 comments on commit 202cc9a

Please sign in to comment.