A rough guide for how to integrate SplinterDB into a program.
(Or just skip to the Example programs below.)
Follow instructions to build SplinterDB from source.
Our Continuous Integration system publishes Docker images that are sufficient for linking SplinterDB into another program.
Example usage:
$ docker run -it --rm projects.registry.vmware.com/splinterdb/splinterdb /bin/bash
The container includes:
- runtime dependencies for SplinterDB, including
libaio
andlibxxhash
- the SplinterDB static and shared libraries:
/usr/local/lib/libsplinterdb.{a,so}
- header files for SplinterDB's public API:
/usr/local/include/splinterdb/
- the pre-built test binary and test script:
/splinterdb/bin/driver_test
and/splinterdb/test.sh
Note: this image does not include tools to build SplinterDB itself from source. See our build docs for that.
Docker-based development is beyond the scope of this doc, but consider using bind mounts to access source code on your host OS:
$ docker run -it --rm \
--mount type=bind,source="$PWD/my-app-src",target=/my-app-src \
projects.registry.vmware.com/splinterdb/splinterdb /bin/bash
For example, a C linker would need the flag -lsplinterdb
. You may also need to configure include and library directories.
For basic key-value store use cases, splinterdb_kv.h
should suffice.
-
Set the fields in
splinterdb_kv_cfg
-
splinterdb_kv_create()
will create a new database andsplinterdb_kv_close()
closes it. All access to that database must go through the singlesplinterdb_kv*
object returned. In particular, it is not safe for multiple processes to open the same disk file or device.For example, a RDBMS using SplinterDB as a storage layer might consolidate all "table open" and "table close" operations across different client connections into a shared, per-table, reference-counted resource which internally calls
splinterdb_kv_open()
in its constructor andsplinterdb_kv_close()
in its destructor. -
Basic key/value operations like insert, delete, lookup and iteration (range scan) are supported.
-
A range query should use the iterator workflow described in
splinterdb_kv.h
. -
SplinterDB is optimized for multi-threaded use, but follow these guidelines:
-
The thread which called
splinterdb_kv_create()
orsplinterdb_kv_open()
is called the "initial thread". -
The initial thread should be the one to call
splinterdb_kv_close()
when thesplinterdb_kv
is no longer needed. -
Threads (other than the initial thread) that will use the
splinterdb_kv
must be registered before use and unregistered before exiting:-
From a non-initial thread, call
splinterdb_kv_register_thread()
. Internally, SplinterDB will allocate scratch space for use by that thread. -
To avoid leaking memory, a non-initial thread should call
splinterdb_kv_deregister_thread()
before it exits.
-
-
Known issue: In a pinch, non-initial, registered threads may call
splinterdb_kv_close()
, but their scratch memory would be leaked. -
Note these rules apply to system threads, not runtime-managed threading available in higher-level languages.
-
Our C unit tests serve as examples for how to call SplinterDB APIs. For example
tests/unit/splinterdb_kv_test.c
covers various basic operations on a single threadtests/unit/splinterdb_kv_stress_test.c
uses multiple threads
In addition, splinterdb-cli
is a small Rust program that may serve as an example for basic usage, including threading.