# Rocksdb Column Families


![left](./student-guide/diagram/03-RocksDB-Column-Families-01-01.png)
------------------------------------------------------------
The basic architecture and reading and writing 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 know about it.

Support for the Column Families feature began with RocksDB 3.0, where each key-value pair (key - value) of RocksDB corresponds to a unique column family (Column Family). If you do not specify a column family (Column Family), the key-value pair will correspond to the "default" column family (Column Family), which is also the default column family (Column Family) of the RocksDB instance.

Column Family (Column Family) provides a way to logically partition a database. Some of its features include:
- Supports cross-column atomic writing. Meaning that you can perform Write ({cf1, key1, value1}, {cf2, key2, value2}) atomically.
- Consistent view across column families.
- Allows different configurations for different column family.
- Instantly add/remove column family, both operations are very fast.

Another thing we need to note is that the main implement idea of Column Families is that they share a WAL log, but not MemTable and Table files. By sharing the WAL file, atomic writing is implemented. Passing quarantine 

MemTable and Table files, we can configure each column family (Column Family) independently and delete them quickly.

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

So far, we have covered 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 own MemTable and Table files, but all column family share a WAL log. This is actually a shard of the RocksDB instance.












