From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 8425944643C for ; Tue, 8 Sep 2020 13:22:14 +0300 (MSK) Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1kFalS-0006tc-1O for tarantool-patches@dev.tarantool.org; Tue, 08 Sep 2020 13:22:14 +0300 From: Aleksandr Lyapunov Date: Tue, 8 Sep 2020 13:22:04 +0300 Message-Id: <1599560532-27089-5-git-send-email-alyapunov@tarantool.org> In-Reply-To: <1599560532-27089-1-git-send-email-alyapunov@tarantool.org> References: <1599560532-27089-1-git-send-email-alyapunov@tarantool.org> Subject: [Tarantool-patches] [PATCH v4 04/12] txm: introduce prepare sequence number List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Prepare sequence number is a monotonically increasing ID that is assigned to any prepared transaction. This ID is suitable for serialization order resolution: the bigger is ID - the later the transaction exists in the serialization order of transactions. Note that id of transactions has quite different order in case when transaction could yield - an younger (bigger id) transaction can prepare/commit first (lower psn) while older tx sleeps in vain. Also it should be mentioned that LSN has the same order as PSN, but it has two general differences: 1. The LSN sequence has no holes, i.e. it is a natural number sequence. This property is useless for transaction engine. 2. The LSN sequence is provided by WAL writer and thus LSN is not available for TX thas was prepared and haven't been committed yet. That feature makes psn more suitable sequence for transactions as it allows to order prepared but not committed transaction and allows, for example, to create a read view between prepared transactions. Part of #4897 --- src/box/txn.c | 6 ++++++ src/box/txn.h | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/box/txn.c b/src/box/txn.c index d9fbb51..1dfe59f 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -40,6 +40,9 @@ double too_long_threshold; +/** Last prepare-sequence-number that was assigned to prepared TX. */ +int64_t txn_last_psn = 0; + /* Txn cache. */ static struct stailq txn_cache = {NULL, &txn_cache.first}; @@ -225,6 +228,7 @@ txn_begin(void) txn->flags = 0; txn->in_sub_stmt = 0; txn->id = ++tsn; + txn->psn = 0; txn->status = TXN_INPROGRESS; txn->signature = TXN_SIGNATURE_ROLLBACK; txn->engine = NULL; @@ -648,6 +652,8 @@ txn_journal_entry_new(struct txn *txn) static int txn_prepare(struct txn *txn) { + txn->psn = ++txn_last_psn; + if (txn_has_flag(txn, TXN_IS_ABORTED_BY_YIELD)) { assert(!txn_has_flag(txn, TXN_CAN_YIELD)); diag_set(ClientError, ER_TRANSACTION_YIELD); diff --git a/src/box/txn.h b/src/box/txn.h index 007284f..d7e77e5 100644 --- a/src/box/txn.h +++ b/src/box/txn.h @@ -44,6 +44,9 @@ extern "C" { /** box statistics */ extern struct rmean *rmean_box; +/** Last prepare-sequence-number that was assigned to prepared TX. */ +extern int64_t txn_last_psn; + struct journal_entry; struct engine; struct space; @@ -264,6 +267,11 @@ struct txn { * Valid IDs start from 1. */ int64_t id; + /** + * A sequential ID that is assigned when the TX becomes prepared. + * Transactions are committed in that order. + */ + int64_t psn; /** Status of the TX */ enum txn_status status; /** List of statements in a transaction. */ -- 2.7.4