# Rocksdb: Column Families
__*Column Families*__
__*Lian*__
__*column cluster*__

![left](./student-guide/diagram/RocksDBColumnFamilies_aa_001_20220511.png)

------------------------------------------------------------
The basic architecture and reads and writes of RocksDB have been introduced above, so we can see that TiKV integrates RocksDB to complete the most basic data persistence. Next, let's introduce another feature of RocksDB, which is Column Families. This feature is related to TiKV's support for transaction later, so we need to understand it.

Support for the Column Families feature started with RocksDB 3.0. Each key value pair (key - value) of RocksDB corresponds to a unique column family (Column Family). If a Column Family is not specified, the key-value pair will correspond to the "default" Column Family (Column Family), which is also the default Column Family of the RocksDB instance.

Column Family (Column Family) provides a way to logically fragment a database. Some of its features include:
- Supports cross-column atom writing. This means you can atomically write ({cf1, key1, value1}, {cf2, key2, value2}).
- Consistent view across column families.
- Allows different configurations for different column family.
- Add/remove column family instantly, both operations are very fast.

Another thing we need to note is that the main implement idea of Column Family is that they share a WAL log, but do not share MemTable and Table files. Atomic writing is achieved by sharing WAL files. By isolating MemTable and Table files, we can configure each Column Family independently and quickly delete them.

Every time a separate Column Family is swiped, we create a new WAL log file. All new writes from all Column Families go to the new WAL log file. However, we can't delete the old WAL yet because he still has some useful data for other column family Families. We can only delete this WAL log file if all column families (Column Family) have flushed the data in this WAL log (log) to ensure that all of your column family will be flushed regularly.

At this point, we have introduced Column Families. We know that a RocksDB instance can have multiple Column Families (Column Families). Each Column Family (Column Family) corresponds to a key-value pair (key - value), and each Column Family (Column Family) has MemTable and Table files of their own, but column family Families (Column Families) share a WAL log. This is actually a shard of a RocksDB instance.












