From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@dev.tarantool.org>
Subject: [Tarantool-patches] [PATCH 02/17] recovery: convert WalSubscription class to structure
Date: Tue, 28 Apr 2020 19:11:22 +0300 [thread overview]
Message-ID: <20200428161137.20536-3-gorcunov@gmail.com> (raw)
In-Reply-To: <20200428161137.20536-1-gorcunov@gmail.com>
The class is not needed here, we are moving from
cpp to c language. This is a first step to make
recovery code fully C compliant.
Part of #3794
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
src/box/recovery.cc | 156 ++++++++++++++++++++++++--------------------
1 file changed, 84 insertions(+), 72 deletions(-)
diff --git a/src/box/recovery.cc b/src/box/recovery.cc
index 1d0e80057..76b771a91 100644
--- a/src/box/recovery.cc
+++ b/src/box/recovery.cc
@@ -375,83 +375,92 @@ recovery_finalize(struct recovery *r)
* file triggers a wakeup. The WAL dir path is set in the
* constructor. XLOG file path is set with set_log_path().
*/
-class WalSubscription {
-public:
- struct fiber *f;
- unsigned events;
- struct ev_stat dir_stat;
- struct ev_stat file_stat;
- char dir_path[PATH_MAX];
- char file_path[PATH_MAX];
-
- static void dir_stat_cb(struct ev_loop *, struct ev_stat *stat, int)
- {
- ((WalSubscription *)stat->data)->wakeup(WAL_EVENT_ROTATE);
- }
-
- static void file_stat_cb(struct ev_loop *, struct ev_stat *stat, int)
- {
- ((WalSubscription *)stat->data)->wakeup(WAL_EVENT_WRITE);
- }
+struct wal_subscr {
+ struct fiber *f;
+ unsigned int events;
+ struct ev_stat dir_stat;
+ struct ev_stat file_stat;
+ char dir_path[PATH_MAX];
+ char file_path[PATH_MAX];
+};
- void wakeup(unsigned events)
- {
- this->events |= events;
- if (f->flags & FIBER_IS_CANCELLABLE)
- fiber_wakeup(f);
- }
+static void
+wal_subscr_wakeup(struct wal_subscr *ws, unsigned int events)
+{
+ ws->events |= events;
+ if (ws->f->flags & FIBER_IS_CANCELLABLE)
+ fiber_wakeup(ws->f);
+}
- WalSubscription(const char *wal_dir)
- {
- f = fiber();
- events = 0;
- if ((size_t)snprintf(dir_path, sizeof(dir_path), "%s", wal_dir) >=
- sizeof(dir_path)) {
+static void
+wal_subscr_dir_stat_cb(struct ev_loop *, struct ev_stat *stat, int)
+{
+ struct wal_subscr *ws = (struct wal_subscr *)stat->data;
+ wal_subscr_wakeup(ws, WAL_EVENT_ROTATE);
+}
- panic("path too long: %s", wal_dir);
- }
+static void
+wal_subscr_file_stat_cb(struct ev_loop *, struct ev_stat *stat, int)
+{
+ struct wal_subscr *ws = (struct wal_subscr *)stat->data;
+ wal_subscr_wakeup(ws, WAL_EVENT_WRITE);
+}
- ev_stat_init(&dir_stat, dir_stat_cb, "", 0.0);
- ev_stat_init(&file_stat, file_stat_cb, "", 0.0);
- dir_stat.data = this;
- file_stat.data = this;
+static void
+wal_subscr_set_log_path(struct wal_subscr *ws, const char *path)
+{
+ size_t len;
- ev_stat_set(&dir_stat, dir_path, 0.0);
- ev_stat_start(loop(), &dir_stat);
+ /*
+ * Avoid toggling ev_stat if the path didn't change.
+ * Note: .file_path valid iff file_stat is active.
+ */
+ if (path && ev_is_active(&ws->file_stat) &&
+ strcmp(ws->file_path, path) == 0) {
+ return;
}
- ~WalSubscription()
- {
- ev_stat_stop(loop(), &file_stat);
- ev_stat_stop(loop(), &dir_stat);
- }
+ ev_stat_stop(loop(), &ws->file_stat);
+ if (path == NULL)
+ return;
- void set_log_path(const char *path)
- {
- /*
- * Avoid toggling ev_stat if the path didn't change.
- * Note: .file_path valid iff file_stat is active.
- */
- if (path && ev_is_active(&file_stat) &&
- strcmp(file_path, path) == 0) {
+ len = snprintf(ws->file_path, sizeof(ws->file_path), "%s", path);
+ if (len >= sizeof(ws->file_path))
+ panic("wal_subscr: log path is too long: %s", path);
- return;
- }
+ ev_stat_set(&ws->file_stat, ws->file_path, 0.0);
+ ev_stat_start(loop(), &ws->file_stat);
+}
- ev_stat_stop(loop(), &file_stat);
+static void
+wal_subscr_create(struct wal_subscr *ws, const char *wal_dir)
+{
+ size_t len;
- if (path == NULL)
- return;
+ memset(ws, 0, sizeof(*ws));
- if ((size_t)snprintf(file_path, sizeof(file_path), "%s", path) >=
- sizeof(file_path)) {
+ ws->f = fiber();
+ ws->events = 0;
- panic("path too long: %s", path);
- }
- ev_stat_set(&file_stat, file_path, 0.0);
- ev_stat_start(loop(), &file_stat);
- }
-};
+ len = snprintf(ws->dir_path, sizeof(ws->dir_path), "%s", wal_dir);
+ if (len >= sizeof(ws->dir_path))
+ panic("wal_subscr: wal dir path is too long: %s", wal_dir);
+
+ ev_stat_init(&ws->dir_stat, wal_subscr_dir_stat_cb, "", 0.0);
+ ev_stat_init(&ws->file_stat, wal_subscr_file_stat_cb, "", 0.0);
+ ws->dir_stat.data = ws;
+ ws->file_stat.data = ws;
+
+ ev_stat_set(&ws->dir_stat, ws->dir_path, 0.0);
+ ev_stat_start(loop(), &ws->dir_stat);
+}
+
+static void
+wal_subscr_destroy(struct wal_subscr *ws)
+{
+ ev_stat_stop(loop(), &ws->file_stat);
+ ev_stat_stop(loop(), &ws->dir_stat);
+}
static int
hot_standby_f(va_list ap)
@@ -463,7 +472,12 @@ hot_standby_f(va_list ap)
ev_tstamp wal_dir_rescan_delay = va_arg(ap, ev_tstamp);
fiber_set_user(fiber(), &admin_credentials);
- WalSubscription subscription(r->wal_dir.dirname);
+ struct wal_subscr ws;
+ auto guard = make_scoped_guard([&]{
+ wal_subscr_destroy(&ws);
+ });
+
+ wal_subscr_create(&ws, r->wal_dir.dirname);
while (! fiber_is_cancelled()) {
@@ -490,11 +504,11 @@ hot_standby_f(va_list ap)
*/
} while (end > start && !xlog_cursor_is_open(&r->cursor));
- subscription.set_log_path(xlog_cursor_is_open(&r->cursor) ?
- r->cursor.name : NULL);
+ wal_subscr_set_log_path(&ws, xlog_cursor_is_open(&r->cursor) ?
+ r->cursor.name : NULL);
bool timed_out = false;
- if (subscription.events == 0) {
+ if (ws.events == 0) {
/**
* Allow an immediate wakeup/break loop
* from recovery_stop_local().
@@ -504,10 +518,8 @@ hot_standby_f(va_list ap)
fiber_set_cancellable(false);
}
- scan_dir = timed_out ||
- (subscription.events & WAL_EVENT_ROTATE) != 0;
-
- subscription.events = 0;
+ scan_dir = timed_out || (ws.events & WAL_EVENT_ROTATE) != 0;
+ ws.events = 0;
}
return 0;
}
--
2.20.1
next prev parent reply other threads:[~2020-04-28 16:12 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-28 16:11 [Tarantool-patches] [PATCH 00/17] recovery: move from cxx to c code Cyrill Gorcunov
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 01/17] recovery: do not call recovery_stop_local inside recovery_delete Cyrill Gorcunov
2020-04-28 16:11 ` Cyrill Gorcunov [this message]
2020-05-03 18:42 ` [Tarantool-patches] [PATCH 02/17] recovery: convert WalSubscription class to structure Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 03/17] recovery: recovery_close_log -- don't throw exception Cyrill Gorcunov
2020-05-03 18:43 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 04/17] recovery: recovery_open_log " Cyrill Gorcunov
2020-05-03 18:43 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 05/17] recovery: recover_xlog " Cyrill Gorcunov
2020-05-03 18:44 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 06/17] recovery: recover_remaining_wals " Cyrill Gorcunov
2020-05-03 18:44 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 07/17] recovery: hot_standby_f " Cyrill Gorcunov
2020-05-03 18:45 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 08/17] recovery: recovery_follow_local " Cyrill Gorcunov
2020-05-03 18:46 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 09/17] recovery: recovery_new " Cyrill Gorcunov
2020-05-03 18:47 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 10/17] recovery: recovery_scan " Cyrill Gorcunov
2020-05-03 18:47 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 11/17] recovery: recovery_finalize " Cyrill Gorcunov
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 12/17] recovery: recovery_stop_local " Cyrill Gorcunov
2020-05-03 18:47 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 13/17] recovery: cxx to c transition Cyrill Gorcunov
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 14/17] recovery: drop redundant type_XlogGapError Cyrill Gorcunov
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 15/17] recovery: provide throwable wrappers Cyrill Gorcunov
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 16/17] box: use _xc helpers of recovery code Cyrill Gorcunov
2020-05-03 18:47 ` Vladislav Shpilevoy
2020-04-28 16:11 ` [Tarantool-patches] [PATCH 17/17] relay: use _xc recovery helpers Cyrill Gorcunov
2020-04-28 16:24 ` [Tarantool-patches] [PATCH 01/17] recovery: do not call recovery_stop_local inside recovery_delete Cyrill Gorcunov
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=20200428161137.20536-3-gorcunov@gmail.com \
--to=gorcunov@gmail.com \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH 02/17] recovery: convert WalSubscription class to structure' \
/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