# The Principle of TiDB Lightning

__*The Lightning Principle*__
__*Lightning architecture*__

![left](./student-guide/diagram/TiDBLightningPI4_en_001_20220617.png)
-------------------------------------------------------------
When an engine file has finished writing data, tidb-lightning starts splitting and scheduling the target TiKV cluster data, and then imports the data into the TiKV cluster.

There are two types of engine files: the `data engine` and the `index engine`, each corresponding to two key-value pairs: row data and secondary indexes. Normally row data is completely sorted the data source, while secondary indexes are unordered. Therefore, `data engine` files are uploaded as soon as the corresponding block is written, while all `index engine` files are imported only after all blocks of the entire table have been encoded.