Skip to content

txn: remove the schema check and safe window related utilities after MDL is introduced #39196

@cfzjywxk

Description

@cfzjywxk

Enhancement

The schema checker and safe window are used to ensure the related schema version would not be changed in a transaction lifecycle. After the meta data lock mechanism is introduced in TiDB, it's guaranteed by the DDL module by default, so it's unnecessary to do extra schema checks. After removing these checks:

  1. The backfill job is no longer blocked by the safe window, and the DDL statement executes faster.
  2. The async commit/1pc transactions are no longer constrained by a max_commit_ts related to the safe window interval.
  3. The schema lease checker could be removed from the kv client.

Previously when a transaction is being committed, it would check the schema versions of related tables, the commit would fail if there were any version changes. Besides, this checking requires a current valid schema version and the check would fail if the version has uncertainties.

Safety:

  1. For 2PC transactions, the commit statement finishes after the primary key is committed, so it's safe to remove the schema checker directly.
  2. For async commit/1PC transactions, the prewrite phase must be finished after the commit statement finishes and there must be a prewrite lock on the corresponding keys, the transaction state must be committed which is ensured by the committing protocol. The related table schema version could not be pushed forward as any DDL operations requiring data reorganization would conflict with the existing prewrite lock, so the commit is still safe. For DDL operations that do not require data reorganization, it's always safe to commit using older schema versions.

Note after removing these checks, the new checking logic is relaxed a lot compared with the previous utilities, it's better to review the test cases and there could be behavior and test result changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/enhancementThe issue or PR belongs to an enhancement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions