From d20d71f911cb044489ccb33eea0feb3fa323e97b Mon Sep 17 00:00:00 2001 From: wjHuang Date: Wed, 30 Nov 2022 20:32:01 +0800 Subject: [PATCH] ddl: don't delay for async commit if MDL is enabled (#39446) ref pingcap/tidb#39196 --- ddl/ddl.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ddl/ddl.go b/ddl/ddl.go index 6e6488ca0d..8c4d5235ea 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -1329,6 +1329,12 @@ type RecoverSchemaInfo struct { // It should be called before any DDL that could break data consistency. // This provides a safe window for async commit and 1PC to commit with an old schema. func delayForAsyncCommit() { + if variable.EnableMDL.Load() { + // If metadata lock is enabled. The transaction of DDL must begin after prewrite of the async commit transaction, + // then the commit ts of DDL must be greater than the async commit transaction. In this case, the corresponding schema of the async commit transaction + // is correct. But if metadata lock is disabled, we can't ensure that the corresponding schema of the async commit transaction isn't change. + return + } cfg := config.GetGlobalConfig().TiKVClient.AsyncCommit duration := cfg.SafeWindow + cfg.AllowedClockDrift logutil.BgLogger().Info("sleep before DDL finishes to make async commit and 1PC safe",