4 ms·
An importunately verbose and complicated API that I've recently come across is that of LMDB. https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database htt
by kazinator 3y ago
An importunately verbose and complicated API that I've recently come across is that of LMDB.
https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Databa...
Here is a long page explaining how to initialize things. (Warning: HTTP only!)
http://www.lmdb.tech/doc/starting.html http://www.lmdb.tech/doc/starting.html
Ya gotta create an environment with mdb_env_create. So okay, that is ready to use, right? Constructor has been called, we have an object, right? Nope! You have to open it now, with mdb_env_open.
But what the above page doesn't tell you is that mdb_env_create has flags. Oooh yeah. MDB_FIXEDMAP, MDB_NOSUBDIR,
MDB_RDONLY, MDB_WRITEMAP, MDB_NOMETASYNC, MDB_NOSYNC, MDB_NOTLS, MDB_NOLOCK, MDB_NORDAHEAD, MDB_NOMEMINIT, ...
What are all these for? Should you be using any of them? Are the defaults good?
So, once we have an env with the right flags, we can mdb_txn_begin. This takes flags again. Luckily, only MDB_RDONLY applies. Probably ....
So we are ready to transact now, right? Nope. "Once a transaction has been created, a database can be opened within it using mdb_dbi_open()." [Which has seven flags!]
But wait, the documentation hastens to add: "[a]lso, mdb_env_set_maxdbs() must be called after mdb_env_create() and before mdb_env_open() to set the maximum number of named databases you want to support."
Finally, "[w]ithin a transaction, mdb_get() and mdb_put() can store single key/value pairs if that is all you need to do (but see Cursors below if you want to do more)."
Ah cursors. Here, mdb_cursor_create doesn't have flags, phew! But there is an integer op code. mdb_cursor_get is basically the ioctl of database access.
MDB_FIRST,
MDB_FIRST_DUP,
MDB_GET_BOTH,
MDB_GET_BOTH_RANGE,
MDB_GET_CURRENT,
MDB_GET_MULTIPLE,
MDB_LAST,
MDB_LAST_DUP,
MDB_NEXT,
MDB_NEXT_DUP,
MDB_NEXT_MULTIPLE,
MDB_NEXT_NODUP,
MDB_PREV,
MDB_PREV_DUP,
MDB_PREV_NODUP,
MDB_SET,
MDB_SET_KEY,
MDB_SET_RANGE.
- malkia 3y agoI disagree, lmdb is exactly what you need to run exactly where you want. No more, no less.
- kazinator 3y agoEvery flag you don't use is more than what you need or want and could be a compile-time configuration option to remove the associated code which implements the flag. Functions represented as integer codes that go through a common dispatch function similar to ioctl lead to compiled code from which the linker cannot remove unused functions. If instead of a MDB_GET_BOTH_RANGE opcode to mdb_cursor_get there was a mdb_cursor_get_both_range function, then if you don't use that function, it could be removed out of the executable. (If it's put into its own object file, and the database library is statically linked.)
- malkia 3y agoOh, please let's not this go into another "compile time" flag, because I've seen enough where this goes. Unless you are doing strictly embedded, or whatever clearance software, you don't need this "compile time" thing. (I'm speaking from experience, having and still having to deal with tons of #ifdef code - gamedev, great for shipping to a console, awful for the rest of the code - game tools).
- deleted 3y ago[deleted]
- kazinator 3y agoYou can have it both ways! #ifdef FOO_BUILD_TIME_FLAGS #define foo_enabled(CTX, FLAG) ((FOO_BUILD_TIME_FLAGS & (FLAG)) != 0) #else #define foo_enabled(CTX, FLAG) (((CTX)->flags & (FLAG)) != 0) #endif If we specify FOO_BUILD_TIME_FLAGS symbol which expands to a bitwise OR or various flags (or maybe just zero!) then the flag checks in the code all become constant expressions, subject to dead code elimination. If we don't specify that, then there is a flags field that is checked at run-time. I'd rather have most of the flags go away. Pick a behavior and hard-coded. Those who want it some other way can UTSL: use the source, Luke. If you have 8 flags, that's 256 combinations to test for interactions.
- fluoridation 3y agoBerkeleyDB is similarly awful to use, with a billion little settings to configure before you can do anything useful, and endless fun ways to corrupt your database. It must be a thing with key-value store developers.
- rjh29 3y agoThe Perl core module for it isn't bad, it's one line to tie a hash to a DB file and then you can use it as normal. The main flags are to determine if it's RO/RW and whether to create the file if it doesn't exist.
- kazinator 3y agoNot the original DBM: https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/libdbm/dbm.h https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/libdbm... It's just a few paltry functions implementing a hashing scheme. Zero bells and whistles.