wal

package
v0.0.0-...-8ad9259 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

README

WAL: Write Ahead Log

How data travels?

  1. Application Buffer or Library Buffer: at this point data lives in application address space.
  2. Kernel Buffer: Kernel page cache where data can live for a non fixed time.
  3. Storage Device Cache:
  4. Stable Storage:

How data travels in MDB?

When data is written to the network socket it is read by the server in buffer i.e. application memory. The server already has a file stream opened(WAL file).

Installation

Example

// Start a new WAL
walObj, err = wal.Open(/path/to/wal/dir)

// Open the existing latest WAL
walObj, err = wal.Open(/path/to/wal/dir)

// Write to WAL
err := walObj.Write([]byte("some data"))

// Read opened WAL file:
rChan := db.rWalObj.Read()
for record := range rChan {
    // do something with the data here
}
  • Close the opened WAL:

db.rWalObj.Close()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWalNotFound no recovery log found. Possible reason first db run.
	ErrWalNotFound = errors.New("WAL: WAL recovery log not found")
	// ErrInvalidPath raised when passed path doesn't exists
	ErrInvalidPath = errors.New("WAL: Invalid directory")
	// ErrInvalidSeq is raised when a missing sequence is found in wal file.
	// Wal recovery should stop here.
	ErrInvalidSeq = errors.New("WAL: Invalid sequence found while recovering. Abort")
	// ErrInvalidWalData is raised while validating each record with it's hash. Wal
	// recovery should stop here.
	ErrInvalidWalData = errors.New("WAL: Invalid data found while recovering. Abort")
	ErrBadWalName     = errors.New("WAL: Bad wal name")
)

Functions

func CalculateHash

func CalculateHash(data []byte) uint32

CalculateHash returns the crc32 value for data

func Exists

func Exists(path string) bool

Exists function checks if the given path is valid

func Fsync

func Fsync(f *os.File) (err error)

Fsync full file sync to flush data on disk from temporary buffer

Types

type Record

type Record struct {
	Seq  int64
	Hash uint32
	Data []byte
}

Record stores individual db command record. Each record contains complete data about a command.

type Wal

type Wal struct {
	// contains filtered or unexported fields
}

Wal datatype

func New

func New(dirPath string) (*Wal, error)

New creates a new wal file returns the Wal object

func Open

func Open(dirPath string) (*Wal, error)

Open opens the existing latest wal file for reading and returns a Wal object

func (*Wal) Close

func (w *Wal) Close()

Close runs the cleanup tasks

func (*Wal) Read

func (w *Wal) Read() chan *Record

Read the wal data from beginning till the end

func (*Wal) Rename

func (w *Wal) Rename() (err error)

Rename the latest created WAL file

func (*Wal) Verify

func (w *Wal) Verify() error

Verify runs through the wal file and returns error if wal is corrupted

func (*Wal) Write

func (w *Wal) Write(data []byte) error

Write appends the Record to WAL

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL