logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

mtbl_writer - create an MTBL file

Description

       MTBL files are written to disk by creating an mtbl_writer object, calling mtbl_writer_add() for each
       key-value entry, and then calling mtbl_writer_destroy().

       mtbl_writer_add() copies key-value pairs from the caller into the mtbl_writer object. Keys are specified
       as a pointer to a buffer, key, and the length of that buffer, len_key. Values are specified as a pointer
       to a buffer, val, and the length of that buffer, len_val.

       Keys must be in sorted, lexicographical byte order. The same key may not be added to an mtbl_writer more
       than once. If the input entries are not sorted or may contain duplicate keys, then the mtbl_sorter(3)
       interface should be used instead.

       mtbl_writer objects may be created by calling mtbl_writer_init() with an fname argument specifying a
       filename to be created. The filename must not already exist on the filesystem. Or, mtbl_writer_init_fd()
       may be called with an fd argument specifying an open, writable file descriptor. Prior to the call, moving
       fd's cursor via write(2) or lseek(2) will have the effect of reserving the file’s initial bytes for
       non-MTBL use. MTBL will only write at, or above the current offset. Thereafter, only mtbl_writer may
       access this fd (including closing it), and no other writes may be made to the underlying file above the
       first offset of the MTBL data. The MTBL data must be last in the file.

       If the wopt parameter to mtbl_writer_init() or mtbl_writer_init_fd() is non-NULL, the parameters
       specified in the mtbl_writer_options object will be configured into the mtbl_writer object.

   Writeroptionscompression

           Specifies the compression algorithm to use on data blocks. Possible values are MTBL_COMPRESSION_NONE,
           MTBL_COMPRESSION_SNAPPY, MTBL_COMPRESSION_LZ4, MTBL_COMPRESSION_LZ4HC, MTBL_COMPRESSION_ZSTD, or
           MTBL_COMPRESSION_ZLIB (the default).

       compression_level

           Specifies the compression level to use on data blocks, if the selected compression algorithm supports
           different compression levels. The compression algorithms which support different compression levels
           are MTBL_COMPRESSION_LZ4HC (0-16), MTBL_COMPRESSION_ZSTD (1-22), and MTBL_COMPRESSION_ZLIB (0-9).
           Other compression algorithms ignore this option, and compression levels outside the ranges supported
           by the algorithm will be silently clamped to the minimum or maximum supported level. If not
           specified, a reasonable default will be used.

       block_size

           The maximum size of uncompressed data blocks, specified in bytes. The default is 8 kilobytes.

       block_restart_interval

           How frequently to restart intra-block key prefix compression. The default is every 16 keys.

Name

       mtbl_writer - create an MTBL file

Return Value

mtbl_writer_init() and mtbl_writer_init_fd() return NULL on failure, and non-NULL on success.

       mtbl_writer_add() returns mtbl_res_success if the key-value entry was successfully copied into the
       mtbl_writer object, and mtbl_res_failure if not, for instance if there has been a key-ordering violation.

                                                   12/11/2016                                     MTBL_WRITER(3)

Synopsis

#include<mtbl.h>

       Writer objects:

       structmtbl_writer*mtbl_writer_init(constchar*fname,conststructmtbl_writer_options*wopt);structmtbl_writer*mtbl_writer_init_fd(intfd,conststructmtbl_writer_options*wopt);voidmtbl_writer_destroy(structmtbl_writer**w);mtbl_resmtbl_writer_add(structmtbl_writer*w,constuint8_t*key,size_tlen_key,constuint8_t*val,size_tlen_val);

       Writer options:

       structmtbl_writer_options*mtbl_writer_options_init(void);voidmtbl_writer_options_destroy(structmtbl_writer_options**wopt);voidmtbl_writer_options_set_compression(structmtbl_writer_options*wopt,mtbl_compression_typecompression_type);voidmtbl_writer_options_set_compression_level(structmtbl_writer_options*wopt,intcompression_level);voidmtbl_writer_options_set_block_size(structmtbl_writer_options*wopt,size_tblock_size);voidmtbl_writer_options_set_block_restart_interval(structmtbl_writer_options*wopt,size_tblock_restart_interval);

See Also