Scroll to navigation



mtbl_reader - read an MTBL file


#include <mtbl.h>

Reader objects:

struct mtbl_reader *
mtbl_reader_init(const char *fname, const struct mtbl_reader_options *ropt);

struct mtbl_reader *
mtbl_reader_init_fd(int fd, const struct mtbl_reader_options *ropt);

mtbl_reader_destroy(struct mtbl_reader **r);

const struct mtbl_source *
mtbl_reader_source(struct mtbl_reader *r);

const struct mtbl_metadata *
mtbl_reader_metadata(struct mtbl_reader *r);

Reader options:

struct mtbl_reader_options *

mtbl_reader_options_destroy(struct mtbl_reader_options **ropt);


struct mtbl_reader_options *ropt,
bool verify_checksums);


struct mtbl_reader_options *ropt,
bool madvise_random);


MTBL files are accessed by creating an mtbl_reader object, calling mtbl_reader_source() to obtain an mtbl_source handle, and using the mtbl_source(3) interface to read entries.

mtbl_reader objects may be created by calling mtbl_reader_init() with an fname argument specifying the filename to be opened, or mtbl_reader_init_fd() may be called with an fd argument specifying an open, readable file descriptor. Since MTBL files are immutable, the same MTBL file may be opened and read from concurrently by independent threads or processes.

If the ropt parameter to mtbl_reader_init() or mtbl_reader_init_fd() is non-NULL, the parameters specified in the mtbl_reader_options object will be configured into the mtbl_reader object.

File-level metadata may be accessed using the mtbl_metadata(3) interface, using the object returned by mtbl_reader_metadata(). Note that the metadata object is valid only as long as the reader object exists.

Reader options


Specifies whether or not the CRC32C checksum on each data block should be verified or not. If verify_checksums is enabled, a checksum mismatch will cause a runtime error. Note that the checksum on the index block is always verified, since the overhead of doing this once when the reader object is instantiated is minimal. The default is to not verify data block checksums.


Specifies whether the kernel should be advised if the data access patterns are expected to be random or not. This may hurt some workloads but help others. The default is to not set this advisory information.

This option can be explicitly overridden by setting the environment variable MTBL_READER_MADVISE_RANDOM to the string "0" (force disable) or "1" (force enable).

This option only has any effect on systems that have the posix_madvise or madvise system calls.


mtbl_reader_init() and mtbl_reader_init_fd() return NULL on failure, and non-NULL on success.