[Tarantool-patches] [PATCH 04/13] wal: refactor wal_write_to_disk()
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Sat Jun 12 00:56:12 MSK 2021
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
---
src/box/wal.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/src/box/wal.c b/src/box/wal.c
index 25edbace6..40382e791 100644
--- a/src/box/wal.c
+++ b/src/box/wal.c
@@ -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,10 @@ 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;
+ assert(!stailq_empty(&wal_msg->commit));
/*
* Track all vclock changes made by this batch into
@@ -1058,23 +1059,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 +1099,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) +
--
2.24.3 (Apple Git-128)
More information about the Tarantool-patches
mailing list