From: Vladimir Davydov <vdavydov.dev@gmail.com> To: kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [PATCH v3 2/5] wal: pass wal_watcher_msg to wal_watcher callback Date: Wed, 24 Oct 2018 16:43:14 +0300 [thread overview] Message-ID: <d926b9dffa28a2480f893b80951c3698c51d68e9.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> This should make it easier to pass some extra information along with the event mask. For example, we will use it to pass the vclock of the oldest stored WAL, which is needed for WAL auto-deletion. Needed for #3397 --- src/box/relay.cc | 7 ++++--- src/box/wal.c | 7 ++----- src/box/wal.h | 16 +++++++++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/box/relay.cc b/src/box/relay.cc index 0a1e95af..2a4cb412 100644 --- a/src/box/relay.cc +++ b/src/box/relay.cc @@ -406,9 +406,10 @@ relay_schedule_pending_gc(struct relay *relay, const struct vclock *vclock) } static void -relay_process_wal_event(struct wal_watcher *watcher, unsigned events) +relay_process_wal_event(struct wal_watcher_msg *msg) { - struct relay *relay = container_of(watcher, struct relay, wal_watcher); + struct relay *relay = container_of(msg->watcher, struct relay, + wal_watcher); if (relay->state != RELAY_FOLLOW) { /* * Do not try to send anything to the replica @@ -418,7 +419,7 @@ relay_process_wal_event(struct wal_watcher *watcher, unsigned events) } try { recover_remaining_wals(relay->r, &relay->stream, NULL, - (events & WAL_EVENT_ROTATE) != 0); + (msg->events & WAL_EVENT_ROTATE) != 0); } catch (Exception *e) { e->log(); diag_move(diag_get(), &relay->diag); diff --git a/src/box/wal.c b/src/box/wal.c index b7acb50e..d231cc98 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -1046,10 +1046,7 @@ static void wal_watcher_notify_perform(struct cmsg *cmsg) { struct wal_watcher_msg *msg = (struct wal_watcher_msg *) cmsg; - struct wal_watcher *watcher = msg->watcher; - unsigned events = msg->events; - - watcher->cb(watcher, events); + msg->watcher->cb(msg); } static void @@ -1102,7 +1099,7 @@ wal_watcher_detach(void *arg) void wal_set_watcher(struct wal_watcher *watcher, const char *name, - void (*watcher_cb)(struct wal_watcher *, unsigned events), + void (*watcher_cb)(struct wal_watcher_msg *), void (*process_cb)(struct cbus_endpoint *)) { assert(journal_is_initialized(&wal_writer_singleton.base)); diff --git a/src/box/wal.h b/src/box/wal.h index 8ef1fb1d..7371ce93 100644 --- a/src/box/wal.h +++ b/src/box/wal.h @@ -63,9 +63,15 @@ wal_init(enum wal_mode wal_mode, const char *wal_dirname, 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; }; @@ -80,7 +86,7 @@ struct wal_watcher { /** Link in wal_writer::watchers. */ struct rlist next; /** The watcher callback function. */ - void (*cb)(struct wal_watcher *, unsigned events); + void (*cb)(struct wal_watcher_msg *); /** Pipe from the watcher to WAL. */ struct cpipe wal_pipe; /** Pipe from WAL to the watcher. */ @@ -114,16 +120,16 @@ 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. Apart from the - * watcher itself, it takes a bit mask of events. - * Events are described in wal_event enum. + * 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. * @param process_cb Function called to process cbus messages * while the watcher is being attached or NULL * if the cbus loop is running elsewhere. */ void wal_set_watcher(struct wal_watcher *watcher, const char *name, - void (*watcher_cb)(struct wal_watcher *, unsigned events), + void (*watcher_cb)(struct wal_watcher_msg *), void (*process_cb)(struct cbus_endpoint *)); /** -- 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 ` Vladimir Davydov [this message] 2018-10-24 13:43 ` [PATCH v3 3/5] wal: rename wal_watcher->events to pending_events Vladimir Davydov 2018-10-24 13:43 ` [PATCH v3 4/5] wal: add event_mask to wal_watcher Vladimir Davydov 2018-10-24 17:13 ` 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=d926b9dffa28a2480f893b80951c3698c51d68e9.1540388352.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH v3 2/5] wal: pass wal_watcher_msg to wal_watcher callback' \ /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