October 20th, Q&A session: Get you issues solved and questions answered!

GitHub logo
Edit

Disk Compression

Disk compression refers to the process of compressing data pages when they are written to disk, reducing the size of the on-disk storage. The pages are kept in memory uncompressed, but when the data is flushed to disk it is compressed using the configured algorithm. This applies only to data pages that are stored to the persistent storage and does not compress indexes or WAL records. WAL records compression can be enabled separately.

Disk page compression can be enabled on a per cache basis in the cache configuration. The cache must reside in a persistent data region. There is no option to enable disk page compression globally at the moment. Moreover, the following prerequisites must be met:

  • Set the pageSize property in your data storage configuration to at least 2 times the page size of your file system. It means that the page size must be either 8K or 16K.

  • Enable the ignite-compress module.

To enable disk page compression for a cache, provide one of the available compression algorithms in the cache configuration, as shown in the following example:

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="dataStorageConfiguration">
        <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
            <property name="pageSize" value="#{4096 * 2}"/>
            <property name="defaultDataRegionConfiguration">
                <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                    <property name="persistenceEnabled" value="true"/>
                </bean>
            </property>
        </bean>
    </property>
    <property name="cacheConfiguration">
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
            <property name="name" value="myCache"/>
            <!-- enable disk page compression for this cache -->
            <property name="diskPageCompression" value="LZ4"/>
            <!-- optionally set the compression level -->
            <property name="diskPageCompressionLevel" value="10"/>
        </bean>
    </property>
</bean>
DataStorageConfiguration dsCfg = new DataStorageConfiguration();

//set the page size to 2 types of the disk page size
dsCfg.setPageSize(4096 * 2);

//enable persistence for the default data region
dsCfg.setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true));

IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setDataStorageConfiguration(dsCfg);

CacheConfiguration cacheCfg = new CacheConfiguration("myCache");
//enable disk page compression for this cache
cacheCfg.setDiskPageCompression(DiskPageCompression.LZ4);
//optionally set the compression level
cacheCfg.setDiskPageCompressionLevel(10);

cfg.setCacheConfiguration(cacheCfg);

Ignite ignite = Ignition.start(cfg);
This API is not presently available for C++. You can use XML configuration.

Supported Algorithms

The supported compression algorithms include:

  • ZSTD — supports compression levels from -131072 to 22 (default: 3).

  • LZ4 — supports compression levels from 0 to 17 (default: 0).

  • SNAPPY — the Snappy algorithm.

  • SKIP_GARBAGE — this algorithm only extracts useful data from half-filled pages and does not compress the data.