Add Server.LastCommandName().
parent
894eb08592
commit
ba9b7739e4
12
log.go
12
log.go
|
@ -73,6 +73,18 @@ func (l *Log) IsEmpty() bool {
|
||||||
return (len(l.entries) == 0)
|
return (len(l.entries) == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The name of the last command in the log.
|
||||||
|
func (l *Log) LastCommandName() string {
|
||||||
|
l.mutex.Lock()
|
||||||
|
defer l.mutex.Unlock()
|
||||||
|
if len(l.entries) > 0 {
|
||||||
|
if command := l.entries[len(l.entries)-1].Command; command != nil {
|
||||||
|
return command.CommandName()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
// Log Terms
|
// Log Terms
|
||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
|
|
14
server.go
14
server.go
|
@ -150,17 +150,31 @@ func (s *Server) VotedFor() string {
|
||||||
|
|
||||||
// Retrieves whether the server's log has no entries.
|
// Retrieves whether the server's log has no entries.
|
||||||
func (s *Server) IsLogEmpty() bool {
|
func (s *Server) IsLogEmpty() bool {
|
||||||
|
s.mutex.Lock()
|
||||||
|
defer s.mutex.Unlock()
|
||||||
return s.log.IsEmpty()
|
return s.log.IsEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
// A list of all the log entries. This should only be used for debugging purposes.
|
// A list of all the log entries. This should only be used for debugging purposes.
|
||||||
func (s *Server) LogEntries() []*LogEntry {
|
func (s *Server) LogEntries() []*LogEntry {
|
||||||
|
s.mutex.Lock()
|
||||||
|
defer s.mutex.Unlock()
|
||||||
if s.log != nil {
|
if s.log != nil {
|
||||||
return s.log.entries
|
return s.log.entries
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A reference to the command name of the last entry.
|
||||||
|
func (s *Server) LastCommandName() string {
|
||||||
|
s.mutex.Lock()
|
||||||
|
defer s.mutex.Unlock()
|
||||||
|
if s.log != nil {
|
||||||
|
return s.log.LastCommandName()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
// Membership
|
// Membership
|
||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue