[Tarantool-patches] [PATCH 13/14] box/journal: introduce journal_write

Cyrill Gorcunov gorcunov at gmail.com
Wed Feb 19 21:37:12 MSK 2020


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 <gorcunov at gmail.com>
---
 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



More information about the Tarantool-patches mailing list