mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: clearify that the firstIndex might not be available.
This commit is contained in:
parent
b7ca56e3c8
commit
2f5b748a90
@ -261,6 +261,8 @@ func (l *raftLog) slice(lo uint64, hi uint64) []pb.Entry {
|
||||
// This should never fail because it has been checked before.
|
||||
log.Panicf("entries[%d:%d) from storage is out of bound", lo, min(hi, l.unstable.offset))
|
||||
return nil
|
||||
} else if err == ErrUnavailable {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
panic(err) // TODO(bdarnell)
|
||||
}
|
||||
|
@ -34,10 +34,11 @@ type unstable struct {
|
||||
offset uint64
|
||||
}
|
||||
|
||||
// maybeFirstIndex returns the first index if it has a snapshot.
|
||||
// maybeFirstIndex returns the index of the first possible entry in entries
|
||||
// if it has a snapshot.
|
||||
func (u *unstable) maybeFirstIndex() (uint64, bool) {
|
||||
if u.snapshot != nil {
|
||||
return u.snapshot.Metadata.Index, true
|
||||
return u.snapshot.Metadata.Index + 1, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ import (
|
||||
// index is unavailable because it predates the last snapshot.
|
||||
var ErrCompacted = errors.New("requested index is unavailable due to compaction")
|
||||
|
||||
var ErrUnavailable = errors.New("requested entry at index is unavailable")
|
||||
|
||||
// Storage is an interface that may be implemented by the application
|
||||
// to retrieve log entries from storage.
|
||||
//
|
||||
@ -47,8 +49,9 @@ type Storage interface {
|
||||
// LastIndex returns the index of the last entry in the log.
|
||||
LastIndex() (uint64, error)
|
||||
// FirstIndex returns the index of the first log entry that is
|
||||
// available via Entries (older entries have been incorporated
|
||||
// into the latest Snapshot).
|
||||
// possibly available via Entries (older entries have been incorporated
|
||||
// into the latest Snapshot; if storage only contains the dummy entry the
|
||||
// first log entry is not available).
|
||||
FirstIndex() (uint64, error)
|
||||
// Snapshot returns the most recent snapshot.
|
||||
Snapshot() (pb.Snapshot, error)
|
||||
@ -95,6 +98,10 @@ func (ms *MemoryStorage) Entries(lo, hi uint64) ([]pb.Entry, error) {
|
||||
if lo <= offset {
|
||||
return nil, ErrCompacted
|
||||
}
|
||||
// only contains dummy entries.
|
||||
if len(ms.ents) == 1 {
|
||||
return nil, ErrUnavailable
|
||||
}
|
||||
return ms.ents[lo-offset : hi-offset], nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user