WiredTiger: Compressors in Java

| Version 3.1.0

Fork me on GitHub Join my user group
Compressors in Java

This section explains how to configure WiredTiger's builtin support for the lz4, snappy, zlib and zstd compression engines.

# Using LZ4 compression

To use the builtin support for Yann Collet's LZ4 compression, first check that LZ4 is installed in include and library directories searched by the compiler. Once LZ4 is installed, you can enable LZ4 using the `–enable-lz4` option to configure.

If LZ4 is installed in a location not normally searched by the compiler toolchain, you'll need to modify the `CPPFLAGS` and `LDFLAGS` to indicate these locations. For example, with the LZ4 includes and libraries installed in `/usr/local/include` and `/usr/local/lib`, you would run configure with the following additional arguments:

--enable-lz4 CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/include"

When opening the WiredTiger database, load the LZ4 shared library as an extension. For example, with the WiredTiger library installed in `/usr/local/lib`, you would use the following extension:

conn = wiredtiger.open(home,
"create," +
"extensions=[/usr/local/lib/libwiredtiger_lz4.so]");

Finally, when creating the WiredTiger object, set `block_compressor` to `lz4:`

ret = session.create("table:mytable",
"block_compressor=lz4,key_format=S,value_format=S");

# Using snappy compression

To use the builtin support for Google's snappy compression, first check that snappy is installed in include and library directories searched by the compiler. Once snappy is installed, you can enable snappy using the `–enable-snappy` option to configure.

If snappy is installed in a location not normally searched by the compiler toolchain, you'll need to modify the `CPPFLAGS` and `LDFLAGS` to indicate these locations. For example, with the snappy includes and libraries installed in `/usr/local/include` and `/usr/local/lib`, you would run configure with the following additional arguments:

--enable-snappy CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/include"

When opening the WiredTiger database, load the snappy shared library as an extension. For example, with the WiredTiger library installed in `/usr/local/lib`, you would use the following extension:

conn = wiredtiger.open(home,
"create," +
"extensions=[/usr/local/lib/libwiredtiger_snappy.so]");

Finally, when creating the WiredTiger object, set `block_compressor` to `snappy:`

ret = session.create("table:mytable",
"block_compressor=snappy,key_format=S,value_format=S");

# Using zlib compression

To use the builtin support for Greg Roelofs' and Mark Adler's zlib compression, first check that zlib is installed in include and library directories searched by the compiler. Once zlib is installed, you can enable zlib using the `–enable-zlib` option to configure.

If zlib is installed in a location not normally searched by the compiler toolchain, you'll need to modify the `CPPFLAGS` and `LDFLAGS` to indicate these locations. For example, with the zlib includes and libraries installed in `/usr/local/include` and `/usr/local/lib`, you would run configure with the following additional arguments:

--enable-zlib CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/include"

When opening the WiredTiger database, load the zlib shared library as an extension. For example, with the WiredTiger library installed in `/usr/local/lib`, you would use the following extension:

conn = wiredtiger.open(home,
"create," +
"extensions=[/usr/local/lib/libwiredtiger_zlib.so]");

The default compression level for the zlib compression is `Z_DEFAULT_COMPRESSION` (see the zlib documentation for further information); compression can be configured to other levels using the additional configuration argument `compression_level`.

conn = wiredtiger.open(home,
"create," +
"extensions=[/usr/local/lib/" +
"libwiredtiger_zlib.so=[config=[compression_level=3]]]");

Finally, when creating the WiredTiger object, set `block_compressor` to `zlib:`

ret = session.create("table:mytable",
"block_compressor=zlib,key_format=S,value_format=S");

# Using Zstd compression

To use the builtin support for Facebook's Zstd compression, first check that Zstd is installed in include and library directories searched by the compiler. Once Zstd is installed, you can enable Zstd using the `–enable-zstd` option to configure.

If Zstd is installed in a location not normally searched by the compiler toolchain, you'll need to modify the `CPPFLAGS` and `LDFLAGS` to indicate these locations. For example, with the Zstd includes and libraries installed in `/usr/local/include` and `/usr/local/lib`, you would run configure with the following additional arguments:

--enable-zstd CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/include"

When opening the WiredTiger database, load the Zstd shared library as an extension. For example, with the WiredTiger library installed in `/usr/local/lib`, you would use the following extension:

conn = wiredtiger.open(home,
"create," +
"extensions=[/usr/local/lib/libwiredtiger_zstd.so]");

The default compression level for the zstd compression is 3; compression can be configured to other levels using the additional configuration argument `compression_level`.

conn = wiredtiger.open(home,
"create," +
"extensions=[/usr/local/lib/" +
"libwiredtiger_zstd.so=[config=[compression_level=9]]]");

Finally, when creating the WiredTiger object, set `block_compressor` to `zstd:`

ret = session.create("table:mytable",
"block_compressor=zstd,key_format=S,value_format=S");

# Upgrading compression engines

WiredTiger does not store information with file blocks to identify the compression engine used to compressed the block. Applications wanting to upgrade to some future compression engine (without requiring a file dump and re-load), should ensure each compressed block includes enough information to identify the compression engine used, so its compression code can correctly decompress old and new blocks.

# Custom compression engines

WiredTiger may be extended by adding custom compression engines; see WT_COMPRESSOR for more information.