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
13 changes: 9 additions & 4 deletions wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -173,7 +172,7 @@ func (l *Log) pushCache(segIdx int) {

// load all the segments. This operation also cleans up any START/END segments.
func (l *Log) load() error {
fis, err := ioutil.ReadDir(l.path)
fis, err := os.ReadDir(l.path)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is using go version 1.13 which os.ReadDir function doesn't exist.

if err != nil {
return err
}
Expand Down Expand Up @@ -530,14 +529,14 @@ func (l *Log) findSegment(index uint64) int {
}

func (l *Log) loadSegmentEntries(s *segment) error {
data, err := ioutil.ReadFile(s.path)
data, err := os.ReadFile(s.path)
if err != nil {
return err
}
ebuf := data
var epos []bpos
var pos int
for exidx := s.index; len(data) > 0; exidx++ {
for len(data) > 0 {
var n int
if l.opts.LogFormat == JSON {
n, err = loadNextJSONEntry(data)
Expand Down Expand Up @@ -742,6 +741,9 @@ func (l *Log) truncateFront(index uint64) (err error) {
}
return f.Close()
}()
if err != nil {
return err
}
// Rename the TEMP file to it's START file name.
startName := filepath.Join(l.path, segmentName(index)+".START")
if err = os.Rename(tempName, startName); err != nil {
Expand Down Expand Up @@ -848,6 +850,9 @@ func (l *Log) truncateBack(index uint64) (err error) {
}
return f.Close()
}()
if err != nil {
return err
}
// Rename the TEMP file to it's END file name.
endName := filepath.Join(l.path, segmentName(s.index)+".END")
if err = os.Rename(tempName, endName); err != nil {
Expand Down
17 changes: 11 additions & 6 deletions wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ func testLog(t *testing.T, opts *Options, N int) {
}
N++

l.Sync()
if err = l.Sync(); err != nil {
t.Fatal(err)
}
testFirstLast(t, l, uint64(N-1), uint64(N), nil)
}

Expand Down Expand Up @@ -519,29 +521,32 @@ func TestOutliers(t *testing.T) {
t.Run("fail-corrupted-tail-json", func(t *testing.T) {
defer os.RemoveAll("testlog/corrupt-tail")
opts := makeOpts(512, true, JSON)
os.MkdirAll("testlog/corrupt-tail", 0777)
ioutil.WriteFile(
if err := os.MkdirAll("testlog/corrupt-tail", 0777); err != nil {
t.Fatal(err)
}

_ = ioutil.WriteFile(
"testlog/corrupt-tail/00000000000000000001",
[]byte("\n"), 0666)
if l, err := Open("testlog/corrupt-tail", opts); err != ErrCorrupt {
l.Close()
t.Fatalf("expected %v, got %v", ErrCorrupt, err)
}
ioutil.WriteFile(
_ = ioutil.WriteFile(
"testlog/corrupt-tail/00000000000000000001",
[]byte(`{}`+"\n"), 0666)
if l, err := Open("testlog/corrupt-tail", opts); err != ErrCorrupt {
l.Close()
t.Fatalf("expected %v, got %v", ErrCorrupt, err)
}
ioutil.WriteFile(
_ = ioutil.WriteFile(
"testlog/corrupt-tail/00000000000000000001",
[]byte(`{"index":"1"}`+"\n"), 0666)
if l, err := Open("testlog/corrupt-tail", opts); err != ErrCorrupt {
l.Close()
t.Fatalf("expected %v, got %v", ErrCorrupt, err)
}
ioutil.WriteFile(
_ = ioutil.WriteFile(
"testlog/corrupt-tail/00000000000000000001",
[]byte(`{"index":"1","data":"?"}`), 0666)
if l, err := Open("testlog/corrupt-tail", opts); err != ErrCorrupt {
Expand Down