Abstract database behind generic interface and implement alternative drivers #322

Merged
lx merged 64 commits from db-abstraction into main 2022-06-08 08:01:56 +00:00
Owner
  • Design interface
  • Implement Sled backend
    • Re-implement the SledCountedTree hack on Sled backend on all backends (i.e. over the abstraction)
  • Convert Garage code to use generic interface
  • Proof-read converted Garage code
  • Test everything well
  • Implement sqlite backend
  • Implement LMDB backend
  • (Implement Persy backend?)
  • (Implement other backends? (like RocksDB, ...))
  • Implement backend choice in config file and garage server module
  • Add CLI for converting between DB formats
  • Exploit the new interface to put more things in transactions
    • .updated() trigger on Garage tables

Fix #284

Bugs

  • When exporting sqlite, trees iterate empty??
  • LMDB doesn't work

Known issues for various back-ends

  • Sled:
    • Eats all my RAM and also all my disk space
    • .len() has to traverse the whole table
    • Is actually quite slow on some operations
    • And is actually pretty bad code...
  • Sqlite:
    • Requires a lock to be taken on all operations. The lock is also taken when iterating on a table with .iter(), and the lock isn't released until the iterator is dropped. This means that we must be VERY carefull to not do anything else inside a .iter() loop or else we will have a deadlock! Most such cases have been eliminated from the Garage codebase, but there might still be some that remain. If your Garage-over-Sqlite seems to hang/freeze, this is the reason.
    • (adapter uses a bunch of unsafe code)
  • Heed (LMDB):
    • Not suited for 32-bit machines as it has to map the whole DB in memory.
    • (adpater uses a tiny bit of unsafe code)

My recommendation: avoid 32-bit machines and use LMDB as much as possible.

Converting databases is actually quite easy. For example from Sled to LMDB:

cd src/db
cargo run --features cli --bin convert -- -i path/to/garage/meta/db -a sled -o path/to/garage/meta/db.lmdb -b lmdb

Then, just add this to your config.toml:

db_engine = "lmdb"
- [x] Design interface - [x] Implement Sled backend - [x] Re-implement the SledCountedTree hack ~~on Sled backend~~ on all backends (i.e. over the abstraction) - [x] Convert Garage code to use generic interface - [x] Proof-read converted Garage code - [ ] Test everything well - [x] Implement sqlite backend - [x] Implement LMDB backend - [ ] (Implement Persy backend?) - [ ] (Implement other backends? (like RocksDB, ...)) - [x] Implement backend choice in config file and garage server module - [x] Add CLI for converting between DB formats - Exploit the new interface to put more things in transactions - [x] `.updated()` trigger on Garage tables Fix #284 **Bugs** - [x] When exporting sqlite, trees iterate empty?? - [x] LMDB doesn't work **Known issues for various back-ends** - Sled: - Eats all my RAM and also all my disk space - `.len()` has to traverse the whole table - Is actually quite slow on some operations - And is actually pretty bad code... - Sqlite: - Requires a lock to be taken on all operations. The lock is also taken when iterating on a table with `.iter()`, and the lock isn't released until the iterator is dropped. This means that we must be VERY carefull to not do anything else inside a `.iter()` loop or else we will have a deadlock! Most such cases have been eliminated from the Garage codebase, but there might still be some that remain. If your Garage-over-Sqlite seems to hang/freeze, this is the reason. - (adapter uses a bunch of unsafe code) - Heed (LMDB): - Not suited for 32-bit machines as it has to map the whole DB in memory. - (adpater uses a tiny bit of unsafe code) **My recommendation:** avoid 32-bit machines and use LMDB as much as possible. **Converting databases** is actually quite easy. For example from Sled to LMDB: ```bash cd src/db cargo run --features cli --bin convert -- -i path/to/garage/meta/db -a sled -o path/to/garage/meta/db.lmdb -b lmdb ``` Then, just add this to your `config.toml`: ```toml db_engine = "lmdb" ```
lx added 4 commits 2022-06-02 15:04:14 +00:00
First iteration of a generic DB layer
Some checks failed
continuous-integration/drone/push Build is failing
fd8d5c37f7
Implement iter() and range() on db
Some checks failed
continuous-integration/drone/push Build is failing
04901093e7
Do not put sled in garage's cargo.toml
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
6805e184e9
lx added 1 commit 2022-06-02 15:39:16 +00:00
Complete sled abstraction
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
fbd5b64ff3
lx added 1 commit 2022-06-02 16:11:52 +00:00
Use Cell instead of ArcSwap
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
f29b91232f
lx added 1 commit 2022-06-02 17:59:56 +00:00
Begin sqlite adapter
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
43704afb29
lx added 2 commits 2022-06-02 21:15:57 +00:00
Sqlite iter with unsafe code
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
c439cb11a9
lx added 1 commit 2022-06-02 21:44:00 +00:00
Horrible implementation of range for sqlite
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
0e4f336887
lx added 1 commit 2022-06-02 21:46:40 +00:00
Just refactor a bit
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
6ebb54cddb
lx added 2 commits 2022-06-03 08:45:33 +00:00
Change value type to be a dyn thing
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
f25309e58f
lx added 1 commit 2022-06-03 09:15:09 +00:00
Fix most clippy lints
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
cc0d984118
lx added 1 commit 2022-06-03 09:45:07 +00:00
Conversion utility
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
df0877bbba
lx added 1 commit 2022-06-03 10:12:57 +00:00
Garage works on sqlite, but it's a hack
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
bd9ff432d7
lx added 2 commits 2022-06-03 10:53:06 +00:00
fix clipy lint
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
295bc2741f
lx added 2 commits 2022-06-03 11:36:19 +00:00
whoops
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
3d18c9e183
lx added 2 commits 2022-06-03 12:17:03 +00:00
Update rmp-serde
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
16e0a655d0
lx added 1 commit 2022-06-03 13:31:48 +00:00
Start LMDB adapter, with fixed semantics
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
4e72c713f1
lx added 1 commit 2022-06-03 13:53:44 +00:00
LMDB: use Heed wrapper (much more complete)
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
bd2997a453
lx added 2 commits 2022-06-03 14:42:04 +00:00
Integrate LMDB with rest
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed
2d5541b0e7
lx added 2 commits 2022-06-06 10:02:59 +00:00
Fix more sqlite deadlocks
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
4539a6c229
lx added 3 commits 2022-06-06 12:08:28 +00:00
This reverts commit 16e0a655d0.
Small syntax changes
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
0ab21e780e
lx added 1 commit 2022-06-06 12:09:24 +00:00
Whoops
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
17918e2ef5
lx added 1 commit 2022-06-06 13:07:43 +00:00
Simplify lmdb adapter (one less indirection)
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
a65049db8f
lx added 2 commits 2022-06-06 13:46:18 +00:00
Table updated trigger now happens in transaction, this is waaaay better!
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
1897815358
lx added 1 commit 2022-06-06 14:13:24 +00:00
Update Cargo.nix
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
9238fda9b2
lx added 1 commit 2022-06-06 14:29:19 +00:00
Improve things in block manager & correctly propagate .len() errors
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
1dabd98330
lx added 1 commit 2022-06-06 14:31:50 +00:00
add comment
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
72e6419b1b
lx added 1 commit 2022-06-06 14:32:12 +00:00
fix
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
bbf68aa039
lx added 1 commit 2022-06-06 14:37:53 +00:00
Fix more .unwrap()'s
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
c3c8d59c99
lx added 1 commit 2022-06-06 14:45:07 +00:00
in db convert: map size up to 1TB on 64-bit systems
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
fd2fe18de3
lx added 1 commit 2022-06-06 14:51:12 +00:00
Add inline marker on a bunch of db functions
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
72a87c8686
lx added 1 commit 2022-06-06 15:02:00 +00:00
Fix clippy lint
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
1f9a371b9a
lx added 1 commit 2022-06-06 15:06:31 +00:00
Remove useless clones in sqlite
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
e42c7bed38
lx added 1 commit 2022-06-06 20:02:43 +00:00
Add nix overrides to include lmdb and sqlite3 libraries
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
35544cac39
lx added 1 commit 2022-06-06 20:35:56 +00:00
bundled sqlite
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
3de9320a0e
lx added 1 commit 2022-06-06 21:00:27 +00:00
Try once again to fix sqlite bundling in nix
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
5dbc79b77e
lx added 1 commit 2022-06-07 14:53:34 +00:00
Bring back the counted tree hack for Sled (with caveat)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
a9e79f848b
caveat: it's not only for sled
lx added 1 commit 2022-06-07 15:05:35 +00:00
db abstraction: make .insert() and .remove() return the old value
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
a3a01141ec
lx added 1 commit 2022-06-07 15:10:30 +00:00
Simplify
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
1d408d52b9
lx added 1 commit 2022-06-07 15:12:04 +00:00
make things more like before
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
cdc03da0b8
lx added 1 commit 2022-06-07 15:14:25 +00:00
less verbose code
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is passing
8c6f690fa5
lx added 3 commits 2022-06-07 15:50:29 +00:00
Cleaner error management (less error-prone api)
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
0543cb3453
lx added 1 commit 2022-06-07 15:56:24 +00:00
Correct error type for (unimplemented) iterators in transactions
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
c103ca8bf2
lx added 1 commit 2022-06-07 15:56:36 +00:00
cargo fmt
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
daec7995c3
lx added 1 commit 2022-06-07 16:06:46 +00:00
simplify & fix db tests
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
d41a67c4ee
lx added 1 commit 2022-06-07 16:21:05 +00:00
Inform user of what DB engine Garage is running on
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
845c344231
lx added 1 commit 2022-06-07 16:22:37 +00:00
sqlite can actually tell us its version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
cc4f1aca97
lx added 1 commit 2022-06-07 16:26:36 +00:00
Simplify sqlite
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
48928d2d70
lx added 1 commit 2022-06-07 16:36:21 +00:00
Remove useless function
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
0c0a02ad03
lx changed title from WIP: Abstract database behind generic interface and implement alternative drivers to Abstract database behind generic interface and implement alternative drivers 2022-06-07 17:02:26 +00:00
lx added 2 commits 2022-06-07 17:11:27 +00:00
Create meta directory in server (or else sqlite fails)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
e682478d75
lx merged commit b44d3fc796 into main 2022-06-08 08:01:56 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Deuxfleurs/garage#322
No description provided.