From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v2 02/10] wal: simplify watcher API Date: Sat, 8 Dec 2018 18:48:06 +0300 Message-Id: <7f779b579a827154d130d2072bc86c53ae4ec8a1.1544282224.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: This patch reverts changes done in order to make WAL watcher API suitable for notiying TX about WAL garbage collection triggered on ENOSPC, namely: b073b0176704 wal: add event_mask to wal_watcher 7077341ec5b3 wal: pass wal_watcher_msg to wal_watcher callback We don't need them anymore, because now we piggyback the notification on the WAL request message that triggered ENOSPC. --- src/box/relay.cc | 12 ++++-------- src/box/wal.c | 27 ++++++--------------------- src/box/wal.h | 25 ++++++------------------- 3 files changed, 16 insertions(+), 48 deletions(-) diff --git a/src/box/relay.cc b/src/box/relay.cc index f864d308..a01c2a2e 100644 --- a/src/box/relay.cc +++ b/src/box/relay.cc @@ -406,12 +406,9 @@ relay_schedule_pending_gc(struct relay *relay, const struct vclock *vclock) } static void -relay_process_wal_event(struct wal_watcher_msg *msg) +relay_process_wal_event(struct wal_watcher *watcher, unsigned events) { - assert((msg->events & (WAL_EVENT_WRITE | WAL_EVENT_ROTATE)) != 0); - - struct relay *relay = container_of(msg->watcher, struct relay, - wal_watcher); + struct relay *relay = container_of(watcher, struct relay, wal_watcher); if (relay->state != RELAY_FOLLOW) { /* * Do not try to send anything to the replica @@ -421,7 +418,7 @@ relay_process_wal_event(struct wal_watcher_msg *msg) } try { recover_remaining_wals(relay->r, &relay->stream, NULL, - (msg->events & WAL_EVENT_ROTATE) != 0); + (events & WAL_EVENT_ROTATE) != 0); } catch (Exception *e) { e->log(); diag_move(diag_get(), &relay->diag); @@ -507,8 +504,7 @@ 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, - WAL_EVENT_WRITE | WAL_EVENT_ROTATE); + relay_process_wal_event, cbus_process); relay_set_cord_name(relay->io.fd); diff --git a/src/box/wal.c b/src/box/wal.c index 0775dbae..644f58c8 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -1169,13 +1169,6 @@ wal_watcher_notify(struct wal_watcher *watcher, unsigned events) assert(!rlist_empty(&watcher->next)); struct wal_watcher_msg *msg = &watcher->msg; - - events &= watcher->event_mask; - if (events == 0) { - /* The watcher isn't interested in this event. */ - return; - } - if (msg->cmsg.route != NULL) { /* * If the notification message is still en route, @@ -1195,7 +1188,10 @@ static void wal_watcher_notify_perform(struct cmsg *cmsg) { struct wal_watcher_msg *msg = (struct wal_watcher_msg *) cmsg; - msg->watcher->cb(msg); + struct wal_watcher *watcher = msg->watcher; + unsigned events = msg->events; + + watcher->cb(watcher, events); } static void @@ -1248,9 +1244,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 *), - unsigned event_mask) + void (*watcher_cb)(struct wal_watcher *, unsigned events), + void (*process_cb)(struct cbus_endpoint *)) { assert(journal_is_initialized(&wal_writer_singleton.base)); @@ -1260,7 +1255,6 @@ 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) @@ -1281,15 +1275,6 @@ wal_clear_watcher(struct wal_watcher *watcher, wal_watcher_detach, watcher, process_cb); } -/** - * Notify all interested watchers about a WAL event. - * - * XXX: Note, this function iterates over all registered watchers, - * including those that are not interested in the given event. - * This is OK only as long as the number of events/watchers is - * small. If this ever changes, we should consider maintaining - * a separate watcher list per each event type. - */ static void wal_notify_watchers(struct wal_writer *writer, unsigned events) { diff --git a/src/box/wal.h b/src/box/wal.h index 6e5a5458..3d616353 100644 --- a/src/box/wal.h +++ b/src/box/wal.h @@ -73,15 +73,9 @@ wal_init(enum wal_mode wal_mode, const char *wal_dirname, int64_t wal_max_rows, void wal_thread_stop(); -/** - * A notification message sent from the WAL to a watcher - * when a WAL event occurs. - */ struct wal_watcher_msg { struct cmsg cmsg; - /** Pointer to the watcher this message is for. */ struct wal_watcher *watcher; - /** Bit mask of events, see wal_event. */ unsigned events; }; @@ -96,7 +90,7 @@ struct wal_watcher { /** Link in wal_writer::watchers. */ struct rlist next; /** The watcher callback function. */ - void (*cb)(struct wal_watcher_msg *); + void (*cb)(struct wal_watcher *, unsigned events); /** Pipe from the watcher to WAL. */ struct cpipe wal_pipe; /** Pipe from WAL to the watcher. */ @@ -106,11 +100,6 @@ 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 @@ -135,19 +124,17 @@ struct wal_watcher { * @param watcher WAL watcher to register. * @param name Name of the cbus endpoint at the caller's cord. * @param watcher_cb Callback to invoke from the caller's cord - * upon receiving a WAL event. It takes an object - * of type wal_watcher_msg that stores a pointer - * to the watcher and information about the event. + * upon receiving a WAL event. Apart from the + * watcher itself, it takes a bit mask of events. + * Events are described in wal_event enum. * @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 *), - unsigned event_mask); + void (*watcher_cb)(struct wal_watcher *, unsigned events), + void (*process_cb)(struct cbus_endpoint *)); /** * Unsubscribe from WAL events. -- 2.11.0