Skip to content
forked from rosedblabs/wal

Write Ahead Log for LSM or bitcask storage(or any append-only write).

License

Notifications You must be signed in to change notification settings

ankur-anand/wal

This branch is 2 commits ahead of rosedblabs/wal:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c1e388f · Feb 20, 2025
Jun 21, 2023
Jul 4, 2024
Jul 4, 2024
May 19, 2024
Jul 6, 2024
May 3, 2023
Jan 12, 2025
May 19, 2024
May 19, 2024
Jan 26, 2025
Feb 20, 2025
May 19, 2024
Jan 26, 2025
Jan 26, 2025

Repository files navigation

wal

Write Ahead Log for LSM or bitcask storage.

Key Features

  • Disk based, support large data volume
  • Append only write, high performance
  • Fast read, one disk seek to retrieve any value
  • Support batch write, all data in a batch will be written in a single disk seek
  • Iterate all data in wal with NewReader function
  • Extremely fast read
  • Support concurrent write and read, all functions are thread safe

Design Overview

wal-logo.png

Format

Format of a single segment file:

       +-----+-------------+--+----+----------+------+-- ... ----+
 File  | r0  |      r1     |P | r2 |    r3    |  r4  |           |
       +-----+-------------+--+----+----------+------+-- ... ----+
       |<---- BlockSize ----->|<---- BlockSize ----->|

  rn = variable size records
  P = Padding
  BlockSize = 32KB

Format of a single record:

+----------+-------------+-----------+--- ... ---+
| CRC (4B) | Length (2B) | Type (1B) |  Payload  |
+----------+-------------+-----------+--- ... ---+

CRC = 32-bit hash computed over the payload using CRC
Length = Length of the payload data
Type = Type of record
       (FullType, FirstType, MiddleType, LastType)
       The type is used to group a bunch of records together to represent
       blocks that are larger than BlockSize
Payload = Byte stream as long as specified by the payload size

Getting Started

func main() {
	wal, _ := wal.Open(wal.DefaultOptions)
	// write some data
	chunkPosition, _ := wal.Write([]byte("some data 1"))
	// read by the position
	val, _ := wal.Read(chunkPosition)
	fmt.Println(string(val))

	wal.Write([]byte("some data 2"))
	wal.Write([]byte("some data 3"))

	// iterate all data in wal
	reader := wal.NewReader()
	for {
		val, pos, err := reader.Next()
		if err == io.EOF {
			break
		}
		fmt.Println(string(val))
		fmt.Println(pos) // get position of the data for next read
	}
}

About

Write Ahead Log for LSM or bitcask storage(or any append-only write).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%