raft: set logger to raft so log context such as multinode groupID can be logged

This commit is contained in:
es-chow
2015-08-10 23:04:38 +08:00
parent 042afcf2a3
commit cc362ccdad
6 changed files with 100 additions and 76 deletions

View File

@@ -26,6 +26,8 @@ type unstable struct {
// all entries that have not yet been written to storage.
entries []pb.Entry
offset uint64
logger Logger
}
// maybeFirstIndex returns the index of the first possible entry in entries
@@ -106,7 +108,7 @@ func (u *unstable) truncateAndAppend(ents []pb.Entry) {
// directly append
u.entries = append(u.entries, ents...)
case after < u.offset:
raftLogger.Infof("replace the unstable entries from index %d", after+1)
u.logger.Infof("replace the unstable entries from index %d", after+1)
// The log is being truncated to before our current offset
// portion, so set the offset and replace the entries
u.offset = after + 1
@@ -114,7 +116,7 @@ func (u *unstable) truncateAndAppend(ents []pb.Entry) {
default:
// truncate to after and copy to u.entries
// then append
raftLogger.Infof("truncate the unstable entries to index %d", after)
u.logger.Infof("truncate the unstable entries to index %d", after)
u.entries = append([]pb.Entry{}, u.slice(u.offset, after+1)...)
u.entries = append(u.entries, ents...)
}
@@ -128,10 +130,10 @@ func (u *unstable) slice(lo uint64, hi uint64) []pb.Entry {
// u.offset <= lo <= hi <= u.offset+len(u.offset)
func (u *unstable) mustCheckOutOfBounds(lo, hi uint64) {
if lo > hi {
raftLogger.Panicf("invalid unstable.slice %d > %d", lo, hi)
u.logger.Panicf("invalid unstable.slice %d > %d", lo, hi)
}
upper := u.offset + uint64(len(u.entries))
if lo < u.offset || hi > upper {
raftLogger.Panicf("unstable.slice[%d,%d) out of bound [%d,%d]", lo, hi, u.offset, upper)
u.logger.Panicf("unstable.slice[%d,%d) out of bound [%d,%d]", lo, hi, u.offset, upper)
}
}