MTBL_READER(3)
π MTBL_READER π
okay bestie, gather round, because today we're learning about mtbl_reader β the little handle that lets you read an MTBL file. yes, from the mtbl manual, section 3. this is the whole entire page, no skips, no crumbs left behind. π
β¨ NAME β¨
mtbl_reader β read an MTBL file. that's it, that's the whole job. iconic behavior honestly. π
πΈ SYNOPSIS πΈ
first things first, you gotta invite the library to the party:
#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);
void
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_init(void);
void
mtbl_reader_options_destroy(struct mtbl_reader_options **ropt);
void
mtbl_reader_options_set_verify_checksums(
struct mtbl_reader_options *ropt,
bool verify_checksums);
void
mtbl_reader_options_set_madvise_random(
struct mtbl_reader_options *ropt,
bool madvise_random);
π DESCRIPTION π
so here's the tea. to read an MTBL file you make an mtbl_reader object, then you call mtbl_reader_source() to get yourself an mtbl_source handle, and then you use the whole mtbl_source(3) interface to actually read entries. that's the pipeline, periodt. β¨
you've got two ways to make an mtbl_reader:
- call
mtbl_reader_init()with anfnameargument β that's the filename you want opened - or call
mtbl_reader_init_fd()with anfdargument β that's an open, readable file descriptor, and yes it must be readable, no cap
and here's the cute part: MTBL files are immutable, so the exact same MTBL file can be opened and read from concurrently by independent threads or processes. literally no drama, no locking, no fighting. sharing is caring. π«Ά
if the ropt parameter you hand to mtbl_reader_init() or mtbl_reader_init_fd() is non-NULL, then all the parameters you set in that mtbl_reader_options object get configured into your mtbl_reader object. if it's NULL, you're just running stock. π
file-level metadata? that's the mtbl_metadata(3) interface, and you get to it via the object returned by mtbl_reader_metadata().
β οΈ bestie listen to me: that metadata object is valid only as long as the reader object exists. the moment your reader dips, the metadata is gone. do not be out here holding onto a metadata pointer after the reader is destroyed, i am begging. π
π Reader options
β verify_checksums
this one is the vibe check for your data. it specifies whether or not the CRC32C checksum on the index block and each data block should be verified or not.
- if
verify_checksumsis enabled and there's a checksum mismatch β that's a fatal runtime error. not a warning, not a little note, a whole fatal runtime error. π - the default is to not verify index or data block checksums.
β madvise_random
this one specifies whether the kernel should be advised if the data access patterns are expected to be random or not. and lowkey? this may hurt some workloads but help others. it's giving "it depends". π€·
- the default is to not set this advisory information.
- this option can be explicitly overridden by setting the environment variable
MTBL_READER_MADVISE_RANDOMto the string"0"(force disable) or"1"(force enable). so you can just vibe-check it from the environment if you want. - and important: this option only has any effect on systems that have the
posix_madviseormadvisesystem calls. if your system doesn't have them, this option is just sitting there looking pretty. π
π RETURN VALUE π
mtbl_reader_init()andmtbl_reader_init_fd()returnNULLon failure, and non-NULLon success.
so like, always check your pointer, bestie. NULL means it did not slay. π₯
that's the whole page, and it came from the MTBL_READER(3) manual, dated 11/14/2022. mwah, go read some files, ily, bye! πβ¨ππ¦πΈπ π«Ά
π¦ where this page comes from
- debian trixie: libmtbl-dev 1.6.1-1+b1 Β· Apache-2.0
- ubuntu questing: libmtbl-dev 1.6.1-1
- ubuntu resolute: libmtbl-dev 1.6.1-1build1 Β· Apache-2.0
- ubuntu stonking: libmtbl-dev 1.6.1-1build1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms