Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce tokio #7

Merged
merged 59 commits into from
Mar 28, 2024
Merged

feat: introduce tokio #7

merged 59 commits into from
Mar 28, 2024

Conversation

jdockerty
Copy link
Owner

@jdockerty jdockerty commented Mar 25, 2024

Large conversion to utilising tokio and asynchronous Rust in the project.

This is loosely based on the project-5 specification for the talent plan course, but it is very incomplete with minimal information so I've largely gone about this myself instead and put together what I think works.

Also includes a rename of the project from kvs to sqrl (squirrel), since I'm now very much off of the beaten path and making this my own.

jdockerty and others added 30 commits March 2, 2024 20:59
We cannot have multiple mutable references to the same data for both set/remove functions, this requires a change from BTreeMap to the concurrent DashMap (or crossbeam alternative) as the insert/remove functions here do not take &mut self and therefore do not force the implementation to be mutable either
The timestamps were being set incorrectly because they were always being generated from now(), which meant that the timestamp for the keydir was always later than the entry into the WAL. During comparison this made it so that the items were never compacted
This requires some extra thinking. I believe we can remove the RwLock around the structures which are already wrapped in one to avoid extra verbosity/unnecessary locking all over the place.

We need to consider how the file lock is handled across threads. Pushing to have this remotely
This was part of the name before, but it makes more sense to be the file extension
Compaction was broken because the opened file was never seeked to the offset, it was simply reading key0 every single time in the log file
By taking the positional offset to write at within the appending func, this fixes the concurrent_set function. Previously, we were writing to the same offset multiple times which caused get() to return the incorrect data.

NOTE: There is still a requirement to fix a memory allocation problem.
The program crashes when `cargo test` is ran altogether.
Prior to this, the bufwriter wasn't actually doing anything because flush was called after every single write, which meant that the syscall was also done. Now, the writes go into the buffer first and are then flushed at the end of the iteration
I'm removing these because it has already been done in the Rust book so I'm not wanting to rehash over it again. I'll utilise the rayon threadpool for speed and move on to the next task
Build the keydir from log files on disk. Prior to this we were
serializing the entire keydir on `Drop` which was a major bottleneck.
Instead we can rebuild the directory by reading from log files.

If we're serializing and loading an entire key directory on disk
then the WAL doesn't entirely serve a purpose since it is unused,
we simply have a k-v store already on disk which we continually
(de)serialize every single time we need too. With this new WIP
implementation, the idea is that we should be able to crash in the
middle of operations and then rebuild the index from log files that
were persisted.
Enables ease of setting logging level for tests and server usage
Prior to this, we were inserting every single element into the keydir
from scratch which meant that every item in every log file was placed
into the index, we don't need to do this.

Instead, we should only modify the entry if it exists and the timestamp
of the log entry is greater than the one we already have, i.e. it is
more up to date.
@jdockerty jdockerty mentioned this pull request Mar 28, 2024
@jdockerty jdockerty merged commit f77c8ee into main Mar 28, 2024
1 check passed
@jdockerty jdockerty deleted the feat/async-tokio branch March 30, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant