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 EB1526EC59; Thu, 4 Feb 2021 14:19:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EB1526EC59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612437559; bh=+nNSn2847tbcXDWq3gL8ti7DA2BWkExqckn3LrRwVU0=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=tjRyh8Twd+9N9XLBcQducAHBuE3pYt5+QFg6L7qom29o3FK+YpqcmFWY2gSrxYtYy kEoqLmwgILzZAR93pI96NCx3ep4dYUdRiY7ZvWXIYlQ59F206b7fZqzZrj6UlcqkS0 dQg/bJi73Obp+6ZCuKq+B6cU6kUSO0PJHgt7jDgg= Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DFD8B6EC59 for ; Thu, 4 Feb 2021 14:19:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DFD8B6EC59 Received: by mail-lj1-f177.google.com with SMTP id l12so2949724ljc.3 for ; Thu, 04 Feb 2021 03:19:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e5lk5BeLPZQzsZOSdaf2EO+aF20H1jGZgYTOLlgNm7E=; b=PCtFzeY8kWZnxEi+7j+iL18vg7bC0nhPD1uZ4Co6psuTK6e+zXmuQLe4OvPE2wPpgy lwr5OTejZz7eOwsVkjV1Qs2dAyjOeJWaOt8aXKO9dtCPVmpX5diB+rqI/cCI29nZmIuv 1d31lVafK/WGTzRuBw01+dCIPeksD0XFLIukRfclO/Dzpr2zX0LAT2r/hxhPpQDXWQT6 zkxlRJ48a0LyoAQr4hRJXqnYeGjF3wDj1xOj8DU1eEUK5tS51vtZSmibWh/tDYzdENPH AYEGJPreDoG3QwqEKKgdWUQhddFecBNuSbBERCxbE3pW0odYJYPwq3vuNNc/38hYoHZ6 Mm5g== X-Gm-Message-State: AOAM530HxueQZDgR7qnXq8Bx66CTXgMqX3fXkz8ZuAK2wk6V1Z3xbvoC KyEHBmWVgO7D+FrcQcGnHd3U9xyBy8k= X-Google-Smtp-Source: ABdhPJwND7pds8oTYXg4slACvDkupIwZFSdhFJq8VJEoE1htwioL6dryeif2Nty2Nx4iCWzm4pLrqA== X-Received: by 2002:a2e:8005:: with SMTP id j5mr4545089ljg.34.1612437555664; Thu, 04 Feb 2021 03:19:15 -0800 (PST) Received: from grain.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id 84sm566847lfd.131.2021.02.04.03.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 03:19:14 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 9EA4D560087; Thu, 4 Feb 2021 14:19:13 +0300 (MSK) To: tml Date: Thu, 4 Feb 2021 14:19:12 +0300 Message-Id: <20210204111912.496547-1-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v3] txn: convert flags to explicit bitfield 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: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Instead of shifting flags inside txn_x_flag() helpers lets define precompiled value. This allows us to operate with several flags at onces and shrink code a bit. Closes #5128 Signed-off-by: Cyrill Gorcunov --- issue https://github.com/tarantool/tarantool/issues/5128 branch gorcunov/gh-5128-txn-flags-3 src/box/txn.c | 3 +-- src/box/txn.h | 26 +++++++++++++------------- src/box/txn_limbo.c | 9 +++------ test/unit/snap_quorum_delay.cc | 3 +-- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/box/txn.c b/src/box/txn.c index a5edbfc60..150280905 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -642,8 +642,7 @@ txn_journal_entry_new(struct txn *txn) */ if (!txn_has_flag(txn, TXN_FORCE_ASYNC)) { if (is_sync) { - txn_set_flag(txn, TXN_WAIT_SYNC); - txn_set_flag(txn, TXN_WAIT_ACK); + txn_set_flag(txn, TXN_WAIT_SYNC | TXN_WAIT_ACK); } else if (!txn_limbo_is_empty(&txn_limbo)) { /* * There some sync entries on the diff --git a/src/box/txn.h b/src/box/txn.h index fca9bc1d0..b42249b17 100644 --- a/src/box/txn.h +++ b/src/box/txn.h @@ -56,25 +56,25 @@ struct Vdbe; enum txn_flag { /** Transaction has been processed. */ - TXN_IS_DONE, + TXN_IS_DONE = 0x1, /** * Transaction has been aborted by fiber yield so * should be rolled back at commit. */ - TXN_IS_ABORTED_BY_YIELD, + TXN_IS_ABORTED_BY_YIELD = 0x2, /** * fiber_yield() is allowed inside the transaction. * See txn_can_yield() for more details. */ - TXN_CAN_YIELD, + TXN_CAN_YIELD = 0x4, /** on_commit and/or on_rollback list is not empty. */ - TXN_HAS_TRIGGERS, + TXN_HAS_TRIGGERS = 0x8, /** * Synchronous transaction touched sync spaces, or an * asynchronous transaction blocked by a sync one until it * is confirmed. */ - TXN_WAIT_SYNC, + TXN_WAIT_SYNC = 0x10, /** * Synchronous transaction 'waiting for ACKs' state before * commit. In this state it waits until it is replicated @@ -82,14 +82,14 @@ enum txn_flag { * commit and returns success to a user. * TXN_WAIT_SYNC is always set, if TXN_WAIT_ACK is set. */ - TXN_WAIT_ACK, + TXN_WAIT_ACK = 0x20, /** * A transaction may be forced to be asynchronous, not * wait for any ACKs, and not depend on prepending sync * transactions. This happens in a few special cases. For * example, when applier receives snapshot from master. */ - TXN_FORCE_ASYNC, + TXN_FORCE_ASYNC = 0x40, }; enum { @@ -394,21 +394,21 @@ struct txn { }; static inline bool -txn_has_flag(struct txn *txn, enum txn_flag flag) +txn_has_flag(struct txn *txn, unsigned int flag) { - return (txn->flags & (1 << flag)) != 0; + return (txn->flags & flag) != 0; } static inline void -txn_set_flag(struct txn *txn, enum txn_flag flag) +txn_set_flag(struct txn *txn, unsigned int flag) { - txn->flags |= 1 << flag; + txn->flags |= flag; } static inline void -txn_clear_flag(struct txn *txn, enum txn_flag flag) +txn_clear_flag(struct txn *txn, unsigned int flag) { - txn->flags &= ~(1 << flag); + txn->flags &= ~flag; } /* Pointer to the current transaction (if any) */ diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index 9c4c3cdf1..1bf292670 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -266,8 +266,7 @@ txn_limbo_wait_complete(struct txn_limbo *limbo, struct txn_limbo_entry *entry) in_queue, tmp) { e->txn->signature = TXN_SIGNATURE_QUORUM_TIMEOUT; txn_limbo_abort(limbo, e); - txn_clear_flag(e->txn, TXN_WAIT_SYNC); - txn_clear_flag(e->txn, TXN_WAIT_ACK); + txn_clear_flag(e->txn, TXN_WAIT_SYNC | TXN_WAIT_ACK); txn_complete_fail(e->txn); if (e == entry) break; @@ -399,8 +398,7 @@ txn_limbo_read_confirm(struct txn_limbo *limbo, int64_t lsn) } e->is_commit = true; txn_limbo_remove(limbo, e); - txn_clear_flag(e->txn, TXN_WAIT_SYNC); - txn_clear_flag(e->txn, TXN_WAIT_ACK); + txn_clear_flag(e->txn, TXN_WAIT_SYNC | TXN_WAIT_ACK); /* * If already written to WAL by now, finish tx processing. * Otherwise just clear the sync flags. Tx procesing will finish @@ -456,8 +454,7 @@ txn_limbo_read_rollback(struct txn_limbo *limbo, int64_t lsn) return; rlist_foreach_entry_safe_reverse(e, &limbo->queue, in_queue, tmp) { txn_limbo_abort(limbo, e); - txn_clear_flag(e->txn, TXN_WAIT_SYNC); - txn_clear_flag(e->txn, TXN_WAIT_ACK); + txn_clear_flag(e->txn, TXN_WAIT_SYNC | TXN_WAIT_ACK); if (e->txn->signature >= 0) { /* Rollback the transaction. */ e->txn->signature = TXN_SIGNATURE_SYNC_ROLLBACK; diff --git a/test/unit/snap_quorum_delay.cc b/test/unit/snap_quorum_delay.cc index b9d4cc6c4..e618b1cc4 100644 --- a/test/unit/snap_quorum_delay.cc +++ b/test/unit/snap_quorum_delay.cc @@ -98,8 +98,7 @@ txn_process_func(va_list ap) struct txn *txn = txn_begin(); txn->fiber = fiber(); /* Simulate a sync transaction. */ - txn_set_flag(txn, TXN_WAIT_SYNC); - txn_set_flag(txn, TXN_WAIT_ACK); + txn_set_flag(txn, TXN_WAIT_SYNC | TXN_WAIT_ACK); /* * The true way to push the transaction to limbo is to call * txn_commit() for sync transaction. But, if txn_commit() -- 2.29.2