Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ func testChecksumPages(t *testing.T, fileSize, nPages, pageSize, nWorkers uint32
if err != nil {
t.Fatal(err)
}
defer f.Close()
t.Cleanup(func() {
if err := f.Close(); err != nil {
t.Error(err)
}
})
if _, err := io.CopyN(f, rand.Reader, int64(fileSize)); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -108,12 +112,16 @@ func testChecksumPages(t *testing.T, fileSize, nPages, pageSize, nWorkers uint32
}

// logic copied from litefs repo
func legacyChecksumPages(dbPath string, pageSize, nPages uint32, checksums []Checksum) (uint32, error) {
func legacyChecksumPages(dbPath string, pageSize, nPages uint32, checksums []Checksum) (lastPage uint32, err error) {
f, err := os.Open(dbPath)
if err != nil {
return 0, err
}
defer f.Close()
defer func() {
if closeErr := f.Close(); err == nil {
err = closeErr
}
}()

buf := make([]byte, pageSize)

Expand Down
9 changes: 5 additions & 4 deletions ltx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"io"
"math"
"math/rand"
"math/rand/v2"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -695,7 +695,7 @@ func BenchmarkChecksumPage(b *testing.B) {

func benchmarkChecksumPage(b *testing.B, pageSize int) {
data := make([]byte, pageSize)
_, _ = rand.Read(data)
_, _ = rand.NewChaCha8([32]byte{}).Read(data)
b.ReportAllocs()
b.SetBytes(int64(pageSize))
b.ResetTimer()
Expand All @@ -715,7 +715,7 @@ func BenchmarkChecksumPageWithHasher(b *testing.B) {

func benchmarkChecksumPageWithHasher(b *testing.B, pageSize int) {
data := make([]byte, pageSize)
_, _ = rand.Read(data)
_, _ = rand.NewChaCha8([32]byte{}).Read(data)
b.ReportAllocs()
b.SetBytes(int64(pageSize))
b.ResetTimer()
Expand All @@ -733,8 +733,9 @@ func BenchmarkXOR(b *testing.B) {

m := make(map[uint32]ltx.Checksum)
page := make([]byte, pageSize)
rnd := rand.NewChaCha8([32]byte{})
for pgno := uint32(1); pgno <= pageN; pgno++ {
_, _ = rand.Read(page)
_, _ = rnd.Read(page)
m[pgno] = ltx.ChecksumPage(pgno, page)
}
b.SetBytes(int64(pageN * pageSize))
Expand Down
Loading