The storage engine of OceanBase Database is built on the log-structured merge-tree (LSM-tree) architecture. In this architecture, data is stored in MemTables and SSTables. When the size of a MemTable exceeds the specified threshold, data in the MemTable is flushed to an SSTable to release the memory space. This process is called a minor compaction. Each minor compaction generates a new SSTable. During off-peak hours of a day, or when the number of minor compactions exceeds the specified threshold, the baseline SSTables and incremental SSTables generated by minor compactions are merged into one SSTable. This process is called a major compaction.
The percentage of memory allowed for MemTables to the total available MemStore memory of a tenant is specified by the memstore_limit_percentage parameter. MemTables are classified into active MemTables and frozen MemTables. When the memory usage of MemTable reaches memstore_limit_percentage × freeze_trigger_percentage, a freeze is automatically triggered to generate a new active MemTable. The existing active MemTable becomes a frozen MemTable. Then, a minor compaction is automatically scheduled. When the minor compaction is completed, the memory occupied by the frozen MemTable is released.
Note
- The
memstore_limit_percentageparameter specifies the percentage of memory allowed for MemTables to the total available MemStore memory of a tenant. Default value: 0. Value range: [0, 100). For more information about this parameter, see memstore_limit_percentage. - The
freeze_trigger_percentageparameter specifies the threshold of memory usage in percentage of tenants for triggering a global freeze. The default value is 20, with a value range of (0, 100). For more information about this parameter, see freeze_trigger_percentage.
You can increase the frequency of minor compaction by using the following methods:
Set the
freeze_trigger_percentageparameter to a smaller value.Manually trigger a minor compaction by running the following command:
alter system minor freeze.
A major compaction is automatically triggered when the number of minor compactions in a tenant reaches the threshold specified by using the major_compact_trigger parameter. The default value is 0 in OceanBase Database V4.0, which indicates that the automatic triggering of a major compaction based on the number of minor compactions is disabled.
Note
The major_compact_trigger parameter specifies the threshold of the number of minor compactions at which a major compaction is triggered. The value range is [0, 65535]. For more information about this parameter, see major_compact_trigger.
You can increase the frequency of major compaction by using the following methods:
Set the
major_compact_triggerparameter to a smaller value.Manually trigger a major compaction by running the following command:
alter system major freeze.
Data inconsistencies during a major compaction
The following data inconsistencies may occur during a major compaction:
The number of rows in the primary table is inconsistent with that in the index table.
The checksum values of some columns in the major SSTable are inconsistent.
The checksum values of all rows in the major SSTable are inconsistent.