Commit Graph

14 Commits

Author SHA1 Message Date
Griffin Smith 81839aa6ae feat(): Allow creating database snapshots
Add a `create_snapshot` function, that creates a RocksDB database
snapshot from the given database handle and returns it.

There's a pretty fantastic amount of horribly unsafe Rust going on here
- primarily caused by the fact that the rust-rocksdb snapshot type is,
unlike Iterator or ColumnFamily or any of the other types that really
*should* be, parametrized by the lifetime of a borrowed reference to its
owner database. The abstraction provided by Rustler doesn't allow
non-static lifetime-parametrized struct types to be returned back to
Erlang as resources, for some technical type-mismatch reasons but also
practically because relying on the Erlang garbage collector to free our
stuff doesn't fit at *all* with rust's lifetime model.

The workaround here is to use `mem::transmute` (I told you it was
crazy...) to turn the snapshot reference from a `Snapshot<'a>` to a
`Snapshot<'static>`, and pass *that*, along with a held ARC reference to
the owning DB, to Erlang, and then when the Erlang GC decides it's time
to free the snapshot, go *back* to a first unbounded, then elided
lifetime to force the snapshot to be dropped.

I've done some cursory checking and regular operation (creating a
snapshot from a process then letting that process die) appears to not
leak the snapshots, but we should keep an eye on this to make sure we
don't have any leaks (or worse) in the future.

As a further note, the bit that parses out the argument for the NIFs
that now accept *either* a DB or a snapshot is a little mucky - that
should be revisited at a later date to see if we can clean it up a
little.
2017-11-30 15:30:06 -05:00
Griffin Smith ffa891319c feat(): Add Rox.stream_keys/2
In addition to Rox.stream/2, add a Rox.stream_keys/2 function, which
optimizes over `stream` by avoiding decoding the values of the stream
from binary at each step of the iteration. There's a later optimization
to be had here by avoiding allocating the Erlang term *entirely*.
2017-10-26 14:08:35 -04:00
Ryan Schmukler 87544c2e2b feat(): allow non-utf8 binary as keys
RocksDB supports any binary to be a key, not just UTF-8 encoded
strings. In the case of things like UUIDs, this difference can be a big
one (ie. 36 bytes vs 16 bytes).
2017-08-15 18:43:01 -04:00
William Carroll fc4ec51166
feat(batch): Impls batch merging 2017-06-22 17:29:50 -04:00
Ryan Schmukler 767483ca72 feat(): add Batch commands (atomic operations) 2017-06-15 14:25:19 -04:00
Ryan Schmukler e5f275cd04 test(stream): better testing 2017-05-25 18:07:59 -05:00
Ryan Schmukler f8dbe6a0db feat(): add delete, restore basic testing 2017-03-21 14:59:34 -04:00
Ryan Schmukler aab14d167e feat(): add auto opening of column families, streaming, enumerable and collectable 2017-03-21 14:09:51 -04:00
Ryan Schmukler 131b5df024 feat(): begin iterator, simplify API, refactor 2017-03-20 20:38:39 -04:00
Ryan Schmukler 7ee6cd3a53 feat(): add count/1 2017-01-24 16:50:37 -05:00
Ryan Schmukler 8415712ec6 fix(stream): fix partial exhaustion of a stream throwing errors 2016-08-18 19:25:38 -07:00
Ryan Schmukler 7f5dbac8b6 fix(): fix stream 2016-08-18 19:14:50 -07:00
Ryan Schmukler 1f74e54af2 test(): add basic tests 2016-08-16 16:37:33 -07:00
Ryan Schmukler 1875e93ff8 initial commit 2016-08-08 11:51:04 -04:00