627 Commits (ee78f9b1cec84735b75282e72ec4f7043b02bd31)

Author SHA1 Message Date
Sayan Nandan a919b1c934 Add tests for flush and unflush routines 3 years ago
Sayan Nandan 454704574b Fix flush routines 3 years ago
Sayan Nandan 2393efb590 Encode model bytemark into `PARTMAP` 3 years ago
Sayan Nandan 610144f78e Add unflush routines 3 years ago
Sayan Nandan 6baa61176f Add volatility tests 3 years ago
Sayan Nandan 66b9ac27af Write storage type into PARTMAP
This commit adds a storage_type segment to the PARTMAP disk file. This
contains information about the storage type of the table.
Is it volatile? Is it persistent? 8-bits were added for future
improvements.
3 years ago
Sayan Nandan 1d403c0d1a Add flush routines 3 years ago
Sayan Nandan e89417cbc6 Fix preload generation and add preload decoding 3 years ago
Sayan Nandan 87d79650ce Add preload generation 3 years ago
Sayan Nandan bca8df5863 Add methods to create directory tree 3 years ago
Sayan Nandan 058b1ef1c6 Replace ns with ks 3 years ago
Sayan Nandan ad48e5478c Add `Integer64BufferRaw` and use it in `resp` 3 years ago
Sayan Nandan 71ab845d02 Fix zeroed impl for `Array<T, N>` 3 years ago
Sayan Nandan 48e29b6ec6 Add `Integer32Buffer` for faster encoding/decoding 3 years ago
Sayan Nandan 5790e99a98 Fix filename generator and use LUT for 32-bit ints 3 years ago
Sayan Nandan ca55694904 And `interface` for fs 3 years ago
Sayan Nandan b162756f80 Avoid unnecessary referencing
Even though the compiler will do immediate derefs, let us be explicit.
3 years ago
Sayan Nandan 03a229104d Fix alignment and auto static lifetime causing UB 3 years ago
Sayan Nandan c24e83c0a7 Encode all sizes to little endian
This is very convenient for us and we will provide advanced byte
ordering only if our users demand for it.
3 years ago
Sayan Nandan e1dfa12ba4 Add runtime panic check on 32-bit or lower 3 years ago
Sayan Nandan 5adc269e11 Add endian info and pointer-width check
When a file created by a 64-bit system is read on a 16/32 bit system,
there may be a size overflow. If so, we should do a runtime panic.
3 years ago
Sayan Nandan 74a0592fbc Simplify transmutation
Also use smaller vectors for faster tests to avoid problems with
thread stack sizes on Windows.
3 years ago
Sayan Nandan c20302ef75 Add storage module for custom encoding/decoding 3 years ago
Sayan Nandan 7c835d03b3 Add NS/KS swap headers in protocol 3 years ago
Sayan Nandan 17d1c472b6 Use proc macro for uninit array magic
The proc macro does some magic to give us a const array with the full
size without having to manually write it. Magic!
3 years ago
Sayan Nandan fd3e06beda Fix array length check assertion 3 years ago
Sayan Nandan e5b0588cca Fix UB due to use of from_const_array 3 years ago
Sayan Nandan f4379d5688 Use Array[64] for NS/KS names
We limit the sizes of keyspaces/namespaces because very long names may
cause fs errors on some file systems.
3 years ago
Sayan Nandan 8faf653d2e Fix ser/de for `Coremap<Array, Array>` 3 years ago
Sayan Nandan bd679f9b79 Document `Array` and `IArray` 3 years ago
Sayan Nandan b997afe89a Fix push function in `Array` 3 years ago
Sayan Nandan 4a27f83e6b Impl `Send` and `Sync` for `Array` 3 years ago
Sayan Nandan 0067b7d1b7 Implement `Array` type
This allows us to have fixed size arrays right on the stack
3 years ago
Sayan Nandan 5ff045bd93 Impl deserialize for `IArray` 3 years ago
Sayan Nandan e25d13afff Add BP optimizations 3 years ago
Sayan Nandan 036b507de8 Impl Serialize for IArray 3 years ago
Sayan Nandan 4fe7aa7050 Add manip methods to `IArray` 3 years ago
Sayan Nandan 6c00ffae3b Add methods to add items to `IArray` 3 years ago
Sayan Nandan 3739aa54fd Add basic `IArray` impl 3 years ago
Sayan Nandan e3d749ac20 Add methods to drop keyspaces and tables 3 years ago
Sayan Nandan 845ef82060 Use static slices for responses 3 years ago
Sayan Nandan 26a22c3102 Add dtor tests for Lazy 3 years ago
Sayan Nandan a7e11cc281 Add methods to create ns, ks and tables 3 years ago
Sayan Nandan bbcbe0756b Add basic methods to memstore 3 years ago
Sayan Nandan 7ea890765d Correct kvengine defs and add custom `Lazy` type 3 years ago
Sayan Nandan 74126ec7cb Add variable width characters and failure test
This is just for sanity
3 years ago
Sayan Nandan 013be0058b Add emoji tests 3 years ago
Sayan Nandan 8749cfa134 Add memstore 3 years ago
Sayan Nandan c953b88695 Add test with bincode 3 years ago
Sayan Nandan b1383bf8c9 Add encoding evaluation in `KVEngine` 3 years ago
Sayan Nandan a276091726 Account for perl errors 3 years ago
Sayan Nandan 5f75df7109 Add some optimizations for unicode checks 3 years ago
Sayan Nandan ead3f62ded Add failure cases for unicode 3 years ago
Sayan Nandan bdfaf6ec4d Ensure that perl doesn't error 3 years ago
Sayan Nandan 5e4cd5be4b Use deterministic finite automaton for validation
A dual stream approach provides even more speed improvements
3 years ago
Sayan Nandan 8cfab3f7d3 Add convenience macros 3 years ago
Sayan Nandan efec980fa6 Add basic `BufferBlockReader` definition 3 years ago
Sayan Nandan bdc4b3483f Add basic `KVEngine` definition 3 years ago
Sayan 552d454940
Enable TLS port to be configured via CLI args (#186)
* Enable TLS port to be configured via CLI

* Add changelog entry
3 years ago
Sayan Nandan 141e39eee1 Use env var to determine TLS cert location 3 years ago
Sayan d43e6f41da
Use `QuickLock` instead of mutex (#185)
* Use our own lock instead of parking_lot::Mutex

* Account for spurious failures in cmpxchg weak

* Ignore send error because parent may have panicked

The parent thread may have already panicked, dropping the rx.
3 years ago
Sayan Nandan 3a363d18cb Simplify artwork [skip ci] 3 years ago
Sayan bae2b8354c
Release v0.6.3 (#184)
* Bump up version to 0.6.3

* Update changelog entry
3 years ago
Sayan 2d7b9d7667
Add automated tests for TLS (#183)
* Auto start with TLS

* Add automated tests for SSL

* Add cert generation script

* Use script to generate SSL cert
3 years ago
Sayan 864c6d461f
Enable maximum connections to be configured manually (#182)
* Enable maximum connections to be configured

* Add arbiter for handling server startup

* Add handling of maxcon for command-line args

* Add changelog entry
3 years ago
Sayan Nandan 79f657b462 Add more LLVM specific optimizations
Just to reduce LLVM bloat
3 years ago
Sayan e30d51a599
Release v0.6.2 (#180)
* Bump up version and add changelog entry

* Use separate cache object for release workflows
3 years ago
Sayan Nandan 0f06f7b26f Add some LLVM specific optims for O1 builds 3 years ago
Sayan d53a0cb505
Fix handling of SIGTERM on *nix (#178)
* Fix handling of SIGTERM on *nix

This is just for future extensibility

* Fix error codes

I have been silly enough to break error codes
3 years ago
Sayan 66e5d41302
Simplify overall locks (#176)
* Remove the need for TableLockStateGuard

The htable impl uses locks under the hood making external locks
redundant.

* Use atomics instead of rwlock for poisoned state

* Simplify snapshot locking
3 years ago
Sayan Nandan 2a2addfa6d Upgrade deps and add changelog entries 3 years ago
Sayan Nandan 0f1264d312 Decompose linearity tests and utils into modules
Also fixed license headers
3 years ago
Sayan Nandan a87478dcba Optimize dependencies 3 years ago
Sayan Nandan 76acde2f4f Fix missing action argument in setkeys macro 3 years ago
Sayan Nandan 26775924ac Add tests for pop 3 years ago
Sayan Nandan 57c957d4e7 Add `pop` action 3 years ago
Sayan cdae667cb0
Fix pid file creation (#170)
* Remove the pid file if runtime errors occur

* Clean up error handling and fix pid file creation

The pid file was being created before evaluating the args, now it may
happen that incorrect args or --help was passed: in that event, the pid
file remains created. This was also fixed, besides some refactoring.
3 years ago
Sayan ca9e482f47
Deter other processes from using the same data dir (#169)
* Deter other processes from using the same data dir

For more information, see #167

* Don't lock `pid_file`

Windows has mandatory locking so second instance won't be able to read
the PID of the other process. We'll just keep the file descriptor/handle
open
3 years ago
Sayan 7349e461e6
Try to auto recover the save operation on termination (#166)
This is very useful because it removes the need for user intervention in
the event save on termination fails. Say the save operation fails due to
'some bad daemon' changing the directory's perms. Now skyd reports this
error while trying to save upon termination. Our sysadmin now fixes the
perms issue. The previous design would force the sysadmin to _somehow_
foreground skyd and hit enter. That is silly. The new design just
attempts to do a save operation every 10 seconds. So in case the issue
is fixed, the save operation will recover on its own.

Why not exponential backoff?
That's because the issue can be fixed some long time later and we may
have reached a large backoff value so the save that could have succeeded
would have to wait for a long duration before it can do anything
meaningful.

This also fixes a bug that caused BGSAVE errors to be reported as info
class log entries.
3 years ago
Sayan 8df9901740
Upgrade deps and actiondoc (#165) 3 years ago
Sayan e553c5172b
Release v0.6.1 (#164)
* Explicitly fsync and relax CPU on snap busy-loop

This commit also switches to using global `VERSION` and `URL` statics
than defining it per-crate.

* Add changelog entry and bump up version

* Optimize `dbtest` macro and rm redundant allocs

* Upgrade deps
3 years ago
Sayan Nandan 0c33395a09 Add some general optimizations 3 years ago
Sayan 1bde8b197d
Fix file-locking on solaris (#162) 3 years ago
Sayan Nandan 72d871ed3f Upgrade deps 3 years ago
Sayan Nandan 1bec90baac Optimize `sset` and `sdel` implementations 3 years ago
Sayan Nandan 2eedb041bb Make `gen_constants_and_matches!` macro logical
This commit imporves the overall 'look' of the macro and makes it appear
more logical
3 years ago
Sayan Nandan 58830edc80 Use iterators for actions 3 years ago
Sayan Nandan a839137643 Move actions into an `actions` module
These are actions and shouldn't be called the `kvengine`.
3 years ago
Sayan Nandan f8ea4c33de ucase for ASCII only
This is a silly optimization but can be significantly faster for larger
action names. Also, since there are (should be) no UTF-8 characters in
the first argument, this is absolutely fine and sensible.
3 years ago
Sayan Nandan a68c42f720 Document missing instances of `unsafe` 3 years ago
Sayan 952c5caa86
Poison the database by default if snapshotting fails (#160)
* Stop accepting writes if snapshotting fails

This is an important consideration: if BGSAVE fails and poisons the
database, snapshotting can and should too. But this is debatable in some
parts. For example, users may configure snapshots to be on a network
file system (symlinked maybe) and this can fail.
Now in some cases, this failure 'may be acceptable'. This commit adds a
way to customize this behavior through the `failsafe` key in the
snapshots section of the cfg file and through the --stop-write-on-fail
option passed to `skyd` on startup. However, BGSAVE remains unchanged:
it will always poison the database if it fails. If the user doesn't want
this, they can simply disable BGSAVE.

* Add changelog
3 years ago
Sayan Nandan ac336ff821 Add missing changes in changelog
Use `pat` token instead of `path` in query engine
3 years ago
Sayan Nandan eea0f86c97 Upgrade skytable client driver version 3 years ago
Sayan 6c9a36d397
Improve compat to use storage formats for upgrades (#158) 3 years ago
Sayan Nandan 260b336bf6 Add tests for races and synchronized unlocks 3 years ago
Sayan a1320da52b
Migrate to using `Coremap` (#156)
* Upgrade all interfaces to use new HTable

* Document `HTable`
3 years ago
Sayan Nandan 966c2594bf Fix `lskeys` tests 3 years ago
Sayan Nandan b77b783064 Add tests for lskeys 3 years ago
Sayan Nandan ea7891fba7 Implement lskeys 3 years ago
Sayan Nandan 449da56308 Upgrade all interfaces to use new in-memory table 3 years ago
Sayan Nandan 975e953426 Add compat module for upgrading old files 3 years ago
Sayan Nandan c2a20d4476 Implement serialize/deserialize for `HTable` 3 years ago
Sayan Nandan a7f5d84ef4 Bump dependencies
Also use `tokio::join` in-place of `futures::join`
3 years ago
Sayan 790558d2c7
Improve reliability, simplicity and recoverability of BGSAVE (#153)
* Create a new file on writing to flock-ed file

This fix is a very important one in two ways. Say we have an user A.
They go ahead and launch skyd. skyd creates a data.bin file. Now A just
deletes the data.bin file for fun. Funny enough, this never causes flock
to error!
Why? Well because the descriptor/handle is still valid and was just
unlinked from the current directory. But this might seem silly since
the user exits with a 'successfully saved notice' only to find that the
file never existed and all of their data was lost. That's bad.
There's a hidden problem in our current approach too, apart from this.
Our writing process begins by truncating the old file and then writing
to it by placing the cursor at 0. Nice, but what if this operation just
crashes. So we lost the current data AND the old data. Not good.

This commit does a better thing: it creates a new temporary file, locks
it before writing and then flushes the current data to the temporary
file. Once that succeeds, it replaces the old data.bin file with the
newly created file.

This solves both the problems mentioned here for us:
1. No more of the silly error
2. If BGSAVE crashes in between, we can be sure that at least the last
data.bin file is in proper shape and not half truncated or so.

This commit further moves the background services into their
own module(s) for easy management.

* Fix CI scripts

Fixes:
1. Our custom runner (drone/.ci.yml) was modified to kill the skyd
process once done since this pipeline is not ephemeral.
2. GHA for some reason ignores any error in the test step and proceeds
to kill the skyd process without erroring. Since GHA runners are
ephemeral, we don't need to do this manually.
3 years ago
Sayan Nandan 85616544ef Ensure that the entire file is locked
Although this is barely documented, setting the nNumberOfBytesToLockLow
and nNumberOfBytesToLockHigh to MAXDWORD apparently locks the entire
file
3 years ago
Sayan Nandan 42ad5680ff Fix missing imports on Windows
I'm not on a Windows machine, so I don't get these errors reported!
3 years ago
Sayan Nandan 03e241902f Ensure that duplicated handle has same permissions
This is particularly relevant for Windows
3 years ago
Sayan Nandan ba53e5160b Use unlocks to ensure that file is readable 3 years ago
Sayan Nandan 76d184663a Add test for BGSAVE 3 years ago
Sayan Nandan d7cd1bfb70 Use different byte count for test
This test simply makes sure that the 0s written while truncating don't
reappear (they should never do)
3 years ago
Sayan Nandan 93ef949bac Manually unlock file after complete termination
The cloned flock might attempt to call the unlock but it is a cloned
descriptor!
3 years ago
Sayan Nandan 893cf1d741 Fix `FileLock::write` impl and make snaps blocking
This commit implements a tokio blocking task for mksnap and also fixes
FileLock's write method and adds a test for the same
3 years ago
Sayan Nandan b5865e500b Use Terminator for termination of all bg services
What we did in the old implementation was pure over-engineering.
We relied on CoreDB's `Drop` impl to terminate the background services.
Now this is absolutely unreliable due to the nature of async functions.
We also relied on the bgsave scheduler to release the lock upon exit
which is also unreliable because we left the service to the mercy of the
runtime. We spawned the task and didn't hold as much as a `JoinHandle`
to it. That's bad because the runtime can just abort these tasks which
may result in the lock never being released. Even though it is designed
to release the lock on Drop, the destructor may however not be called at
all.

This commit fixes all those issues by simplifying the entire impl to
use Terminator. Now the background save and snapshot services run
independently, in their own tasks. Whenever the user passes a SIGINT,
we tell everyone to quit. The listeners understand that this is the
last query they'll process and the background save tasks exit almost
immediately. But what if some data was modified by this last query...?

No worries, that is completely handled by main(). The lock that BGSAVE
leaves is immediately (almost) returned to main and main will attempt
to flush the data almost immediately. That's how we maintain reliability
3 years ago
Sayan Nandan 78e9441564 Spawn blocking I/O tasks on a dedicated thread 3 years ago
Sayan Nandan 7d1b44a57f The snapshot service had similar bugs that were
fixed
3 years ago
Sayan Nandan 5a7f17db14 Fix strong count calculation logic
See the added comment for more context
3 years ago
Sayan Nandan 5d4650712f Fix BGSAVE running right on service start
This fixes another flaw with the previous implementation: running BGSAVE
right when the service is started which causes unnecessary disk I/O
3 years ago
Sayan Nandan 77f4b6e7be Make BGSAVE optimistic and fix BGSAVE bugs
This commit ensures that BGSAVE is optimistic in doing what it is doing:
If BGSAVE fails once, it will immediately poison the table. Now let's
say that some amazing sysadmin managed to SSH into the server and was
able to fix the storage issue; BGSAVE would be able to succeed.
The current implementation was flawed: firstly it prevented that and
secondly even if it succeeded in running BGSAVE, the server would refuse
to accept writes. This commit fixes this behavior.
3 years ago
Sayan Nandan a61ab02cd9
Fix disk storage on termination (#151)
See #150 for more information
3 years ago
Sayan Nandan 3616793554 Update versioning and support information [skip ci] 3 years ago
Sayan Nandan 6b47279b1b Fix CI script and improve terminal artwork 3 years ago
Sayan Nandan f55fa85174 Upgrade server to use client driver's `RespCode`s 3 years ago
Sayan Nandan 57d2883218 Fix SSET not skipping action name 3 years ago
Sayan Nandan d9bd911768 Fix segfault due to not skipping the action name
All the strong actions operate on the raw vector of args and hence need
to skip the action name (which is the first argument just like shell
commands)
3 years ago
Sayan Nandan 75f46c9235 Fix DBSIZE writing header when already written 3 years ago
Sayan Nandan ba0a67a179 Fix queries returning full responses
They should return groups instead
3 years ago
Sayan Nandan 229a424f45 Fix mset and uset tests 3 years ago
Sayan Nandan 80fc9e5e9c Upgrade all tests to use the driver 3 years ago
Sayan Nandan e08cffd187 Fix MGET returning flat array
MGET returns a 'mixed outcome' with respcodes and strings
3 years ago
Sayan Nandan db68453eab MGET returns a flat array 3 years ago
Sayan Nandan 35755f8033 Fix ret of parse error instead of `NotEnough`
If we couldn't fetch the tsymbol, it means that the stream hasn't
buffered enough data.

Also tests were added to account for the same
3 years ago
Sayan Nandan 8bdf5f32de Use write_all to ensure all bytes are written 3 years ago
Sayan Nandan b523103e4f Remove dbg messages and fix queryengine lcase eval 3 years ago
Sayan Nandan 124caec193 Disable dead_code lint for 'prospective' modules 3 years ago
Sayan Nandan a730511a2f Remove redundant methods 3 years ago
Sayan Nandan 7b11047bfe Make sure result is used 3 years ago
Sayan Nandan 78067d15eb Upgrade all interfaces to use the Skyhash protocol 3 years ago
Sayan Nandan d6a3cc2acb Document the Skyhash deserializer 3 years ago
Sayan Nandan 6d1d5f7877 Fix metaframe parsing and add more tests 3 years ago
Sayan Nandan fc5c943693 Simplify ASCII digit conversion
checked_sub is too sophisticated to use for this; just check if it is an
ASCII digit by using the built-in method
3 years ago
Sayan Nandan 4eabd3fc26 Ensure there are bytes before doing anything 3 years ago
Sayan Nandan 00dbeceb1b Remove the size part of the metaline completely
The size part of the metaline is absolutely redundant as we're doing
double the work while reading the size and then the real thing.
Since sizes won't have escape codes, we can freely read upto the LF
3 years ago
Sayan Nandan a39d9bf4cf Implement parser for new protocol 3 years ago
Sayan Nandan 14bfe1fcd1 Add support for parsing arrays and nested arrays 3 years ago
Sayan Nandan 53cad270fc Add parsing for u64 and also check overflows 3 years ago
Sayan Nandan ad0fbffe32 Add data types and add parsing for strings 3 years ago
Sayan Nandan 60d7a1c173 Optimize will_cursor_give_char check 3 years ago
Sayan Nandan 3a1abda2cb Return NotEnough if nothing at current cursor
If Parser::will_cursor_give_char is set to not error if a char matches
or the next line is empty, return Ok(bool). If this_if_nothing_ahead is
set to false, then return a NotEnough error if no more chars are
available.

The newly added test explains why
3 years ago
Sayan Nandan 6d29e519c9 Fix read_sizeline returning wrong error
Also added more tests
3 years ago
Sayan Nandan daaf6968ba Verify if byte is LF before moving cursor 3 years ago
Sayan Nandan d91e696e24 Add more tests 3 years ago
Sayan Nandan 0bdbd81f92 Add a header magic
We add a header magic '0x0D' or the CR byte. This acts as a boundary
between multiple queries on the same connection
3 years ago
Sayan Nandan 88b4eb88a1 Make some idents public 3 years ago
Sayan Nandan 6dbe0fcfaa Add parsing for complete query 3 years ago
Sayan Nandan e07614d857 Rename function to reflect names in rest of mod 3 years ago
Sayan Nandan d22fec8036 Implement complete actiongroup parsing 3 years ago
Sayan Nandan 65f0e445a4 Pre-allocate capacity for the element 3 years ago
Sayan Nandan 2efe2ab213 Implement parsing of datagroup elements 3 years ago
Sayan Nandan 14e0ab2462 Rename functions appropriately 3 years ago
Sayan Nandan 773c82ac83 Add actiongroup size parsing 3 years ago
Sayan Nandan 2fed0e876b Implement metaframe parsing 3 years ago
Sayan Nandan 559af81ee9 Start impl of new parser and add sizeline parsing 3 years ago
Sayan Nandan 4265820fbd Don't raise error if there is more data 3 years ago
Sayan Nandan c9b2abfc96 Fix test 3 years ago
Sayan Nandan abb1b9bf33 Only discard part of buffer that was parsed 3 years ago
Sayan Nandan 74893c275e
Abstract HashMap into HTable (#146)
It is likely that we'll change the HashMap implementation in the future,
hence its best to hide away the HashMap to make sure we can easily
replace it.
3 years ago
Sayan Nandan d18631680c Bump up version and add changelog entry 3 years ago
Sayan Nandan 50273f324a Upgrade dependencies 3 years ago
Sayan Nandan f3e7a73b00 Fix trying to read dir instead of snapshot file
Also, migration support for the old snapshot directory was added
3 years ago
Sayan Nandan 90ee7baa8a Fix snapshot directory parsing logic
The previous logic was heavily flawed; it only had to check if the path
was a dir and isn't the remote snapshot directory.

Similarly, the file name parsing should only kick in if the item is a
file
3 years ago
Sayan Nandan 772e7b0b27 Fix restoring from snapshot and data file 3 years ago
Sayan Nandan 0b3dd9c129 Add backwards compat for old snapshot dirs 3 years ago
Sayan Nandan f013a90179 Change snapshot directory to data/snapshots 3 years ago
Sayan Nandan f60b3098da Change the data file path to data/data.bin
As a consequence, other methods were also upgraded
3 years ago
Sayan Nandan 3851f6d9ce
Remove redundant functions from mod `config` (#143) 3 years ago
Sayan Nandan ce466ebc22 Reacquire lock when runtime exits
This commit adds changes so that the main process almost immediately
acquires a lock on the data file when runtime is dropped. This is just
an added precaution to try and ensure that no other process does
something silly with the data file.

The descriptor is cloned for this using `FileLock::try_clone`
3 years ago
Sayan Nandan 74ce75d919 There is no need for block_on_process_exit
8e46e62 added a block_on_process_exit function that kept on sending
`notify_one()`s in a loop until the services terminated. This was
pointless as the `Drop` impl would do it for us anyways.
(What was I thinking?)

So, in main(), we're spawning an async task that lets the DB run as long
as we don't pass a ctrl_c (or some bad panic occurs). Once the ctrl_c
is received, we start terminating all workers. `block_on` returns DB
which should be the only one holding an atomic reference to the shared
field. We assert this right after dropping `runtime`.

Finally, the ECONNRESET suppression match was fixed to remove an
unreachable branch by adding conditional compilation
3 years ago
Sayan Nandan 8e46e62d3f Wait for all workers to drop and release flock(s)
This commit ensures that the workers exit before attempting a flush_db
operation. Only after block_on_process_exit finishes we return `db`.
Now we run a simple flush_db operation knowing that the lock has been
released.
To block on process termination, we introduce a new function
block_on_process_exit that does the same thing as CoreDB's Drop
implementation.
3 years ago
Sayan Nandan 7349f5261d Manually build rt and then block on dbnet::run 3 years ago
Sayan Nandan d9af302417 Don't use additional scope 3 years ago
Sayan Nandan fb503e2981 Fix trying to unlock `file` instead of `file2`
Silly me, `file` has already been unlocked
3 years ago
Sayan Nandan 1180de3b71 Ret FileLock from BGSave to unlock before flush_db 3 years ago
Sayan Nandan 5df31287da Use dedicated blocking osthread for unlocking file
This commit ensures that the file unlock operation is completed as soon
as bgsave returns and not in the future
3 years ago
Sayan Nandan 39ab1e7683 Log error that causes `flush_db` to fail 3 years ago
Sayan Nandan 07dd884f3c Upgrade deps and remove unused regex in cli
Closes #128, closes #129 and closes #132
3 years ago
Sayan Nandan 4354bfc0f9 Fix ECONNRESET errors on Windows
As discussed in #110, this commit suppresses ECONNRESET on Windows.
3 years ago
Sayan Nandan ea1381269b Don't use filename `con`
Windows is the most ingenious OS in the world where filenames can
conflict with shell commands. That's right, con is an I/O device on
Windows and cannot be used for a filename! This is why we were having
checkout errors on Windows!

Vive la POSIX!
3 years ago
Sayan Nandan e918dabf26 Use generic Connection replacing SSL/TCP variants
We have introduced a trait `BufferedSocketStream` that is a 'dummy'
trait and is implemented for both `SslStream<TcpStream>` and
`TcpStream`. So, the generic `Connection` object accepts any type that
implements the `BufferedSocketStream` trait (and hence should also
implement `AsyncWrite`)
3 years ago
Sayan Nandan 4ba5418120 Document `dbnet::con` 3 years ago
Sayan Nandan ef36351428 Refactor dbnet and protocol into logical modules 3 years ago
Sayan Nandan eb71335a62 Upgrade all functions to use generic connections
This commit does a LOT! It migrates the `queryengine::execute_simple`,
`CoreDB::execute_query` and the kvengine functions to use generic
connections.

The object dbnet::Con was removed because it isn't needed anymore.
The listeners were also upgraded to use the generic connection handler
3 years ago
Sayan Nandan c399ae1f1c Implement a generic con handler and rename traits
The trait `Con` and `ConOps` were renamed to `ProtocolConnectionExt`
and `ProtocolConnection`.

This naming scheme clearly explains that the Ext version 'augments' the
non-Ext impl. This is the very case here: ProtocolConnection provides
the basic funtions needed for interfacing with net I/O while the Ext
trait enables high-level interaction with the protocol and ultimately
queries.

A generic `ConnectionHandler` object was added that will replace the
SSL and non-SSL handler objects, again reducing redundancy.

Dummy execute functions were added to CoreDB and queryengine.
3 years ago
Sayan Nandan ba478b9f5a Add a generic implementation for a connection
This commit defines two traits: `Con` and `ConOps`. Implementors of
`ConOps` get a free implementation for `Con`. `Con` is the ultimate
object that can be used in place of the current SSL/non-SSL connection
objects. If you look at the implementations of the current connection
objects, they have a lot of repetition as they do almost the same thing
except for the fact that they have a different underlying stream.
This is exactly what we're trying to eliminate. We will also define a
generic connection handler object to reduce redundancy.
3 years ago
Sayan Nandan 9e11b8bcd0 Add note on how `dbtest` tests work 3 years ago
Sayan Nandan 2cbd35cbb5 Enable flocks on startup and shutdown
Several changes were made to accomodate for this, including the addition
of the write_to_disk function that should be used by fns which don't
have a FileLock to pass for flushing data to the disk.

BGSAVE now takes ownership of a FileLock object which it uses for
running BGSAVE.
3 years ago
Sayan Nandan fd23218809 Add test for Windows for duplicate unlock attempts 3 years ago
Sayan Nandan 02e57f5da0 Document `flock`s 3 years ago
Sayan Nandan 982b8e9a25 Use the unlocked field across all platforms
Initially added in 7777d1ee, this commit enables it for all platforms to
avoid an extra syscall
3 years ago
Sayan Nandan 7777d1ee96 Attempt to fix flocks on windows with unlock field
It seems that on Windows unlocking errors if the file has already been
unlocked. To fix this, we've added a platform-specific field to see if
the FileLock object has already been used to unlock the file.
This is the unlock field. In the Drop impl for Windows, we check the
unlocked flag to determine if we need to unlock the file.
3 years ago
Sayan Nandan 79a7cfd2c2 windows::um::fileapi::UnlockFile is an unsafe call 3 years ago