mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
apply suggestions
Signed-off-by: Clement <gh.2lgqz@aleeas.com>
This commit is contained in:
parent
96d898579a
commit
7f0ada26c6
@ -23,10 +23,9 @@ import (
|
||||
"go.etcd.io/raft/v3/raftpb"
|
||||
)
|
||||
|
||||
// TestMemoryStorageCompaction tests that after calling raftStorage.Compact(compacti)
|
||||
// without errors, the dummy entry becomes {Index: compacti} and
|
||||
// raftStorage.FirstIndex() returns (compacti+1, nil).
|
||||
func TestMemoryStorageCompaction(t *testing.T) {
|
||||
// TestMemoryStorageCompactInclusive tests that compacting is inclusive,
|
||||
// meaning the first index after compaction is larger by one than compacted index.
|
||||
func TestMemoryStorageCompactInclusive(t *testing.T) {
|
||||
// entries: [ {Index: 0} ]
|
||||
raftStorage := raft.NewMemoryStorage()
|
||||
|
||||
@ -57,11 +56,12 @@ func TestMemoryStorageCompaction(t *testing.T) {
|
||||
|
||||
// after compacting, entries should be:
|
||||
// [ {Index: 3}, {Index: 4}, {Index: 5} ]
|
||||
err = raftStorage.Compact(3)
|
||||
compacti := uint64(3)
|
||||
err = raftStorage.Compact(compacti)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
||||
firstIndex, err = raftStorage.FirstIndex()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, uint64(3+1), firstIndex)
|
||||
assert.Equal(t, compacti+1, firstIndex)
|
||||
}
|
||||
|
@ -818,12 +818,9 @@ func (s *EtcdServer) run() {
|
||||
snapi: sn.Metadata.Index,
|
||||
appliedt: sn.Metadata.Term,
|
||||
appliedi: sn.Metadata.Index,
|
||||
// compacti is the index from the last time raftStorage.Compact was called
|
||||
// without errors.
|
||||
//
|
||||
// After calling raftStorage.Compact(compacti) without errors, the dummy entry of
|
||||
// raftStorage becomes {Index: compacti}, and raftStorage.FirstIndex() returns
|
||||
// (compacti+1, nil). This is validated by TestMemoryStorageCompaction.
|
||||
// Compaction is inclusive, meaning compact index should be lower by one
|
||||
// than the first index after compaction.
|
||||
// This is validated by TestMemoryStorageCompaction.
|
||||
compacti: firstRaftIndex - 1,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user