[Tarantool-patches] [PATCH 06/13] wal: encapsulate ER_WAL_IO
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Sat Jun 12 00:56:14 MSK 2021
ER_WAL_IO is set on any WAL error if it was after journal_write()
success. It is not correct, because there can be plenty of
reasons.
In WAL it could be an actual IO error or a cascading rollback in
progress. When used for transactions, it could be an error related
to synchronous transactions like a timeout, or a persistent
ROLLBACK.
These errors are overridden by ER_WAL_IO. The patch encapsulates
the diag installation for bad journal write and for transaction
rollback.
The next patches are going to introduce more error codes and use
proper ones to install a diag.
Part of #6027
---
src/box/applier.cc | 10 +++++-----
src/box/journal.c | 8 ++++++++
src/box/journal.h | 10 ++++++++++
src/box/raft.c | 2 +-
src/box/txn.c | 8 +++++++-
src/box/txn.h | 10 ++++++++++
src/box/txn_limbo.c | 2 +-
7 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/src/box/applier.cc b/src/box/applier.cc
index 60d648795..3fd71393d 100644
--- a/src/box/applier.cc
+++ b/src/box/applier.cc
@@ -711,7 +711,7 @@ applier_read_tx(struct applier *applier, struct stailq *rows, double timeout)
}
static void
-applier_rollback_by_wal_io(void)
+applier_rollback_by_wal_io(int64_t signature)
{
/*
* Setup shared applier diagnostic area.
@@ -725,7 +725,7 @@ applier_rollback_by_wal_io(void)
* rollback may happen a way later after it was passed to
* the journal engine.
*/
- diag_set(ClientError, ER_WAL_IO);
+ diag_set_txn_sign(signature);
diag_set_error(&replicaset.applier.diag,
diag_last_error(diag_get()));
@@ -747,7 +747,7 @@ applier_txn_rollback_cb(struct trigger *trigger, void *event)
* special handling.
*/
if (txn->signature != TXN_SIGNATURE_SYNC_ROLLBACK)
- applier_rollback_by_wal_io();
+ applier_rollback_by_wal_io(txn->signature);
return 0;
}
@@ -787,7 +787,7 @@ apply_synchro_row_cb(struct journal_entry *entry)
struct synchro_entry *synchro_entry =
(struct synchro_entry *)entry->complete_data;
if (entry->res < 0) {
- applier_rollback_by_wal_io();
+ applier_rollback_by_wal_io(entry->res);
} else {
txn_limbo_process(&txn_limbo, synchro_entry->req);
trigger_run(&replicaset.applier.on_wal_write, NULL);
@@ -838,7 +838,7 @@ apply_synchro_row(struct xrow_header *row)
if (journal_write(&entry.base) != 0)
goto err;
if (entry.base.res < 0) {
- diag_set(ClientError, ER_WAL_IO);
+ diag_set_journal_res(entry.base.res);
goto err;
}
return 0;
diff --git a/src/box/journal.c b/src/box/journal.c
index df491610a..0a1e9932a 100644
--- a/src/box/journal.c
+++ b/src/box/journal.c
@@ -31,6 +31,7 @@
#include "journal.h"
#include <small/region.h>
#include <diag.h>
+#include "error.h"
struct journal *current_journal = NULL;
@@ -41,6 +42,13 @@ struct journal_queue journal_queue = {
.waiter_count = 0,
};
+void
+diag_set_journal_res_detailed(const char *file, unsigned line, int64_t res)
+{
+ (void)res;
+ diag_set_detailed(file, line, ClientError, ER_WAL_IO);
+}
+
struct journal_entry *
journal_entry_new(size_t n_rows, struct region *region,
journal_write_async_f write_async_cb,
diff --git a/src/box/journal.h b/src/box/journal.h
index 4ab7e8afb..01ea60f72 100644
--- a/src/box/journal.h
+++ b/src/box/journal.h
@@ -44,6 +44,16 @@ struct journal_entry;
typedef void (*journal_write_async_f)(struct journal_entry *entry);
+/**
+ * Convert a result of a journal entry write to an error installed into the
+ * current diag.
+ */
+void
+diag_set_journal_res_detailed(const char *file, unsigned line, int64_t res);
+
+#define diag_set_journal_res(res) \
+ diag_set_journal_res_detailed(__FILE__, __LINE__, res)
+
/**
* An entry for an abstract journal.
* Simply put, a write ahead log request.
diff --git a/src/box/raft.c b/src/box/raft.c
index 55dee4cb1..7f787c0c5 100644
--- a/src/box/raft.c
+++ b/src/box/raft.c
@@ -312,7 +312,7 @@ box_raft_write(struct raft *raft, const struct raft_msg *msg)
if (is_err)
goto fail;
if (entry->res < 0) {
- diag_set(ClientError, ER_WAL_IO);
+ diag_set_journal_res(entry->res);
goto fail;
}
diff --git a/src/box/txn.c b/src/box/txn.c
index 761630939..ac11127d3 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -248,6 +248,12 @@ txn_free(struct txn *txn)
stailq_add(&txn_cache, &txn->in_txn_cache);
}
+void
+diag_set_txn_sign_detailed(const char *file, unsigned line, int64_t signature)
+{
+ return diag_set_journal_res_detailed(file, line, signature);
+}
+
struct txn *
txn_begin(void)
{
@@ -906,7 +912,7 @@ txn_commit(struct txn *txn)
if (journal_write(req) != 0)
goto rollback_io;
if (req->res < 0) {
- diag_set(ClientError, ER_WAL_IO);
+ diag_set_journal_res(req->res);
goto rollback_io;
}
if (txn_has_flag(txn, TXN_WAIT_SYNC)) {
diff --git a/src/box/txn.h b/src/box/txn.h
index a06aaea23..d51761bc9 100644
--- a/src/box/txn.h
+++ b/src/box/txn.h
@@ -123,6 +123,16 @@ enum {
TXN_SIGNATURE_SYNC_ROLLBACK = -3,
};
+/**
+ * Convert a result of a transaction execution to an error installed into the
+ * current diag.
+ */
+void
+diag_set_txn_sign_detailed(const char *file, unsigned line, int64_t signature);
+
+#define diag_set_txn_sign(signature) \
+ diag_set_txn_sign_detailed(__FILE__, __LINE__, signature)
+
/**
* Status of a transaction.
*/
diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c
index 83b86387c..b03c71514 100644
--- a/src/box/txn_limbo.c
+++ b/src/box/txn_limbo.c
@@ -338,7 +338,7 @@ txn_limbo_write_synchro(struct txn_limbo *limbo, uint16_t type, int64_t lsn,
if (journal_write(entry) != 0)
goto fail;
if (entry->res < 0) {
- diag_set(ClientError, ER_WAL_IO);
+ diag_set_journal_res(entry->res);
goto fail;
}
return;
--
2.24.3 (Apple Git-128)
More information about the Tarantool-patches
mailing list