Expand description
Rust FFI interface to the mtbl C library for dealing with SSTables (write-once sorted map files).
SSTables are basically constant on-disk maps, like those used by CDB (which also has Rust bindings, except using sorted maps instead of hashmaps.
Version 0.2 of mtbl-sys covers the 0.8 version of the MTBL C library.
§Function documentation
For documentation about each function, see MTBL’s extensive man pages, e.g.
man mtbl_reader.
§More details about MTBL
Quoting from the MTBL documentation:
mtbl is not a database library. It does not provide an updateable key-value data store, but rather exposes primitives for creating, searching and merging SSTable files. Unlike databases which use the SSTable data structure internally as part of their data store, management of SSTable files – creation, merging, deletion, combining of search results from multiple SSTables – is left to the discretion of the mtbl library user.
mtbl SSTable files consist of a sequence of data blocks containing sorted key-value pairs, where keys and values are arbitrary byte arrays. Data blocks are optionally compressed using zlib or the Snappy library. The data blocks are followed by an index block, allowing for fast searches over the keyspace.
The basic mtbl interface is the writer, which receives a sequence of key-value pairs in sorted order with no duplicate keys, and writes them to data blocks in the SSTable output file. An index containing offsets to data blocks and the last key in each data block is buffered in memory until the writer object is closed, at which point the index is written to the end of the SSTable file. This allows SSTable files to be written in a single pass with sequential I/O operations only.
Once written, SSTable files can be searched using the mtbl reader interface. Searches can retrieve key-value pairs based on an exact key match, a key prefix match, or a key range. Results are retrieved using a simple iterator interface.
The mtbl library also provides two utility interfaces which facilitate a sort-and-merge workflow for bulk data loading. The sorter interface receives arbitrarily ordered key-value pairs and provides them in sorted order, buffering to disk as needed. The merger interface reads from multiple SSTables simultaneously and provides the key-value pairs from the combined inputs in sorted order. Since mtbl does not allow duplicate keys in an SSTable file, both the sorter and merger interfaces require a caller-provided merge function which will be called to merge multiple values for the same key. These interfaces also make use of sequential I/O operations only.
Structs§
- mtbl_
fileset - mtbl_
fileset_ options - mtbl_
iter - mtbl_
merger - mtbl_
merger_ options - mtbl_
metadata - mtbl_
reader - mtbl_
reader_ options - mtbl_
sorter - mtbl_
sorter_ options - mtbl_
source - mtbl_
writer - mtbl_
writer_ options
Enums§
- Compression
Type - Compression method used when writing an MTBL file.
- MtblRes
Functions§
- mtbl_
crc32c ⚠ - mtbl_
fileset_ ⚠destroy - mtbl_
fileset_ ⚠init - mtbl_
fileset_ ⚠options_ destroy - mtbl_
fileset_ ⚠options_ init - mtbl_
fileset_ ⚠options_ set_ merge_ func - mtbl_
fileset_ ⚠options_ set_ reload_ interval - mtbl_
fileset_ ⚠reload - mtbl_
fileset_ ⚠reload_ now - mtbl_
fileset_ ⚠source - mtbl_
fixed_ ⚠decode32 - mtbl_
fixed_ ⚠decode64 - mtbl_
fixed_ ⚠encode32 - mtbl_
fixed_ ⚠encode64 - mtbl_
iter_ ⚠destroy - mtbl_
iter_ ⚠next - mtbl_
merger_ ⚠add_ source - mtbl_
merger_ ⚠destroy - mtbl_
merger_ ⚠init - mtbl_
merger_ ⚠options_ destroy - mtbl_
merger_ ⚠options_ init - mtbl_
merger_ ⚠options_ set_ merge_ func - mtbl_
merger_ ⚠source - mtbl_
metadata_ ⚠bytes_ data_ blocks - Total number of bytes consumed by data blocks.
- mtbl_
metadata_ ⚠bytes_ index_ block - Total number of bytes consumed by the index.
- mtbl_
metadata_ ⚠bytes_ keys - Total number of bytes that all keys would occupy if stored end-to-end in a byte array with no delimiters.
- mtbl_
metadata_ ⚠bytes_ values - Total number of bytes that all values in the file would occupy if stored end-to-end in a byte array with no delimiters.
- mtbl_
metadata_ ⚠compression_ algorithm - One of the compression values allowed by mtbl_writer(3).
- mtbl_
metadata_ ⚠count_ data_ blocks - Total number of data blocks.
- mtbl_
metadata_ ⚠count_ entries - Total number of key-value entries.
- mtbl_
metadata_ ⚠data_ block_ size - Maximum size of an uncompressed data block, see mtbl_writer(3).
- mtbl_
metadata_ ⚠index_ block_ offset - Byte offset in the MTBL file where the index begins.
- mtbl_
reader_ ⚠destroy - mtbl_
reader_ ⚠init - mtbl_
reader_ ⚠init_ fd - mtbl_
reader_ ⚠metadata - mtbl_
reader_ ⚠options_ destroy - mtbl_
reader_ ⚠options_ init - mtbl_
reader_ ⚠options_ set_ madvise_ random - mtbl_
reader_ ⚠options_ set_ verify_ checksums - mtbl_
reader_ ⚠source - mtbl_
sorter_ ⚠add - mtbl_
sorter_ ⚠destroy - mtbl_
sorter_ ⚠init - mtbl_
sorter_ ⚠iter - mtbl_
sorter_ ⚠options_ destroy - mtbl_
sorter_ ⚠options_ init - mtbl_
sorter_ ⚠options_ set_ max_ memory - mtbl_
sorter_ ⚠options_ set_ merge_ func - mtbl_
sorter_ ⚠options_ set_ temp_ dir - mtbl_
sorter_ ⚠write - mtbl_
source_ ⚠get - mtbl_
source_ ⚠get_ prefix - mtbl_
source_ ⚠get_ range - mtbl_
source_ ⚠iter - mtbl_
varint_ ⚠decode32 - mtbl_
varint_ ⚠decode64 - mtbl_
varint_ ⚠encode32 - mtbl_
varint_ ⚠encode64 - mtbl_
varint_ ⚠length - mtbl_
varint_ ⚠length_ packed - mtbl_
writer_ ⚠add - mtbl_
writer_ ⚠destroy - mtbl_
writer_ ⚠init - mtbl_
writer_ ⚠init_ fd - mtbl_
writer_ ⚠options_ destroy - mtbl_
writer_ ⚠options_ init - mtbl_
writer_ ⚠options_ set_ block_ restart_ interval - mtbl_
writer_ ⚠options_ set_ block_ size - mtbl_
writer_ ⚠options_ set_ compression