russhwolf / multiplatform-settings

A Kotlin Multiplatform library for saving simple key-value data
Apache License 2.0
1.69k stars 67 forks source link

DBM proof-of-concept via QDBM #54

Closed russhwolf closed 2 years ago

russhwolf commented 4 years ago

Still needs some cleanup but it should be passing tests now

I remain woefully uncertain whether this is useful from an interop perspective.

goncalossilva commented 2 years ago

I'm not a Linux expert, but have some experience developing for Linux and would love to see multiplatform-settings support it (use case is a KMP library that will be used from Python). Throwing 2 cents in here, in case it helps.

QDBM is a solid option. For proper transactions and crash recovery, it should be set up using a B+ tree instead of a hash table. I think that requires using the Villa API instead of this one (ref). It's generally available, but not in Alpine. The author has mostly abandoned this project in favor of Tokyo/Kyoto Cabinet.

A similar option I'd recommend looking into is GDBM, i.e., GNU dbm. It's a rewrite of NDBM, but has features around crash tolerance and crash recovery. It's also widely available, including in Alpine. My guess is that the code would remain largely the same, except checking for the GDBM_NEED_RECOVERY error code and invoking gdbm_recover() accordingly.

Other options might seem interesting, but they either haven't been around for as long as Q/GDBM has, they aren't as widely available, have various documented corruption issues, or I haven't heard about them. 😅

russhwolf commented 2 years ago

I looked at GDBM as well when I first did this, but had licensing concerns. QDBM is LGPL which I understand is safe to link against from Apache-licensed code. GDBM is GPL3 which I understand is not.

russhwolf commented 2 years ago

Closing in favor of #111 and/or #112