From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 514974696CA for ; Wed, 19 Feb 2020 21:39:47 +0300 (MSK) Received: by mail-lj1-f193.google.com with SMTP id q8so1465913ljb.2 for ; Wed, 19 Feb 2020 10:39:47 -0800 (PST) From: Cyrill Gorcunov Date: Wed, 19 Feb 2020 21:37:12 +0300 Message-Id: <20200219183713.17646-14-gorcunov@gmail.com> In-Reply-To: <20200219183713.17646-1-gorcunov@gmail.com> References: <20200219183713.17646-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 13/14] box/journal: introduce journal_write List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml To write entries in synchronous way. It uses journal_write_async under the hood together with fiber_wait. Note both journal_write and journal_write_async require current fiber to come in with txn bound to the storage for context unification sake. Signed-off-by: Cyrill Gorcunov --- src/box/journal.c | 24 ++++++++++++++++++++++++ src/box/journal.h | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/src/box/journal.c b/src/box/journal.c index 238860165..d0860e883 100644 --- a/src/box/journal.c +++ b/src/box/journal.c @@ -98,3 +98,27 @@ journal_write_async(struct journal_entry *entry) return ret; } + +int +journal_write(struct journal_entry *entry) +{ + struct txn *txn = in_txn(); + assert(txn != NULL); + + if (journal_write_async(entry)) + return -1; + + /* + * In case of non-yielding journal the transaction could + * already be done and there is nothing to wait in such + * case, otherwise wait for wakeup upon transaction + * is complete. + */ + if (!txn_has_flag(txn, TXN_IS_DONE)) { + bool cancellable = fiber_set_cancellable(false); + fiber_yield(); + fiber_set_cancellable(cancellable); + } + + return txn->signature >= 0 ? 0 : -1; +} diff --git a/src/box/journal.h b/src/box/journal.h index efb6ac8e1..e73d684e5 100644 --- a/src/box/journal.h +++ b/src/box/journal.h @@ -131,6 +131,14 @@ extern struct journal *current_journal; extern int journal_write_async(struct journal_entry *entry); +/** + * Write a single entry to the journal. + * + * @return 0 if write was written or -1 in case of an error. + */ +extern int +journal_write(struct journal_entry *entry); + /** * Change the current implementation of the journaling API. * Happens during life cycle of an instance: -- 2.20.1