WiscKey Database
Embedded LSM-Tree Key-Value Database
Loading...
Searching...
No Matches
wal.h File Reference

Write-Ahead Log for the keys and the value positions. More...

#include <stdint.h>
#include <stdio.h>
#include "memtable.h"
Include dependency graph for wal.h:

Go to the source code of this file.

Data Structures

struct  WAL
 Write-Ahead Log(WAL) of the Database. More...
 

Functions

struct WALWAL_new (char *path)
 Creates a new emtpy WAL.
 
int WAL_load_memtable (struct WAL *wal, struct MemTable *memtable)
 Replays the WAL from the start and recreates the MemTable.
 
int WAL_append (struct WAL *wal, const char *key, size_t key_len, int64_t value_loc)
 Appends a new MemTable operation to the WAL.
 
int WAL_sync (const struct WAL *wal)
 Syncs the WAl to the disk.
 
void WAL_free (struct WAL *wal)
 Frees the WAL.
 

Detailed Description

Write-Ahead Log for the keys and the value positions.

Author
Adam Comer adamb.nosp@m.come.nosp@m.r@gma.nosp@m.il.c.nosp@m.om
Date
May 15, 2020

Function Documentation

◆ WAL_append()

int WAL_append ( struct WAL * wal,
const char * key,
size_t key_len,
int64_t value_loc )

Appends a new MemTable operation to the WAL.

For sets, the value_loc should be the position in the ValueLog that the value entry was written to. For deletes, value_loc should be -1 to indicate a tombstone.

Parameters
walThe WAL to append a MemTable operation to.
keyThe key to apply an operation to.
key_lenThe length of the key.
value_locThe location in the ValueLog of the value or -1 if it is being deleted.
Returns
This function returns 0 if the operation was successfully writen to the WAL and -1 if there was an error.

◆ WAL_free()

void WAL_free ( struct WAL * wal)

Frees the WAL.

Note: This function won't delete the file or the underlying data in the WAL. This function only frees the memory allocated to a WAL.

Parameters
walThe WAL to free.

◆ WAL_load_memtable()

int WAL_load_memtable ( struct WAL * wal,
struct MemTable * memtable )

Replays the WAL from the start and recreates the MemTable.

This is the main recovery function for the WAL for when the Database restarts.

Parameters
walThe WAL to replay the log from.
memtableA empty MemTable to replay the log into.
Returns
This function returns 0 if the WAL successfully replayed and -1 if there was an error.

◆ WAL_new()

struct WAL * WAL_new ( char * path)

Creates a new emtpy WAL.

Note: If a WAL already exists at this path, the file will not be overwritten.

Parameters
pathThe path of the new WAL file.
Returns
A pointer to a new WAL.

◆ WAL_sync()

int WAL_sync ( const struct WAL * wal)

Syncs the WAl to the disk.

This function forcefully flushes the changes to the WAL to disk. Use this function sparingly as is will heavily reduce the write throughput of the WAL.

Parameters
walThe WAL to flush to disk.
Returns
This function returns 0 if the WAL successfully synced to the disk and -1 if there was an error.