Skip to content

Commit

Permalink
no need to return err in pendingWrites
Browse files Browse the repository at this point in the history
  • Loading branch information
roseduan committed Sep 23, 2023
1 parent 0753d5a commit b73e88f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions benchmark/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ func BenchmarkWAL_WriteBatch(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for j := 0; j < 31; j++ {
err := walFile.PendingWrites([]byte(strings.Repeat("X", wal.MB)))
assert.Nil(b, err)
walFile.PendingWrites([]byte(strings.Repeat("X", wal.MB)))
}
err := walFile.PendingWrites([]byte(strings.Repeat("X", wal.MB)))
assert.Equal(b, wal.ErrPendingSizeTooLarge, err)
walFile.PendingWrites([]byte(strings.Repeat("X", wal.MB)))
pos, err := walFile.WriteAll()
assert.Nil(b, err)
assert.Equal(b, 0, len(pos))
Expand Down
3 changes: 1 addition & 2 deletions wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,13 @@ func (wal *WAL) ClearPendingWrites() {
// PendingWrites add data to wal.pendingWrites and wait for batch write.
// If the data in pendingWrites exceeds the size of one segment,
// it will return a 'ErrPendingSizeTooLarge' error and clear the pendingWrites.
func (wal *WAL) PendingWrites(data []byte) error {
func (wal *WAL) PendingWrites(data []byte) {
wal.pendingWritesLock.Lock()
defer wal.pendingWritesLock.Unlock()

size := wal.maxDataWriteSize(int64(len(data)))
wal.pendingSize += size
wal.pendingWrites = append(wal.pendingWrites, data)
return nil
}

// rotateActiveSegment create a new segment file and replace the activeSegment.
Expand Down
3 changes: 1 addition & 2 deletions wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ func TestWAL_Reader(t *testing.T) {
func testWriteAllIterate(t *testing.T, wal *WAL, size, valueSize int) {
for i := 0; i < size; i++ {
val := strings.Repeat("wal", valueSize)
err := wal.PendingWrites([]byte(val))
assert.Nil(t, err)
wal.PendingWrites([]byte(val))
}
positions, err := wal.WriteAll()
assert.Nil(t, err)
Expand Down

0 comments on commit b73e88f

Please sign in to comment.