Skip to content
Snippets Groups Projects
Commit 972d909b authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy Committed by Serge Petrenko
Browse files

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

(cherry picked from commit 7d10096c)
parent f4438449
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <small/region.h> #include <small/region.h>
#include <diag.h> #include <diag.h>
#include "error.h" #include "error.h"
#include "xrow.h"
struct journal *current_journal = NULL; struct journal *current_journal = NULL;
...@@ -118,3 +119,21 @@ journal_queue_flush(void) ...@@ -118,3 +119,21 @@ journal_queue_flush(void)
fiber_wakeup(rlist_first_entry(list, struct fiber, state)); fiber_wakeup(rlist_first_entry(list, struct fiber, state));
journal_queue_wait(); 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;
}
...@@ -277,6 +277,10 @@ journal_write(struct journal_entry *entry) ...@@ -277,6 +277,10 @@ journal_write(struct journal_entry *entry)
return current_journal->write(current_journal, 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. * Queue a single entry to the journal in asynchronous way.
* *
......
...@@ -380,25 +380,9 @@ synchro_request_write(const struct synchro_request *req) ...@@ -380,25 +380,9 @@ synchro_request_write(const struct synchro_request *req)
*/ */
char body[XROW_BODY_LEN_MAX]; char body[XROW_BODY_LEN_MAX];
struct xrow_header 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;
xrow_encode_synchro(&row, body, req); xrow_encode_synchro(&row, body, req);
if (journal_write_row(&row) == 0)
journal_entry_create(entry, 1, xrow_approx_len(&row), return;
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:
diag_log(); diag_log();
/* /*
* XXX: the stub is supposed to be removed once it is defined what to do * XXX: the stub is supposed to be removed once it is defined what to do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment