Skip to content
Snippets Groups Projects
Commit 348e0245 authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy
Browse files

wal: refactor wal_write_to_disk()

It didn't have a single fail path. That led to some amount of code
duplication, and it complicated future patches where the journal
entries are going to get a proper error reason instead of default
-1 without any details.

The patch is a preparation for #6027 where it is wanted to have
more detailed errors on journal entry/transaction fail instead
of ER_WAL_IO for everything. Sometimes it can override a real
error like a cascade rollback, or a transaction conflict.

Part of #6027
parent 7191a692
No related branches found
No related tags found
No related merge requests found
......@@ -863,10 +863,8 @@ wal_opt_rotate(struct wal_writer *writer)
return 0;
if (xdir_create_xlog(&writer->wal_dir, &writer->current_wal,
&writer->vclock) != 0) {
diag_log();
&writer->vclock) != 0)
return -1;
}
/*
* Keep track of the new WAL vclock. Required for garbage
* collection, see wal_collect_garbage().
......@@ -1038,7 +1036,11 @@ wal_write_to_disk(struct cmsg *msg)
{
struct wal_writer *writer = &wal_writer_singleton;
struct wal_msg *wal_msg = (struct wal_msg *) msg;
struct stailq_entry *last_committed = NULL;
struct journal_entry *entry;
struct error *error;
if (stailq_empty(&wal_msg->commit))
panic("Attempted to write an empty batch to WAL");
/*
* Track all vclock changes made by this batch into
......@@ -1058,23 +1060,17 @@ wal_write_to_disk(struct cmsg *msg)
if (writer->is_in_rollback) {
/* We're rolling back a failed write. */
stailq_concat(&wal_msg->rollback, &wal_msg->commit);
vclock_copy(&wal_msg->vclock, &writer->vclock);
return;
goto done;
}
/* Xlog is only rotated between queue processing */
if (wal_opt_rotate(writer) != 0) {
stailq_concat(&wal_msg->rollback, &wal_msg->commit);
vclock_copy(&wal_msg->vclock, &writer->vclock);
return wal_begin_rollback();
goto done;
}
/* Ensure there's enough disk space before writing anything. */
if (wal_fallocate(writer, wal_msg->approx_len) != 0) {
stailq_concat(&wal_msg->rollback, &wal_msg->commit);
vclock_copy(&wal_msg->vclock, &writer->vclock);
return wal_begin_rollback();
goto done;
}
/*
......@@ -1104,8 +1100,6 @@ wal_write_to_disk(struct cmsg *msg)
* Iterate over requests (transactions)
*/
int rc;
struct journal_entry *entry;
struct stailq_entry *last_committed = NULL;
stailq_foreach_entry(entry, &wal_msg->commit, fifo) {
wal_assign_lsn(&vclock_diff, &writer->vclock, entry);
entry->res = vclock_sum(&vclock_diff) +
......
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