Commit Graph

50 Commits

Author SHA1 Message Date
Martchus bb985870f0 Avoid overflow when running out of IDs
* Throw an exception instead
* Add function that allows re-using lower IDs instead
* Move functions to query IDs to read-only operations
2022-04-15 19:18:35 +02:00
Martchus 95ff695381 Add helper to rebuild typed database 2022-03-07 23:31:47 +01:00
Martchus 62fe316637 Pass `func` as `const &` in `modify` function 2022-03-07 23:31:40 +01:00
Martchus 4580d7242a Fix typos 2022-03-01 00:42:50 +01:00
Martchus f6fd78155b Add `rbegin()` and `lower_bound()` for main DB 2022-02-25 00:29:17 +01:00
Martchus bf6dbf0e42 Improve comments 2022-02-21 23:46:32 +01:00
Martchus 6c21fe7cb1 Use type alias for ID type 2022-02-21 22:57:15 +01:00
Martchus b87dd49bba Allow iterating over index
The use-case is checking the index-value first (e.g. just a simple string)
to decide whether the object is actually instead of deserializing the
whole object (e.g. a huge object which is quite costly to deserialize)
directly.
2022-02-19 00:10:17 +01:00
Martchus 64ba75ac48 Add serialization shortcuts for std::string and std::uintX_t types 2022-02-19 00:06:13 +01:00
Martchus b302cdfabe Allow using smart pointers in iterator 2022-02-18 19:20:14 +01:00
Martchus 1517bdce29 Fix case of having no index at all 2022-02-10 22:37:32 +01:00
Martchus 28a3aa7345 Add default c'tor and move assignment to transactions 2022-02-01 22:02:25 +01:00
Martchus 1748fe674c Use `std::`-prefix for all std-types used in headers 2022-02-01 20:26:46 +01:00
Martchus 011bfa9ab9 Use `std::size_t` consistently for index (of index) 2022-02-01 20:26:46 +01:00
Martchus 65d8653c77 Get rid of macros and boilerplate code for handling indexes
and by the way support more than 4 indexes at the same time
2022-02-01 20:26:46 +01:00
Martchus 2e7d278c9b Apply uniform formatting via clang-format 2022-01-30 21:14:43 +01:00
Martchus b499a201c2 Add CMake build system replacing Makefile
* Allow building a shared library with proper exports
* Remove bundled catch2 library in favor of searching for system-provided
  version
* Adapt/fix tests and examples to latest changes
* Fix several warnings
2022-01-30 01:14:42 +01:00
Martchus adcb9338e8 Speed-up cleaning DB/indexes via `mdb_drop` instead of manual deletions 2022-01-26 00:43:21 +01:00
Martchus 31a45912dc Add `keyConv` function for `string_view` 2022-01-25 23:39:06 +01:00
Martchus f2042c59a5 Avoid instantiating an std::string when calling serializer 2022-01-25 23:39:06 +01:00
Martchus c8a865528e Pass string_view in serFromString() by value as it is just two pointers 2022-01-25 23:38:30 +01:00
Martchus 3bafada5cc Use distinct exception class and unify format of error messages
* Avoid manual code for making error message
* Use `const` for the return code variable where possible
* Unify formatting of error messages
2022-01-22 18:59:54 +01:00
Martchus a002cdecdf Improve some comments converting them to Doxygen-recognized comments 2022-01-22 18:18:15 +01:00
Martchus d53687bdee Allow users to plug their own (de)serialization implementation
* Move serialization-specific code into its own header
* Keep reflective-rapidjson-based implementation as example
2022-01-18 22:24:31 +01:00
Martchus b833bfef3b Move everything under a namespace 2022-01-18 22:09:12 +01:00
Martchus c96b87c60a Remove obsolete comments 2022-01-18 22:09:12 +01:00
Martchus 551339ff8f Avoid instantiating new `std::string` when converting key 2022-01-18 20:35:43 +01:00
Martchus 98bf74ed80 Allow returning non-const value when iterating
Modifying the object shouldn't harm and directly using it avoids a copy.
Of course this does not modify the object in the database.
2021-12-25 23:05:49 +01:00
Martchus 84e2e9ceea Use ReflectiveRapidJSON for serialization 2021-12-25 23:05:49 +01:00
Martchus b621c27ad4 Fix several warnings
* Avoid implicit signedness conversions where possible
* Avoid c-style casts
2021-12-25 23:02:10 +01:00
Jonas Schäfer 3c57c6a113 Hide MDB*Transaction behind a unique_ptr front
This is to prevent the issue with Object Slicing. With the previous
solution (where MDB*Transaction are normal objects), consider the
following code:

    MDBRWTransaction txn = env.getRWTransaction();

    //! Invalid: We explicitly break this move because it would be
    //! unsafe:
    // MDBROTransaction ro_txn(std::move(txn));

    //! Valid, RW inherits from RO now, so we can bind an RO
    //! reference to an RW transaction.
    MDBROTransaction &ro_txn = txn;

    //! Dangerous!!
    MDBROTransaction ro_txn2(std::move(ro_txn));

The last move there breaks the semantics of the RW transaction which
is bound to the reference ro_txn. It looses its RW cursors, which
remain partly inside the txn instance. All kinds of weird and bad
things can happen here. For instance, the ro_txn2 would go out of
scope before the txn, calling the destructor MDBROTransaction
destructor (which defaults to commit instead of abort!) and only
freeing parts of the cursors. Only then the MDBRWTransaction
destructor is called, which will free the cursors which belong to
the RW transaction which has already been committed.

The only safe way to prevent Object Slicing in this scenario I
could come up with is to disallow moves of the objects altogether
and instead use unique_ptr as front for them. This also removes
an additional dynamic allocation per RW transaction (for the
cursor vector), since the address of that vector is now constant
over the lifetime of the transaction without indirection.
2019-11-11 21:23:20 +01:00
Jonas Schäfer d2b0ee057a Re-work the class hierarchy of cursors and transactions
MDBRWTransaction now inherits from MDBROTransaction. Both
transaction types will free their cursors before aborting or
committing. In addition, transactions are now virtual classes.

The reason for this is that RW and RO transactions are handled
very differently in LMDB. Nevertheless, it is very useful to be
able to write read-only code in a way which also can use an RW
transaction. This saves code duplication or unnecessary templates.

Since the only methods which are reqiured to be virtual on
transactions for this to work are the destructor and the
abort/commit methods, the overhead should be neglegible.

This also comes in very handy when going forward to implement
nested transactions, because it is not possible to nest RO
transactions below RW transactions, exacerbating the issue
described above.

Fixes #7 en passant.
2019-11-11 21:23:20 +01:00
bert hubert e02d654dfe namespace cleanliness 2019-02-06 11:08:55 +01:00
bert hubert bdcd9150a9 unify RO and RW cursor operations, move serFromString to a view 2019-01-09 09:58:04 +01:00
bert hubert 7dac111b02 to work around clang issue, keyConv is now very ugly, but completely generic 2019-01-05 14:40:28 +01:00
bert hubert cb2ed50e1f getKey for typed +const correctness 2019-01-04 20:51:04 +01:00
bert hubert 8851f18cbe better default init of MDBOutVal in typed 2018-12-28 19:21:32 +01:00
bert hubert f977301e94 expand tests to time_t indexes, found bug in our keyconv! 2018-12-28 16:45:44 +01:00
bert hubert b3eb2a03cb add tests, prefix_range 2018-12-28 16:33:20 +01:00
bert hubert 59b3b602fa lots of changes 2018-12-27 17:49:41 +01:00
bert hubert 4c1b5e404c get now returns an id, making id=0 special, split out our sample code 2018-12-17 14:56:01 +01:00
bert hubert 3277381170 s/insert/put/ 2018-12-16 21:46:53 +01:00
bert hubert 654e782b5f add a lot of comments for future ahu 2018-12-16 20:28:49 +01:00
bert hubert bb981d6d31 add compound keys and iterator-- 2018-12-16 15:58:38 +01:00
bert hubert a144209f12 find, begin 2018-12-15 21:06:47 +01:00
bert hubert 5af0bb3e67 readonly transactions, common implementation 2018-12-15 17:53:29 +01:00
bert hubert f11d89dd4a more docs + cleanups 2018-12-15 01:54:29 +01:00
bert hubert d3f94d67c3 tuplify, macrofy, add cardinality, templated find, get etc 2018-12-15 00:46:15 +01:00
bert hubert ada45b45ba interim pre-tuple 2018-12-14 23:46:46 +01:00
bert hubert d98d657765 eradicate some MDB_dbi use, more string_view 2018-12-14 23:00:44 +01:00