This topic introduces how SSTable is divided into three layers and how compactions are performed in OceanBase Database.
The storage engine of OceanBase Database uses the log-structured merge-tree (LSM-tree) architecture. In this architecture, data is stored in MemTables and SSTables. SSTables are divided into three layers: mini SSTables, minor SSTables, and major SSTables.
A compaction is a two-step process: mini compaction and minor compaction. When the memory usage of a MemTable reaches a specified threshold, data in the MemTable is flushed to the disk as a mini SSTable to release the memory space. This process is called a mini compaction. As new data is written, the number of mini SSTables increases. When the number of mini SSTables exceeds a specified threshold, the system automatically triggers a minor compaction in the background. 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.
Layered strategy for SSTable
OceanBase Database introduces the layered strategy for SSTable in compactions.
L0 layer (mini SSTable)
The frozen MemTable is directly flushed into a mini SSTable. OceanBase Database can have multiple mini SSTables at the same time.
L1 layer (minor SSTable)
Only one minor SSTable exists in most cases.
Multiple mini SSTables in the L0 layer and the original minor SSTable are compacted into a new minor SSTable in the L1 layer.
L2 layer (major SSTable)
The major SSTable comprises baseline data and is generated during a major compaction. Generally, only one major SSTable exists.
The following figure shows how the layered strategy for SSTable works.

Trigger methods
A minor compaction can be automatically triggered or manually initiated.