From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v2 04/10] box: don't use box_checkpoint_is_in_progress outside box.cc Date: Sat, 8 Dec 2018 18:48:08 +0300 Message-Id: <9fc9cb3fbc469e505c8253ae8591a1c924d5b54a.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: We only use box_checkpoint_is_in_progress in SIGUSR1 signal handler to print a warning in case checkpointing cannot be started, because it's already done by another fiber. Actually, it's not necessary to use it there - instead we can simply log the error returned by box_checkpoint, which will be self-explaining ER_CHECKPOINT_IN_PROGRESS in this case. So let's make box_checkpoint_is_in_progress private to box.cc - this will simplify moving the checkpoint daemon to the gc module. While we are at it, remove the unused snapshot_version declaration. --- src/box/box.cc | 12 ++++++++---- src/box/box.h | 5 ----- src/main.cc | 21 +++++++++++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 036769a9..d146ec16 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -87,10 +87,14 @@ static void title(const char *new_status) systemd_snotify("STATUS=%s", status); } -bool box_checkpoint_is_in_progress = false; const struct vclock *box_vclock = &replicaset.vclock; /** + * Set if there's a fiber performing box_checkpoint() right now. + */ +static bool checkpoint_is_in_progress; + +/** * Set if backup is in progress, i.e. box_backup_start() was * called but box_backup_stop() hasn't been yet. */ @@ -2182,11 +2186,11 @@ box_checkpoint() if (! is_box_configured) return 0; int rc = 0; - if (box_checkpoint_is_in_progress) { + if (checkpoint_is_in_progress) { diag_set(ClientError, ER_CHECKPOINT_IN_PROGRESS); return -1; } - box_checkpoint_is_in_progress = true; + checkpoint_is_in_progress = true; /* create checkpoint files */ latch_lock(&schema_lock); if ((rc = engine_begin_checkpoint())) @@ -2206,7 +2210,7 @@ end: engine_abort_checkpoint(); latch_unlock(&schema_lock); - box_checkpoint_is_in_progress = false; + checkpoint_is_in_progress = false; /* * Wait for background garbage collection that might diff --git a/src/box/box.h b/src/box/box.h index 7712c192..6de0691d 100644 --- a/src/box/box.h +++ b/src/box/box.h @@ -124,11 +124,6 @@ box_wait_ro(bool ro, double timeout); void box_set_orphan(bool orphan); -/** True if snapshot is in progress. */ -extern bool box_checkpoint_is_in_progress; -/** Incremented with each next snapshot. */ -extern uint32_t snapshot_version; - /** * Iterate over all spaces and save them to the * snapshot file. diff --git a/src/main.cc b/src/main.cc index 6fb0e479..993355ac 100644 --- a/src/main.cc +++ b/src/main.cc @@ -96,18 +96,27 @@ tarantool_uptime(void) } /** -* Create a checkpoint from signal handler (SIGUSR1) -*/ + * Create a checkpoint from signal handler (SIGUSR1) + */ +static int +sig_checkpoint_f(va_list ap) +{ + (void)ap; + if (box_checkpoint() != 0) + diag_log(); + return 0; +} + static void sig_checkpoint(ev_loop * /* loop */, struct ev_signal * /* w */, int /* revents */) { - if (box_checkpoint_is_in_progress) { - say_warn("Checkpoint is already in progress," - " the signal is ignored"); + struct fiber *f = fiber_new("checkpoint", sig_checkpoint_f); + if (f == NULL) { + say_warn("failed to allocate checkpoint fiber"); return; } - fiber_start(fiber_new_xc("checkpoint", (fiber_func)box_checkpoint)); + fiber_wakeup(f); } static void -- 2.11.0