From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 5EE1E6EC55; Sat, 12 Jun 2021 01:03:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5EE1E6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1623449012; bh=LDEfZda7BMji5LVt9wunecy42gaa69BaqyOVUnI3k8A=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=uvc9OxGuMkoQZ0S83h8PRC+5C0QW+2gJwnFUxkf8OxcUf+n7eR86dJky2ku6bGpsL AjZFsXGqXyjdWufwRNqLGfZG5pCOslBhPxQ6/K6/ytr8Vlp/jLEhJeWWcvpd/Zs7Ud 8MhblMOolVQRtWXbUXnQ/HQrW1/V+rdb+IvWsnBM= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 552AE6F3CB for ; Sat, 12 Jun 2021 00:56:37 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 552AE6F3CB Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lrp8m-0008JK-E8; Sat, 12 Jun 2021 00:56:36 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Fri, 11 Jun 2021 23:56:16 +0200 Message-Id: <255747b5470b3cffc28176ead3f6deab4f6b4580.1623448465.git.v.shpilevoy@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D5B0DA836B685C540E30C2BDD69416C6E46C178CD572CB10182A05F5380850403CA66A75669F742E3DA7CF71937BD990AFFB96248100A0DCCBBAF50B0A99ED9F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F87C043BA75DB4CEEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637340F95D8C375F5048638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D871B5388A33DB9AD8C2E8D40DCD724E23117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCECADA55FE5B58BB7A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FC26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6B1CFA6D474D4A6A4089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C978317387390EF8EF124055037634962608ED X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC44E1F4276B809941968874A2D3FA5089FE6A95F5C9FCC8F9E1173F25BAE05F90B19C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF31C0090ACECF247D699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D342F9EE325F82A28A839BFE05B6C9775CD79E93FA37F4B3F3C54CD92897ECB31491EB9A6E9FB2701711D7E09C32AA3244C2BC6A3281283F33D55203187028C7BC43C6EB905E3A8056BFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojQR1NM653rVHKRehrIoOLGQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638221EF9AC251FFF8847DCCB5030BCDB70313841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 08/13] journal: introduce proper error codes X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Journal used to have only one error code in journal_entry.res: -1. It had at least 2 problems: - There was an assumption that TXN_SIGNATURE_ROLLBACK is the same as journal_entry error = -1; - It wasn't possible to tell if the entry tried to be written and failed, or it didn't try yet. Both looked as -1. The patch introduces a new error code JOURNAL_ENTRY_ERR_UNKNOWN. The IO error now has its own value: JOURNAL_ENTRY_ERR_IO. This helps to ensure that a not finished journal entry or a transaction won't try to obtain a diag error for their result. Part of #6027 --- src/box/journal.c | 1 + src/box/journal.h | 15 ++++++++++++++- src/box/txn.c | 6 ++++-- src/box/txn.h | 13 ++++++++++--- src/box/txn_limbo.c | 5 +++-- src/box/wal.c | 4 ++-- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/box/journal.c b/src/box/journal.c index 0a1e9932a..35c99c1c6 100644 --- a/src/box/journal.c +++ b/src/box/journal.c @@ -45,6 +45,7 @@ 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); } diff --git a/src/box/journal.h b/src/box/journal.h index 01ea60f72..18767176e 100644 --- a/src/box/journal.h +++ b/src/box/journal.h @@ -44,6 +44,19 @@ struct journal_entry; typedef void (*journal_write_async_f)(struct journal_entry *entry); +enum { + /** Entry didn't attempt a journal write. */ + JOURNAL_ENTRY_ERR_UNKNOWN = -1, + /** Tried to be written, but something happened related to IO. */ + JOURNAL_ENTRY_ERR_IO = -2, + /** + * Anchor for the structs built on top of journal entry so as they + * could introduce their own unique errors. Set to a big value in + * advance. + */ + JOURNAL_ENTRY_ERR_MIN = -100, +}; + /** * Convert a result of a journal entry write to an error installed into the * current diag. @@ -108,7 +121,7 @@ journal_entry_create(struct journal_entry *entry, size_t n_rows, entry->complete_data = complete_data; entry->approx_len = approx_len; entry->n_rows = n_rows; - entry->res = -1; + entry->res = JOURNAL_ENTRY_ERR_UNKNOWN; entry->flags = 0; } diff --git a/src/box/txn.c b/src/box/txn.c index 2c889a31a..c9c2e93ff 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -276,7 +276,7 @@ txn_begin(void) txn->psn = 0; txn->rv_psn = 0; txn->status = TXN_INPROGRESS; - txn->signature = TXN_SIGNATURE_ROLLBACK; + txn->signature = TXN_SIGNATURE_UNKNOWN; txn->engine = NULL; txn->engine_tx = NULL; txn->fk_deferred_count = 0; @@ -479,6 +479,7 @@ txn_complete_fail(struct txn *txn) { assert(!txn_has_flag(txn, TXN_IS_DONE)); assert(txn->signature < 0); + assert(txn->signature != TXN_SIGNATURE_UNKNOWN); txn->status = TXN_ABORTED; struct txn_stmt *stmt; stailq_reverse(&txn->stmts); @@ -535,7 +536,8 @@ txn_on_journal_write(struct journal_entry *entry) * txn_limbo has already rolled the tx back, so we just * have to free it. */ - if (txn->signature < TXN_SIGNATURE_ROLLBACK) { + if (txn->signature != TXN_SIGNATURE_UNKNOWN) { + assert(txn->signature < 0); txn_free(txn); return; } diff --git a/src/box/txn.h b/src/box/txn.h index d51761bc9..037865ac6 100644 --- a/src/box/txn.h +++ b/src/box/txn.h @@ -36,6 +36,7 @@ #include "trigger.h" #include "fiber.h" #include "space.h" +#include "journal.h" #if defined(__cplusplus) extern "C" { @@ -103,24 +104,30 @@ enum { enum { /** Signature set for empty transactions. */ TXN_SIGNATURE_NOP = 0, + /** + * Aliases for journal errors to make all signature codes have the same + * prefix. + */ + TXN_SIGNATURE_UNKNOWN = JOURNAL_ENTRY_ERR_UNKNOWN, + TXN_SIGNATURE_IO = JOURNAL_ENTRY_ERR_IO, /** * The default signature value for failed transactions. * Indicates either write failure or any other failure * not caused by synchronous transaction processing. */ - TXN_SIGNATURE_ROLLBACK = -1, + TXN_SIGNATURE_ROLLBACK = JOURNAL_ENTRY_ERR_MIN - 1, /** * A value set for failed synchronous transactions * on master, when not enough acks were collected. */ - TXN_SIGNATURE_QUORUM_TIMEOUT = -2, + TXN_SIGNATURE_QUORUM_TIMEOUT = JOURNAL_ENTRY_ERR_MIN - 2, /** * A value set for failed synchronous transactions * on replica (or any instance during recovery), when a * transaction is rolled back because ROLLBACK message was * read. */ - TXN_SIGNATURE_SYNC_ROLLBACK = -3, + TXN_SIGNATURE_SYNC_ROLLBACK = JOURNAL_ENTRY_ERR_MIN - 3, }; /** diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index b03c71514..51dc2a186 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -79,7 +79,8 @@ txn_limbo_append(struct txn_limbo *limbo, uint32_t id, struct txn *txn) * needs that to be able rollback transactions, whose WAL write is in * progress. */ - assert(txn->signature < 0); + assert(txn->signature == TXN_SIGNATURE_UNKNOWN); + assert(txn->status == TXN_PREPARED); if (limbo->is_in_rollback) { /* * Cascading rollback. It is impossible to commit the @@ -393,7 +394,7 @@ txn_limbo_read_confirm(struct txn_limbo *limbo, int64_t lsn) */ if (e->lsn == -1) break; - } else if (e->txn->signature < 0) { + } else if (e->txn->signature == TXN_SIGNATURE_UNKNOWN) { /* * A transaction might be covered by the CONFIRM even if * it is not written to WAL yet when it is an async diff --git a/src/box/wal.c b/src/box/wal.c index 40382e791..f59cc9113 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -1169,7 +1169,7 @@ done: if (!stailq_empty(&rollback)) { /* Update status of the successfully committed requests. */ stailq_foreach_entry(entry, &rollback, fifo) - entry->res = -1; + entry->res = JOURNAL_ENTRY_ERR_IO; /* Rollback unprocessed requests */ stailq_concat(&wal_msg->rollback, &rollback); wal_begin_rollback(); @@ -1293,7 +1293,7 @@ wal_write_async(struct journal *journal, struct journal_entry *entry) return 0; fail: - entry->res = -1; + assert(entry->res == JOURNAL_ENTRY_ERR_UNKNOWN); return -1; } -- 2.24.3 (Apple Git-128)