Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Clement <[email protected]>
  • Loading branch information
clement2026 committed Sep 25, 2024
1 parent 96d8985 commit 7f0ada2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
12 changes: 6 additions & 6 deletions server/etcdserver/memory_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
}
9 changes: 3 additions & 6 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit 7f0ada2

Please sign in to comment.