[Tarantool-patches] [PATCH 10/13] txn: install proper diag errors on txn fail

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sat Jun 12 00:56:06 MSK 2021


Previously all journal and txn errors were turned into ER_WAL_IO
error code. It led to loss of the real error, which sometimes was
absolutely not related to IO. For example, a timeout in the limbo
for a synchronous transaction.

The patch makes journal/txn errors turn into proper diags.

Part of #6027
---
 src/box/errcode.h     |  1 +
 src/box/journal.c     | 10 +++++++---
 src/box/txn.c         | 17 ++++++++++++++++-
 test/box/error.result |  1 +
 4 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/box/errcode.h b/src/box/errcode.h
index b143e91d9..49aec4bf6 100644
--- a/src/box/errcode.h
+++ b/src/box/errcode.h
@@ -277,6 +277,7 @@ struct errcode_record {
 	/*222 */_(ER_QUORUM_WAIT,		"Couldn't wait for quorum %d: %s") \
 	/*223 */_(ER_INTERFERING_PROMOTE,	"Instance with replica id %u was promoted first") \
 	/*224 */_(ER_RAFT_DISABLED,		"Elections were turned off while running box.ctl.promote()")\
+	/*225 */_(ER_TXN_ROLLBACK,		"Transaction was rolled back") \
 
 /*
  * !IMPORTANT! Please follow instructions at start of the file
diff --git a/src/box/journal.c b/src/box/journal.c
index 35c99c1c6..32c3e4bd7 100644
--- a/src/box/journal.c
+++ b/src/box/journal.c
@@ -45,9 +45,13 @@ struct journal_queue journal_queue = {
 void
 diag_set_journal_res_detailed(const char *file, unsigned line, int64_t res)
 {
-	assert(res < 0 && res != JOURNAL_ENTRY_ERR_UNKNOWN);
-	(void)res;
-	diag_set_detailed(file, line, ClientError, ER_WAL_IO);
+	switch(res) {
+	case JOURNAL_ENTRY_ERR_IO:
+		diag_set_detailed(file, line, ClientError, ER_WAL_IO);
+		return;
+	}
+	panic("Journal result code %lld can't be converted to an error "
+	      "at %s:%u", (long long)res, file, line);
 }
 
 struct journal_entry *
diff --git a/src/box/txn.c b/src/box/txn.c
index 1c1eb15bc..b3819b8f9 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -251,7 +251,22 @@ txn_free(struct txn *txn)
 void
 diag_set_txn_sign_detailed(const char *file, unsigned line, int64_t signature)
 {
-	return diag_set_journal_res_detailed(file, line, signature);
+	if (signature >= JOURNAL_ENTRY_ERR_MIN)
+		return diag_set_journal_res_detailed(file, line, signature);
+	switch(signature) {
+	case TXN_SIGNATURE_ROLLBACK:
+		diag_set_detailed(file, line, ClientError, ER_TXN_ROLLBACK);
+		return;
+	case TXN_SIGNATURE_QUORUM_TIMEOUT:
+		diag_set_detailed(file, line, ClientError,
+				  ER_SYNC_QUORUM_TIMEOUT);
+		return;
+	case TXN_SIGNATURE_SYNC_ROLLBACK:
+		diag_set_detailed(file, line, ClientError, ER_SYNC_ROLLBACK);
+		return;
+	}
+	panic("Transaction signature %lld can't be converted to an error "
+	      "at %s:%u", (long long)signature, file, line);
 }
 
 struct txn *
diff --git a/test/box/error.result b/test/box/error.result
index 6ef099153..062a90399 100644
--- a/test/box/error.result
+++ b/test/box/error.result
@@ -443,6 +443,7 @@ t;
  |   222: box.error.QUORUM_WAIT
  |   223: box.error.INTERFERING_PROMOTE
  |   224: box.error.RAFT_DISABLED
+ |   225: box.error.TXN_ROLLBACK
  | ...
 
 test_run:cmd("setopt delimiter ''");
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list