Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Context.CommitIndex().

  • Loading branch information...
commit b50c4eb1889fc6c49881887bc6d5ecd5985b70ee 1 parent 4d569a8
@benbjohnson benbjohnson authored
Showing with 13 additions and 1 deletion.
  1. +7 −0 context.go
  2. +6 −1 server.go
View
7 context.go
@@ -7,6 +7,7 @@ type Context interface {
Server() Server
CurrentTerm() uint64
CurrentIndex() uint64
+ CommitIndex() uint64
}
// context is the concrete implementation of Context.
@@ -14,6 +15,7 @@ type context struct {
server Server
currentIndex uint64
currentTerm uint64
+ commitIndex uint64
}
// Server returns a reference to the server.
@@ -30,3 +32,8 @@ func (c *context) CurrentTerm() uint64 {
func (c *context) CurrentIndex() uint64 {
return c.currentIndex
}
+
+// CommitIndex returns last commit index the server is at.
+func (c *context) CommitIndex() uint64 {
+ return c.commitIndex
+}
View
7 server.go
@@ -173,7 +173,12 @@ func NewServer(name string, path string, transporter Transporter, stateMachine S
s.log.ApplyFunc = func(c Command) (interface{}, error) {
switch c := c.(type) {
case CommandApply:
- return c.Apply(&context{server: s, currentTerm: s.currentTerm, currentIndex: s.log.currentIndex()})
+ return c.Apply(&context{
+ server: s,
+ currentTerm: s.currentTerm,
+ currentIndex: s.log.currentIndex(),
+ commitIndex: s.log.commitIndex,
+ })
case deprecatedCommandApply:
return c.Apply(s)
default:
Please sign in to comment.
Something went wrong with that request. Please try again.