From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH v3 4/5] wal: add event_mask to wal_watcher
Date: Wed, 24 Oct 2018 16:43:16 +0300 [thread overview]
Message-ID: <9cae1b27408a1ffc94ee3fd884bad2633e90e7c3.1540388352.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1540388352.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1540388352.git.vdavydov.dev@gmail.com>
In order to implement WAL auto-deletion, we need a notification channel
through which the WAL thread could notify TX that a WAL file was deleted
so that the latter can shoot off stale replicas. We will reuse existing
wal_watcher API for this. Currently, wal_watcher invokes the registered
callback on each WAL write so using it as is would be inefficient. To
avoid that, let's allow the caller to specify events of interest when
registering a wal_watcher.
Needed for #3397
---
src/box/relay.cc | 5 ++++-
src/box/wal.c | 10 +++++++++-
src/box/wal.h | 9 ++++++++-
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/box/relay.cc b/src/box/relay.cc
index 2a4cb412..0034f99a 100644
--- a/src/box/relay.cc
+++ b/src/box/relay.cc
@@ -408,6 +408,8 @@ relay_schedule_pending_gc(struct relay *relay, const struct vclock *vclock)
static void
relay_process_wal_event(struct wal_watcher_msg *msg)
{
+ assert((msg->events & (WAL_EVENT_WRITE | WAL_EVENT_ROTATE)) != 0);
+
struct relay *relay = container_of(msg->watcher, struct relay,
wal_watcher);
if (relay->state != RELAY_FOLLOW) {
@@ -505,7 +507,8 @@ relay_subscribe_f(va_list ap)
};
trigger_add(&r->on_close_log, &on_close_log);
wal_set_watcher(&relay->wal_watcher, cord_name(cord()),
- relay_process_wal_event, cbus_process);
+ relay_process_wal_event, cbus_process,
+ WAL_EVENT_WRITE | WAL_EVENT_ROTATE);
relay_set_cord_name(relay->io.fd);
diff --git a/src/box/wal.c b/src/box/wal.c
index b239acd4..09927f6f 100644
--- a/src/box/wal.c
+++ b/src/box/wal.c
@@ -1027,6 +1027,12 @@ wal_watcher_notify(struct wal_watcher *watcher, unsigned events)
{
assert(!rlist_empty(&watcher->next));
+ events &= watcher->event_mask;
+ if (events == 0) {
+ /* The watcher isn't interested in this event. */
+ return;
+ }
+
if (watcher->msg.cmsg.route != NULL) {
/*
* If the notification message is still en route,
@@ -1100,7 +1106,8 @@ wal_watcher_detach(void *arg)
void
wal_set_watcher(struct wal_watcher *watcher, const char *name,
void (*watcher_cb)(struct wal_watcher_msg *),
- void (*process_cb)(struct cbus_endpoint *))
+ void (*process_cb)(struct cbus_endpoint *),
+ unsigned event_mask)
{
assert(journal_is_initialized(&wal_writer_singleton.base));
@@ -1110,6 +1117,7 @@ wal_set_watcher(struct wal_watcher *watcher, const char *name,
watcher->msg.events = 0;
watcher->msg.cmsg.route = NULL;
watcher->pending_events = 0;
+ watcher->event_mask = event_mask;
assert(lengthof(watcher->route) == 2);
watcher->route[0] = (struct cmsg_hop)
diff --git a/src/box/wal.h b/src/box/wal.h
index b7edcd43..e8a4299c 100644
--- a/src/box/wal.h
+++ b/src/box/wal.h
@@ -96,6 +96,11 @@ struct wal_watcher {
/** Message sent to notify the watcher. */
struct wal_watcher_msg msg;
/**
+ * Bit mask of WAL events that this watcher is
+ * interested in.
+ */
+ unsigned event_mask;
+ /**
* Bit mask of WAL events that happened while
* the notification message was en route.
* It indicates that the message must be resend
@@ -126,11 +131,13 @@ struct wal_watcher {
* @param process_cb Function called to process cbus messages
* while the watcher is being attached or NULL
* if the cbus loop is running elsewhere.
+ * @param event_mask Bit mask of events the watcher is interested in.
*/
void
wal_set_watcher(struct wal_watcher *watcher, const char *name,
void (*watcher_cb)(struct wal_watcher_msg *),
- void (*process_cb)(struct cbus_endpoint *));
+ void (*process_cb)(struct cbus_endpoint *),
+ unsigned event_mask);
/**
* Unsubscribe from WAL events.
--
2.11.0
next prev parent reply other threads:[~2018-10-24 13:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-24 13:43 [PATCH v3 0/5] Delete old WAL files if running out of disk space Vladimir Davydov
2018-10-24 13:43 ` [PATCH v3 1/5] wal: preallocate disk space before writing rows Vladimir Davydov
2018-10-24 17:08 ` Konstantin Osipov
2018-10-25 9:24 ` Vladimir Davydov
2018-10-24 13:43 ` [PATCH v3 2/5] wal: pass wal_watcher_msg to wal_watcher callback Vladimir Davydov
2018-10-24 13:43 ` [PATCH v3 3/5] wal: rename wal_watcher->events to pending_events Vladimir Davydov
2018-10-24 13:43 ` Vladimir Davydov [this message]
2018-10-24 17:13 ` [PATCH v3 4/5] wal: add event_mask to wal_watcher Konstantin Osipov
2018-10-24 13:43 ` [PATCH v3 5/5] wal: delete old wal files when running out of disk space Vladimir Davydov
2018-10-25 12:55 ` [PATCH v3 0/5] Delete old WAL files if " Vladimir Davydov
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=9cae1b27408a1ffc94ee3fd884bad2633e90e7c3.1540388352.git.vdavydov.dev@gmail.com \
--to=vdavydov.dev@gmail.com \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH v3 4/5] wal: add event_mask to wal_watcher' \
/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