Did you know ... | Search Documentation: |
Pack rocksdb -- prolog/rocksdb.pl |
RocksDB is an embeddable persistent key-value store for fast storage. The store can be used only from one process at the same time. It may be used from multiple Prolog threads though. This library provides a SWI-Prolog binding for RocksDB. RocksDB just associates byte arrays. This interface defines several mappings between Prolog datastructures and byte arrays that may be configured to store both keys and values. See rocks_open/3 for details.
rocksdb/include/rocksdb/options.h
are supported, in addition
to the following options:
alias(+Name)
Give the database a name instead of using an anonymous
handle. A named database is not subject to GC and must
be closed explicitly.open(+How)
If How is once
and an alias is given, a second open simply
returns a handle to the already open database.key(+Type)
value(+Type)
Define the type for the key and value. This must be
consistent over multiple invocations. Defined types are:
X = f(a), Key = k(X,X)
is a different
key from Key = k(f(a),f(a))
and X = [a|X]
is a
different key from X = [a,a|X]
. Applications for which
such keys should match must first normalize the key.
Normalization can be based on term_factorized/3 from
library(terms).
In addition, value
accepts one of list(type)
or set(type)
,
currently only for the numeric types. This causes
rocks_put/3 and rocks_get/3 to exchange the value as a
list and installs a built-in merge function.mode(+Mode)
One of read_write
(default) or read_only
. The latter
uses OpenForReadOnly() to open the database.optimize_for_small_db(true)
- Use this if your DB is very
small (like under 1GB) and you don't want tog
spend lots of memory for memtables.increase_parallelism(true)
- see DBOptions::IncreaseParallelism()list(Type)
or set(Type)
, Value must be a list. For
set(Type)
the list is converted into an ordered set.list(Type)
or set(Type)
to be used when opening the database.
Using rocks_merge/3 rather than rocks_get/2, update and
rocks_put/3 makes the operation atomic and reduces disk
accesses.
Options are the same as for rocks_put/4.
Merger is called as below, where two clauses are required:
one with How set to partial
and one with How set to
full
. If full
, MergeValue is a list of values that need
to be merged, if partial
, MergeValue is a single value.
call(:Merger, +How, +Key, +Value0, +MergeValue, -Value)
If Key is not in RocksDB, Value0 is unified with a value that
depends on the value type. If the value type is an atom, it is
unified with the empty atom; if it is string
or binary
it is
unified with an empty string; if it is int32
or int64
it is
unified with the integer 0; and finally if the type is term
it
is unified with the empty list.
For example, if the value is a set of Prolog values we open the
database with value(term)
to allow for Prolog lists as value and
we define merge_set/5 as below.
merge(partial, _Key, Left, Right, Result) :- ord_union(Left, Right, Result). merge(full, _Key, Initial, Additions, Result) :- append([Initial|Additions], List), sort(List, Result).
If the merge callback fails or raises an exception the merge operation fails and the error is logged through the RocksDB logging facilities. Note that the merge callback can be called in a different thread or even in a temporary created thread if RocksDB decides to merge remaining values in the background.
Options are the same as for rocks_put/4.
list(Type)
or set(Type)
this
returns a Prolog list.list(Type)
or set(Type)
Value is a list.
Options are the same as for rocks_get/4.
atom
, string
or binary
. To only
iterate all keys with Prefix, use rocks_enum_prefix/4 or the
construct below.
Options are the same as for rocks_get/4.
rocks_enum_from(DB, Key, Value, Prefix), ( sub_atom(Key, 0, _, _, Prefix) -> handle(Key, Value) ; !, fail )
Options are the same as for rocks_get/4.
Options are the same as for rocks_put/4.
Actions is a list of:
The following example is translated from the RocksDB documentation:
rocks_get(RocksDB, key1, Value), rocks_batch(RocksDB, [ delete(key1), put(key2, Value) ])
The following predicates are exported, but not or incorrectly documented.