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

Log file of the key-value pairs. More...

#include <stdio.h>
Include dependency graph for value_log.h:

Go to the source code of this file.

Data Structures

struct  ValueLog
 Value Log of the Database. More...
 

Functions

struct ValueLogValueLog_new (const char *path, size_t head, size_t tail)
 Creates a new ValueLog or loads an existing one from disk.
 
int ValueLog_append (struct ValueLog *log, size_t *pos, const char *key, size_t key_len, const char *value, size_t value_len)
 Appends a new key-value pair to the ValueLog.
 
int ValueLog_get (const struct ValueLog *log, char **value, size_t *value_len, size_t value_loc)
 Fetches a value from the ValueLog at a given position.
 
int ValueLog_sync (const struct ValueLog *log)
 Syncs the ValueLog to the disk.
 
void ValueLog_free (struct ValueLog *log)
 Frees the ValueLog.
 

Detailed Description

Log file of the key-value pairs.

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

Function Documentation

◆ ValueLog_append()

int ValueLog_append ( struct ValueLog * log,
size_t * pos,
const char * key,
size_t key_len,
const char * value,
size_t value_len )

Appends a new key-value pair to the ValueLog.

In the event that the write was unsuccessful, the ValueLog won't shift the head forward. Therefore, writes can be retried without the risk of polluting the ValueLog or corrupting past entries.

Parameters
logThe ValueLog to write to.
posA pointer that is assigned to the location on the where the key-value pair was written to.
keyThe key being written.
key_lenThe length of the key.
valueThe value that is being written.
value_lenThe length of the value.
Returns
This function returns 0 if the entry was written successfully and -1 if there was an error.

◆ ValueLog_free()

void ValueLog_free ( struct ValueLog * log)

Frees the ValueLog.

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

Parameters
logThe ValueLog to free.

◆ ValueLog_get()

int ValueLog_get ( const struct ValueLog * log,
char ** value,
size_t * value_len,
size_t value_loc )

Fetches a value from the ValueLog at a given position.

Note: The value pointer will allocate memory to hold the value that is being requested. The caller is responsible for freeing the memory.

Parameters
logThe ValueLog to read from.
valueA double-pointer for the value. This pointer will set with a newly allocated block of memory with the value that the caller can access.
value_lenA pointer that is assigned to the the length of the value pointer.
value_locThe location on the ValueLog that this value resides in.
Returns
This function returns 0 if the value was retrieved successfully and -1 if there was an error.

◆ ValueLog_new()

struct ValueLog * ValueLog_new ( const char * path,
size_t head,
size_t tail )

Creates a new ValueLog or loads an existing one from disk.

If the ValueLog file already exists, this function will only open the file without scanning it. This function doesn't check if file has been corrupted.

Note: Free this ValueLog with ValueLog_free.

Parameters
pathPath to the ValueLog. The path must be be null-terminated.
headThe head of the ValueLog. Set to 0 for a new ValueLog.
tailThe tail of the ValueLog. Set to 0 for a new ValueLog.
Returns
A pointer to a ValueLog.

◆ ValueLog_sync()

int ValueLog_sync ( const struct ValueLog * log)

Syncs the ValueLog to the disk.

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

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