Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
akiozihao committed Dec 11, 2023
2 parents cea51ec + 8de9190 commit 69cc8b9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Release 1.3.6 (2023-09-25)

## 🎄 Enhancements
* avoid resetting pool to optimize the memory usage
* no need to return err in pendingWrites
* fix benchmark error
## 🎠 Community
* Thanks to @akiozihao
* check ErrPendingSizeTooLarge first (https://github.com/rosedblabs/wal/pull/32)

# Release 1.3.5 (2023-09-19)

## 🎄 Enhancements
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ Write Ahead Log for LSM or bitcask storage, with block cache.
## Key Features
* Disk based, support large data volume
* Append only write, high performance
* Fast read, one disk seek to retrieve any data
* Fast read, one disk seek to retrieve any value
* Support Block Cache, improve read performance
* Support batch write, all data in a batch will be written in a single disk seek
* Iterate all data in wal with NewReader
* Iterate all data in wal with `NewReader` function
* Support concurrent write and read, all functions are thread safe
* Support data compression, use Snappy and ZSTD(Coming soon)

## Design Overview

Expand Down
10 changes: 4 additions & 6 deletions benchmark/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
opts := wal.Options{
DirPath: dir,
SegmentFileExt: ".SEG",
SegmentSize: 32 * 1024 * 1024,
SegmentSize: wal.GB,
}
var err error
walFile, err = wal.Open(opts)
Expand Down Expand Up @@ -51,14 +51,12 @@ 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))
assert.Equal(b, 32, 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 69cc8b9

Please sign in to comment.