From 7d10096cc4ff6e71cb9fba335e4a2dd3b1210fd0 Mon Sep 17 00:00:00 2001
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Date: Mon, 10 Jun 2024 22:11:45 +0200
Subject: [PATCH] journal: extract journal_write_row from limbo

The function writes a single xrow into the journal in a blocking
way. It isn't so simple, so makes sense to keep as a function,
especially given that it will be used more in the next commit.

Part of #10113

NO_DOC=refactoring
NO_TEST=refactoring
NO_CHANGELOG=refactoring
---
 src/box/journal.c   | 19 +++++++++++++++++++
 src/box/journal.h   |  4 ++++
 src/box/txn_limbo.c | 20 ++------------------
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/src/box/journal.c b/src/box/journal.c
index 83d2e7145b..40fe426ae3 100644
--- a/src/box/journal.c
+++ b/src/box/journal.c
@@ -33,6 +33,7 @@
 #include <diag.h>
 #include "error.h"
 #include "watcher.h"
+#include "xrow.h"
 
 struct journal *current_journal = NULL;
 
@@ -123,3 +124,21 @@ journal_queue_flush(void)
 		fiber_wakeup(rlist_first_entry(list, struct fiber, state));
 	journal_queue_wait();
 }
+
+int
+journal_write_row(struct xrow_header *row)
+{
+	char buf[sizeof(struct journal_entry) + sizeof(struct xrow_header *)];
+	struct journal_entry *entry = (struct journal_entry *)buf;
+	entry->rows[0] = row;
+	journal_entry_create(entry, 1, xrow_approx_len(row),
+			     journal_entry_fiber_wakeup_cb, fiber());
+
+	if (journal_write(entry) != 0)
+		return -1;
+	if (entry->res < 0) {
+		diag_set_journal_res(entry->res);
+		return -1;
+	}
+	return 0;
+}
diff --git a/src/box/journal.h b/src/box/journal.h
index 7d3e525f8f..0147083eca 100644
--- a/src/box/journal.h
+++ b/src/box/journal.h
@@ -277,6 +277,10 @@ journal_write(struct journal_entry *entry)
 	return current_journal->write(current_journal, entry);
 }
 
+/** Write a single row in a blocking way. */
+int
+journal_write_row(struct xrow_header *row);
+
 /**
  * Queue a single entry to the journal in asynchronous way.
  *
diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
index dd5aeec1bc..6ea624c273 100644
--- a/src/box/txn_limbo.c
+++ b/src/box/txn_limbo.c
@@ -382,25 +382,9 @@ synchro_request_write(const struct synchro_request *req)
 	 */
 	char body[XROW_BODY_LEN_MAX];
 	struct xrow_header row;
-	char buf[sizeof(struct journal_entry) +
-		 sizeof(struct xrow_header *)];
-
-	struct journal_entry *entry = (struct journal_entry *)buf;
-	entry->rows[0] = &row;
-
 	xrow_encode_synchro(&row, body, req);
-
-	journal_entry_create(entry, 1, xrow_approx_len(&row),
-			     journal_entry_fiber_wakeup_cb, fiber());
-
-	if (journal_write(entry) != 0)
-		goto fail;
-	if (entry->res < 0) {
-		diag_set_journal_res(entry->res);
-		goto fail;
-	}
-	return;
-fail:
+	if (journal_write_row(&row) == 0)
+		return;
 	diag_log();
 	/*
 	 * XXX: the stub is supposed to be removed once it is defined what to do
-- 
GitLab