History

Allow empty logs after a fresh wal.Open

See #33

tidwall committed 1 year ago

Commit 602cbd21 parent 1f6190c2 files · +17 −1Browse files

Unified · Split

2 files
  1. wal.go +1 −1
  2. wal_test.go +16 −0
wal.go+1−1
@@ -294,7 +294,7 @@ func (l *Log) load() error { · 293 unmodified lines
294 return err294 return err
295 }295 }
296 l.lastIndex = lseg.index + uint64(len(lseg.epos)) - 1296 l.lastIndex = lseg.index + uint64(len(lseg.epos)) - 1
297 if l.firstIndex > l.lastIndex && !l.opts.AllowEmpty {297 if l.lastIndex > 0 && l.firstIndex > l.lastIndex && !l.opts.AllowEmpty {
298 return ErrEmptyLog298 return ErrEmptyLog
299 }299 }
300 return nil300 return nil
wal_test.go+16−0
@@ -1326,3 +1326,19 @@ func TestEmptyTruncateBackTwice(t *testing.T) { · 1325 unmodified lines
1326 t.Fatalf("expected %v, got %v", true, empty)1326 t.Fatalf("expected %v, got %v", true, empty)
1327 }1327 }
1328}1328}
1329
1330func TestIssue33(t *testing.T) {
1331 // Create a fresh log without allowempty, close, and reopen.
1332 // This should not fail with an ErrEmptyLog
1333 os.RemoveAll("testlog")
1334 l, err := Open("log", nil)
1335 if err != nil {
1336 t.Fatal(err)
1337 }
1338 l.Close()
1339 l, err = Open("log", nil)
1340 if err != nil {
1341 t.Fatal(err)
1342 }
1343 l.Close()
1344}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t