From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org
Subject: [Tarantool-patches] [PATCH 1/3] txn: introduce on_wal_write trigger
Date: Sun, 5 Jul 2020 17:20:14 +0200 [thread overview]
Message-ID: <73503c97a1f5c704eb3062dc0ca41f0b10a5ec3d.1593962115.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1593962115.git.v.shpilevoy@tarantool.org>
With synchronous replication a sycn transaction passes 2 stages:
WAL write + commit. These are separate events on the contrary with
async transactions, where WAL write == commit.
The WAL write event is needed on non-leader nodes to be able to
send an ACK to the master.
Part of #5100
---
src/box/txn.c | 29 ++++++++++++++++++++++++++++-
src/box/txn.h | 10 +++++++++-
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/src/box/txn.c b/src/box/txn.c
index 6c333cbed..2fe763c1c 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -422,6 +422,25 @@ txn_run_rollback_triggers(struct txn *txn, struct rlist *triggers)
}
}
+/* A helper function to process on_wal_write triggers. */
+static void
+txn_run_wal_write_triggers(struct txn *txn)
+{
+ /* Is zero during recovery. */
+ assert(txn->signature >= 0);
+ if (trigger_run(&txn->on_wal_write, txn) != 0) {
+ /*
+ * As transaction couldn't handle a trigger error so
+ * there is no option except panic.
+ */
+ diag_log();
+ unreachable();
+ panic("wal_write trigger failed");
+ }
+ /* WAL write happens only once. */
+ trigger_destroy(&txn->on_wal_write);
+}
+
/**
* Complete transaction processing.
*/
@@ -446,8 +465,14 @@ txn_complete(struct txn *txn)
/* Commit the transaction. */
if (txn->engine != NULL)
engine_commit(txn->engine, txn);
- if (txn_has_flag(txn, TXN_HAS_TRIGGERS))
+ if (txn_has_flag(txn, TXN_HAS_TRIGGERS)) {
txn_run_commit_triggers(txn, &txn->on_commit);
+ /*
+ * For async transactions WAL write ==
+ * commit.
+ */
+ txn_run_wal_write_triggers(txn);
+ }
double stop_tm = ev_monotonic_now(loop());
if (stop_tm - txn->start_tm > too_long_threshold) {
@@ -458,6 +483,8 @@ txn_complete(struct txn *txn)
stop_tm - txn->start_tm);
}
} else {
+ if (txn_has_flag(txn, TXN_HAS_TRIGGERS))
+ txn_run_wal_write_triggers(txn);
/*
* Complete is called on every WAL operation
* authored by this transaction. And it not always
diff --git a/src/box/txn.h b/src/box/txn.h
index f88c3815e..c1f06dbdc 100644
--- a/src/box/txn.h
+++ b/src/box/txn.h
@@ -259,7 +259,7 @@ struct txn {
*/
struct trigger fiber_on_stop;
/** Commit and rollback triggers. */
- struct rlist on_commit, on_rollback;
+ struct rlist on_commit, on_rollback, on_wal_write;
/**
* This member represents counter of deferred foreign key
* violations within transaction. DEFERRED mode means
@@ -370,6 +370,7 @@ txn_init_triggers(struct txn *txn)
if (!txn_has_flag(txn, TXN_HAS_TRIGGERS)) {
rlist_create(&txn->on_commit);
rlist_create(&txn->on_rollback);
+ rlist_create(&txn->on_wal_write);
txn_set_flag(txn, TXN_HAS_TRIGGERS);
}
}
@@ -388,6 +389,13 @@ txn_on_rollback(struct txn *txn, struct trigger *trigger)
trigger_add(&txn->on_rollback, trigger);
}
+static inline void
+txn_on_wal_write(struct txn *txn, struct trigger *trigger)
+{
+ txn_init_triggers(txn);
+ trigger_add(&txn->on_wal_write, trigger);
+}
+
/**
* Most statements don't have triggers, and txn objects
* are created on every access to data, so statements
--
2.21.1 (Apple Git-122.3)
next prev parent reply other threads:[~2020-07-05 15:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-05 15:20 [Tarantool-patches] [PATCH 0/3] Another applier ACKs rework Vladislav Shpilevoy
2020-07-05 15:20 ` Vladislav Shpilevoy [this message]
2020-07-05 15:20 ` [Tarantool-patches] [PATCH 2/3] applier: don't miss WAL writes happened during ACK send Vladislav Shpilevoy
2020-07-05 15:20 ` [Tarantool-patches] [PATCH 3/3] applier: use WAL write event instead of commit for ACK Vladislav Shpilevoy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=73503c97a1f5c704eb3062dc0ca41f0b10a5ec3d.1593962115.git.v.shpilevoy@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=sergepetrenko@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH 1/3] txn: introduce on_wal_write trigger' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox