Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
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	[thread overview]
Message-ID: <9fc9cb3fbc469e505c8253ae8591a1c924d5b54a.1544282224.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1544282224.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1544282224.git.vdavydov.dev@gmail.com>

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

  parent reply	other threads:[~2018-12-08 15:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-08 15:48 [PATCH v2 00/10] Allow to limit size of WAL files Vladimir Davydov
2018-12-08 15:48 ` [PATCH v2 01/10] gc: do not use WAL watcher API for deactivating stale consumers Vladimir Davydov
2018-12-08 21:41   ` Konstantin Osipov
2018-12-08 15:48 ` [PATCH v2 02/10] wal: simplify watcher API Vladimir Davydov
2018-12-08 21:41   ` Konstantin Osipov
2018-12-08 15:48 ` [PATCH v2 03/10] box: fix certain cfg options initialized twice on recovery Vladimir Davydov
2018-12-08 21:42   ` Konstantin Osipov
2018-12-08 15:48 ` Vladimir Davydov [this message]
2018-12-08 21:43   ` [PATCH v2 04/10] box: don't use box_checkpoint_is_in_progress outside box.cc Konstantin Osipov
2018-12-08 15:48 ` [PATCH v2 05/10] box: move checkpointing to gc module Vladimir Davydov
2018-12-08 21:44   ` Konstantin Osipov
2018-12-08 15:48 ` [PATCH v2 06/10] gc: some renames Vladimir Davydov
2018-12-08 21:44   ` Konstantin Osipov
2018-12-08 15:48 ` [PATCH v2 07/10] Introduce checkpoint schedule module Vladimir Davydov
2018-12-08 21:45   ` Konstantin Osipov
2018-12-08 15:48 ` [PATCH v2 08/10] Rewrite checkpoint daemon in C Vladimir Davydov
2018-12-08 21:45   ` Konstantin Osipov
2018-12-08 15:48 ` [PATCH v2 09/10] wal: pass struct instead of vclock to checkpoint methods Vladimir Davydov
2018-12-08 21:46   ` Konstantin Osipov
2018-12-08 15:48 ` [PATCH v2 10/10] wal: trigger checkpoint if there are too many WALs Vladimir Davydov
2018-12-08 21:48   ` Konstantin Osipov
2018-12-09 11:20 ` [PATCH v2 00/10] Allow to limit size of WAL files 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=9fc9cb3fbc469e505c8253ae8591a1c924d5b54a.1544282224.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v2 04/10] box: don'\''t use box_checkpoint_is_in_progress outside box.cc' \
    /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