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

Non-volatile storage of the keys in the Database. More...

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

Go to the source code of this file.

Data Structures

struct  SSTableRecord
 Single Record in a SSTable. More...
 
struct  SSTable
 On-disk String-Sorted Table(SSTable) of the keys. More...
 

Macros

#define SSTABLE_MIN_SIZE    1024
 Minimum number of records in a SSTable index array.
 
#define SSTABLE_KEY_NOT_FOUND   (-2)
 Return value if the value is not found.
 

Functions

unsigned long SSTable_parse_timestamp (char *filename)
 Parses the creation timestamp in microseconds from a SSTable filename.
 
unsigned long SSTable_parse_level (char *filename)
 Parses the compaction level from a SSTable filename.
 
struct SSTableSSTable_new (char *path)
 Loads a SSTable at a path.
 
struct SSTableSSTable_new_from_memtable (char *path, struct MemTable *memtable)
 Creates a new SSTable from a full MemTable.
 
int64_t SSTable_get_value_loc (struct SSTable *table, char *key, size_t key_len)
 Gets the location of a value on the ValueLog from a key.
 
int SSTable_in_key_range (struct SSTable *table, char *key, size_t key_len)
 Checks if the given key could be in this SSTable.
 
void SSTable_free (struct SSTable *table)
 Frees the SSTable.
 

Detailed Description

Non-volatile storage of the keys in the Database.

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

Function Documentation

◆ SSTable_free()

void SSTable_free ( struct SSTable * table)

Frees the SSTable.

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

Parameters
tableThe SSTable to free.

◆ SSTable_get_value_loc()

int64_t SSTable_get_value_loc ( struct SSTable * table,
char * key,
size_t key_len )

Gets the location of a value on the ValueLog from a key.

This function uses the in-memory index to seek each record on disk. This function uses binary search for a runtime of O(log(n)) seeks.

Parameters
tableThe SSTable to search.
keyThe key to search with.
key_lenThe length of the key.
Returns
This function returns the position in the ValueLog if the key is found. -2 if the key is not in the SSTable. -1 if there is an error reading the record.

◆ SSTable_in_key_range()

int SSTable_in_key_range ( struct SSTable * table,
char * key,
size_t key_len )

Checks if the given key could be in this SSTable.

This function runs in constant time without any operations on disk.

Parameters
tableThe SSTable to search.
keyThe key in question.
key_lenThe length of the key.
Returns
This function returns 1 if the key is in the range and 0 if it is not.

◆ SSTable_new()

struct SSTable * SSTable_new ( char * path)

Loads a SSTable at a path.

Note: This operation scans the entire SSTable to build the index.

Parameters
pathThe Path of the SSTable on the filesystem.
Returns
A pointer to a new SSTable.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SSTable_new_from_memtable()

struct SSTable * SSTable_new_from_memtable ( char * path,
struct MemTable * memtable )

Creates a new SSTable from a full MemTable.

This function will create a new SSTable at a path. If a file already exists at this path, then the file will be overwritten.

Note: The MemTable will not be freed after creating a new SSTable. The caller is responsible for freeing the MemTable.

Parameters
pathThe path of the new SSTable.
memtableThe MemTable to create a SSTable from.
Returns
A pointer to the newly created SSTable.
Here is the call graph for this function:

◆ SSTable_parse_level()

unsigned long SSTable_parse_level ( char * filename)

Parses the compaction level from a SSTable filename.

This function expects the filename in the format of ll-ll.sstable

Parameters
filenameThe filename of the SSTable to parse.
Returns
The compaction level of the SSTable.
Here is the caller graph for this function:

◆ SSTable_parse_timestamp()

unsigned long SSTable_parse_timestamp ( char * filename)

Parses the creation timestamp in microseconds from a SSTable filename.

This function expects the filename in the format of ll-ll.sstable

Parameters
filenameThe filename of the SSTable to parse.
Returns
The timestamp of when the SSTable was created.
Here is the caller graph for this function: