This topic describes the principles behind minor compaction.
The storage engine of OceanBase AI Database uses an LSM-tree architecture. Data is primarily stored in two parts: the MemTable and the SSTable. The SSTable is further divided into three types: Mini SSTable, Minor SSTable, and Major SSTable.
Minor compaction consists of two processes: Mini Compaction and Minor Compaction. When the memory usage of the MemTable reaches a certain threshold, data in the MemTable is flushed to disk as a Mini SSTable to free up memory space. This process is called Mini Compaction. As user data is written, the number of Mini SSTables increases. When the number of Mini SSTables exceeds a certain threshold, the background automatically triggers Minor Compaction. Before a minor compaction, no new data is written to the MemTable to be compacted. This process is called a minor freeze. The minor freeze prevents new data from being written to the current active MemTable and generates a new active MemTable.
SSTable layering strategy
OceanBase AI Database introduces an SSTable layering strategy in the implementation of minor compaction, adding an L0 layer on top of the original structure.
L0 layer (Mini SSTable)
A frozen MemTable is directly flushed as a Mini SSTable. Multiple Mini SSTables can coexist within OceanBase AI Database.
L1 layer (Minor SSTable)
In most cases, there is only one Minor SSTable.
A new Minor SSTable is generated at the L1 layer from multiple Mini SSTables in the L0 layer and the original Minor SSTable.
L2 layer (Major SSTable)
Baseline data, generated during major compaction. Typically, there is only one.
The internal implementation principle of the SSTable layering strategy is illustrated below.

Trigger methods of minor compaction
Minor compaction can be triggered automatically or manually.