WiscKey Database
Embedded LSM-Tree Key-Value Database
Loading...
Searching...
No Matches
sstable.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Adam Bishop Comer
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef WISCKEY_SSTABLE_H
18#define WISCKEY_SSTABLE_H
19
20#include <stdio.h>
21
22#include "memtable.h"
23
31
32#define SSTABLE_MIN_SIZE \
33 1024
34#define SSTABLE_KEY_NOT_FOUND (-2)
35
43{
44 char* key;
45 size_t key_len;
46 int64_t value_loc;
47};
48
57struct SSTable
58{
59 char* path;
60 unsigned long timestamp;
61 unsigned long level;
62 FILE* file;
63 uint64_t* records;
65 size_t capacity;
66 size_t size;
67
68 char* low_key;
70 size_t low_key_len;
71 char* high_key;
73 size_t high_key_len;
74};
75
84unsigned long
85SSTable_parse_timestamp(char* filename);
86
95unsigned long
96SSTable_parse_level(char* filename);
97
106struct SSTable*
107SSTable_new(char* path);
108
122struct SSTable*
123SSTable_new_from_memtable(char* path, struct MemTable* memtable);
124
138int64_t
139SSTable_get_value_loc(struct SSTable* table, char* key, size_t key_len);
140
152int
153SSTable_in_key_range(struct SSTable* table, char* key, size_t key_len);
154
163void
164SSTable_free(struct SSTable* table);
165
166#endif /* WISCKEY_SSTABLE_H */
In-memory table of the records that have been modified most recently.
struct SSTable * SSTable_new_from_memtable(char *path, struct MemTable *memtable)
Creates a new SSTable from a full MemTable.
Definition sstable.c:263
int SSTable_in_key_range(struct SSTable *table, char *key, size_t key_len)
Checks if the given key could be in this SSTable.
Definition sstable.c:363
unsigned long SSTable_parse_timestamp(char *filename)
Parses the creation timestamp in microseconds from a SSTable filename.
Definition sstable.c:64
unsigned long SSTable_parse_level(char *filename)
Parses the compaction level from a SSTable filename.
Definition sstable.c:81
struct SSTable * SSTable_new(char *path)
Loads a SSTable at a path.
Definition sstable.c:127
void SSTable_free(struct SSTable *table)
Frees the SSTable.
Definition sstable.c:392
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.
Definition sstable.c:317
MemTable of the Database.
Definition memtable.h:55
Single Record in a SSTable.
Definition sstable.h:43
char * key
Key of the record.
Definition sstable.h:44
size_t key_len
Length of they key.
Definition sstable.h:45
int64_t value_loc
Location of the value in the ValueLog.
Definition sstable.h:46
On-disk String-Sorted Table(SSTable) of the keys.
Definition sstable.h:58
size_t high_key_len
Length of the highest key.
Definition sstable.h:73
size_t size
Size of the growable in-memory index.
Definition sstable.h:66
FILE * file
File that the keys reside on.
Definition sstable.h:62
unsigned long level
Compaction level.
Definition sstable.h:61
unsigned long timestamp
Creation timestamp in microseconds.
Definition sstable.h:60
size_t capacity
Capacity of the growable in-memory index.
Definition sstable.h:65
char * path
Path of the SSTable on-disk.
Definition sstable.h:59
size_t low_key_len
Length of the lowest key.
Definition sstable.h:70
uint64_t * records
Definition sstable.h:63
char * high_key
Definition sstable.h:71
char * low_key
Definition sstable.h:68