From 04e052d970a9c8c649bbe2d9020dd73f5e9e3e2b Mon Sep 17 00:00:00 2001
From: godzie44 <godzie@yandex.ru>
Date: Thu, 15 Feb 2024 16:11:47 +0300
Subject: [PATCH] fix: Do not abort incoming transaction if MVCC mode is not
 enabled.

Currently, DDL transaction may abort other in-progress
transactions (this behavior added in #8f4be32 - avoid sharing
(ergo phantom reads) metadata object for different
transactions in MVCC mode).
This behavior makes no sense if the MVCC is
disabled (cause these conflicts never happen).

Closes #47

NO_CHANGELOG=internal
NO_DOC=internal
NO_TEST=internal
---
 src/box/memtx_engine.cc         |  4 ++--
 test/engine/errinj_ddl.result   | 13 +++++++------
 test/engine/errinj_ddl.test.lua |  7 ++-----
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/box/memtx_engine.cc b/src/box/memtx_engine.cc
index 24926f5ca7..a818b9d641 100644
--- a/src/box/memtx_engine.cc
+++ b/src/box/memtx_engine.cc
@@ -603,9 +603,9 @@ memtx_engine_prepare(struct engine *engine, struct txn *txn)
 			memtx_tx_history_prepare_stmt(stmt);
 		}
 		memtx_tx_prepare_finalize(txn);
+		if (txn->is_schema_changed)
+			memtx_tx_abort_all_for_ddl(txn);
 	}
-	if (txn->is_schema_changed)
-		memtx_tx_abort_all_for_ddl(txn);
 	return 0;
 }
 
diff --git a/test/engine/errinj_ddl.result b/test/engine/errinj_ddl.result
index 631aa5fc68..f98afc3aec 100644
--- a/test/engine/errinj_ddl.result
+++ b/test/engine/errinj_ddl.result
@@ -444,7 +444,7 @@ errinj.set("ERRINJ_BUILD_INDEX_DELAY", true)
 ch = fiber.channel(1)
 ---
 ...
-_ = fiber.create(function() pcall(s1.create_index, s1, 'sk', {parts = {2, 'unsigned'}}) ch:put(true) end)
+_ = fiber.create(function() s1:create_index('sk', {parts = {2, 'unsigned'}}) ch:put(true) end)
 ---
 ...
 -- Modification of the same space must fail while an index creation
@@ -503,12 +503,13 @@ s1.index.pk:select()
   - [4, 4]
   - [5, 5]
 ...
--- gh-5998: first DDL operation to be committed wins and aborts all other
--- transactions. So index creation should fail.
---
-assert(s1.index.sk == nil)
+s1.index.sk:select()
 ---
-- true
+- - [1, 1]
+  - [2, 2]
+  - [3, 3]
+  - [4, 4]
+  - [5, 5]
 ...
 s1:drop()
 ---
diff --git a/test/engine/errinj_ddl.test.lua b/test/engine/errinj_ddl.test.lua
index dff72aec82..8e65e358c8 100644
--- a/test/engine/errinj_ddl.test.lua
+++ b/test/engine/errinj_ddl.test.lua
@@ -204,7 +204,7 @@ for i = 1, 5 do s2:insert{i, i} end
 
 errinj.set("ERRINJ_BUILD_INDEX_DELAY", true)
 ch = fiber.channel(1)
-_ = fiber.create(function() pcall(s1.create_index, s1, 'sk', {parts = {2, 'unsigned'}}) ch:put(true) end)
+_ = fiber.create(function() s1:create_index('sk', {parts = {2, 'unsigned'}}) ch:put(true) end)
 
 -- Modification of the same space must fail while an index creation
 -- is in progress.
@@ -226,8 +226,5 @@ errinj.set("ERRINJ_BUILD_INDEX_DELAY", false)
 ch:get()
 
 s1.index.pk:select()
--- gh-5998: first DDL operation to be committed wins and aborts all other
--- transactions. So index creation should fail.
---
-assert(s1.index.sk == nil)
+s1.index.sk:select()
 s1:drop()
-- 
GitLab