Skip to content

ljmsc/wal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2bda851 · Mar 20, 2025

History

38 Commits
Jan 25, 2023
Jan 25, 2023
Jun 12, 2021
Oct 9, 2019
Feb 15, 2021
Feb 7, 2021
Feb 7, 2021
Oct 24, 2021
Feb 15, 2021
Jun 9, 2021
Mar 20, 2025
Mar 20, 2025
Oct 10, 2021
Feb 7, 2021
Feb 10, 2021
Feb 10, 2021
Feb 10, 2021
Feb 10, 2021
Oct 24, 2021
Jun 12, 2021
Oct 24, 2021
Feb 7, 2021
Oct 24, 2021
Oct 24, 2021
Oct 24, 2021

Repository files navigation

WAL (Write ahead log)

Go Report Card GoDoc

wal is a write ahead log written in go.

Installation

The code was tested with go version 1.15. Older versions can also work but have not been tested.

go get -u github.com/ljmsc/wal

Currently, only unix systems are supported.

Usage

Note: since version 0.7.0 the wal is no longer safe for concurrent write. It is up to the developer to protect the wal. e.g. Mutex, Channels. Since this kind of functionality is not always needed I removed it for performance's sake.

basic

package main

import (
	"fmt"

	"github.com/ljmsc/wal"
)

type entry []byte

func (t *entry) Unmarshal(_data []byte) error {
	*t = _data
	return nil
}

func main() {
	storage, err := wal.Open("./path/to/wal", 4, 100)
	if err != nil {
		// handle error
		panic(err)
	}
	defer storage.Close()

	data := []byte("this is my awesome test data")
	seqNum, err := storage.Write(data)
	if err != nil {
		// handle write error
		panic(err)
	}
	fmt.Printf("successful wrote entry. Sequence Number: %d\n", seqNum)

	re := entry{}
	if err := storage.ReadAt(&re, seqNum); err != nil {
		// handle error
		panic(err)
	}

	fmt.Printf("successful read entry from log. value: %s \n", re)
}

License

The project (and all code) is licensed under the Mozilla Public License Version 2.0.