TODO: rename entry to record
Add benchmarks
Each table is a file. Each row in a file is an entry.
- To delete a record we write over the old data with a tombstone.
- To update a record we insert new data as the old record, and delete the old record.
- To clean up tombstones we make a sweep every now and then
- Define a tombstone
- Q: Do we need to lock the file before writing?
- Q: What happens when we write to a "memmap" file that has changed externally
- Q: How do we delete a record without removing data: A: A toombstone according to ACouncilOfOne
struct Table {
inner: File,
}
impl Table {
fn find_row(&self, key: &[u8]) -> &[u8] {
}
fn delete(&mut self, index: ?) {
// replace data in buffer with tombstone data
}
fn update(&mut self, data: &[u8], old_index: ?) {
self.delete(old_index);
self.insert(data);
}
fn insert(&mut self, data: &[u8]) {
// Will always append
}
}
struct Tombstone;
impl Tombstone {
fn new(size: usize) -> Vec<u8> {
vec![0; size]
}
}- Append data
- Append data
Look something up:
- Memmap the file
- Find first character in keyword using
netlib::memchr::memchr - Split the buffer on the position
- try to match the first set of bytes in the new chunk, with keyword[1..]
- Find the
\nto the left and right of the first byte position
- Find the row
- Replace it with the updated row
- Find the row
- Replace the row with a tombstone
- Append new data
- Locate data to delete
- Replace data with tombstone
- Locate data to delete
- Replace data with tombstone