pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.36k stars 5.85k forks source link

inject table metas as kv instead of DDL for testkit boostrap #56727

Open lcwangchao opened 1 month ago

lcwangchao commented 1 month ago

Enhancement

Many unit tests are using testkit.CreateMockStore or testkit.CreateMockStoreAndDomain to create a new mock TiDB cluster for the following cases. The above methods wrap up the bootstrap procedure that creates all the system tables using DDL. Normally, DDL operations will dispatch the job to the owner and then await the owner's response. Together with other mechanisms such as MDL or infoschema syncing , it is much slower than just writing key/values to the KV layer. A natural thought is that writing the meta to the KV layer directly without the complex DDL process may accelerate the tests. We have reasons why DDL is not necessary when bootstrapping:

  1. There is no user traffic when bootstrapping. We do not need online DDL to achieve async schema change.
  2. There are only simple operations in bootstrap, such as CREATE TABLE/VIEW/DATABASE which only write meta without the reorg phase.
  3. After refactoring, we can use a standalone metabuild.Context to build all the tables' meta without the help of a real session.
lance6716 commented 1 month ago

Can you explain more about the purpose?

lcwangchao commented 1 month ago

I opened this PR

Can you explain more about the purpose?

Added some explanations. However, PR #56728 only tests how much we can accelerate the unit test.

lance6716 commented 1 month ago

I also found https://github.com/pingcap/tidb/issues/42434 but it's reverted somehow.