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 06/13] gc: format consumer name in gc_consumer_register
Date: Thu,  4 Oct 2018 20:20:08 +0300	[thread overview]
Message-ID: <4706d4e8531ed4dd074e4767a4665d785ec55703.1538671546.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1538671546.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1538671546.git.vdavydov.dev@gmail.com>

It's better than using tt_snprintf at call sites.
---
 src/box/box.cc   |  7 +++----
 src/box/gc.c     | 11 ++++++++---
 src/box/gc.h     | 10 ++++++----
 src/box/relay.cc |  6 +++---
 4 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index 207e411c..bdf71eb2 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1458,9 +1458,8 @@ box_process_join(struct ev_io *io, struct xrow_header *header)
 		tnt_raise(ClientError, ER_MISSING_SNAPSHOT);
 
 	/* Register the replica with the garbage collector. */
-	struct gc_consumer *gc = gc_consumer_register(
-		tt_sprintf("replica %s", tt_uuid_str(&instance_uuid)),
-		&start_vclock, GC_CONSUMER_WAL);
+	struct gc_consumer *gc = gc_consumer_register(&start_vclock,
+		GC_CONSUMER_WAL, "replica %s", tt_uuid_str(&instance_uuid));
 	if (gc == NULL)
 		diag_raise();
 	auto gc_guard = make_scoped_guard([=]{
@@ -2176,7 +2175,7 @@ box_backup_start(int checkpoint_idx, box_backup_cb cb, void *cb_arg)
 			return -1;
 		}
 	} while (checkpoint_idx-- > 0);
-	backup_gc = gc_consumer_register("backup", vclock, GC_CONSUMER_ALL);
+	backup_gc = gc_consumer_register(vclock, GC_CONSUMER_ALL, "backup");
 	if (backup_gc == NULL)
 		return -1;
 	int rc = engine_backup(vclock, cb, cb_arg);
diff --git a/src/box/gc.c b/src/box/gc.c
index 449416b5..100c972f 100644
--- a/src/box/gc.c
+++ b/src/box/gc.c
@@ -32,6 +32,7 @@
 
 #include <trivia/util.h>
 
+#include <stdarg.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -185,8 +186,8 @@ gc_set_checkpoint_count(int checkpoint_count)
 }
 
 struct gc_consumer *
-gc_consumer_register(const char *name, const struct vclock *vclock,
-		     enum gc_consumer_type type)
+gc_consumer_register(const struct vclock *vclock, enum gc_consumer_type type,
+		     const char *format, ...)
 {
 	struct gc_consumer *consumer = calloc(1, sizeof(*consumer));
 	if (consumer == NULL) {
@@ -195,7 +196,11 @@ gc_consumer_register(const char *name, const struct vclock *vclock,
 		return NULL;
 	}
 
-	snprintf(consumer->name, GC_NAME_MAX, "%s", name);
+	va_list ap;
+	va_start(ap, format);
+	vsnprintf(consumer->name, GC_NAME_MAX, format, ap);
+	va_end(ap);
+
 	vclock_copy(&consumer->vclock, vclock);
 	consumer->type = type;
 
diff --git a/src/box/gc.h b/src/box/gc.h
index fde4facf..6e2a4910 100644
--- a/src/box/gc.h
+++ b/src/box/gc.h
@@ -35,6 +35,7 @@
 
 #include "vclock.h"
 #include "latch.h"
+#include "trivia/util.h"
 
 #if defined(__cplusplus)
 extern "C" {
@@ -122,17 +123,18 @@ gc_set_checkpoint_count(int checkpoint_count);
  *
  * This will stop garbage collection of objects newer than
  * @vclock until the consumer is unregistered or advanced.
- * @name is a human-readable name of the consumer, it will
- * be used for reporting the consumer to the user.
+ * @format... specifies a human-readable name of the consumer,
+ * it will be used for listing the consumer in box.info.gc().
  * @type consumer type, reporting whether consumer only depends
  * on WAL files.
  *
  * Returns a pointer to the new consumer object or NULL on
  * memory allocation failure.
  */
+CFORMAT(printf, 3, 4)
 struct gc_consumer *
-gc_consumer_register(const char *name, const struct vclock *vclock,
-		     enum gc_consumer_type type);
+gc_consumer_register(const struct vclock *vclock, enum gc_consumer_type type,
+		     const char *format, ...);
 
 /**
  * Unregister a consumer and invoke garbage collection
diff --git a/src/box/relay.cc b/src/box/relay.cc
index c90383d4..88430856 100644
--- a/src/box/relay.cc
+++ b/src/box/relay.cc
@@ -592,9 +592,9 @@ relay_subscribe(struct replica *replica, int fd, uint64_t sync,
 	 * join.
 	 */
 	if (replica->gc == NULL) {
-		replica->gc = gc_consumer_register(
-			tt_sprintf("replica %s", tt_uuid_str(&replica->uuid)),
-			replica_clock, GC_CONSUMER_WAL);
+		replica->gc = gc_consumer_register(replica_clock,
+				GC_CONSUMER_WAL, "replica %s",
+				tt_uuid_str(&replica->uuid));
 		if (replica->gc == NULL)
 			diag_raise();
 	}
-- 
2.11.0

  parent reply	other threads:[~2018-10-04 17:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 17:20 [PATCH 00/13] box: garbage collection refactoring and fixes Vladimir Davydov
2018-10-04 17:20 ` [PATCH 01/13] vinyl: fix master crash on replica join failure Vladimir Davydov
2018-10-04 21:43   ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 02/13] vinyl: force deletion of runs left from unfinished indexes on restart Vladimir Davydov
2018-10-04 21:44   ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 03/13] gc: make gc_consumer and gc_state structs transparent Vladimir Davydov
2018-10-04 21:47   ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 04/13] gc: use fixed length buffer for storing consumer name Vladimir Davydov
2018-10-04 21:47   ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 05/13] gc: fold gc_consumer_new and gc_consumer_delete Vladimir Davydov
2018-10-04 21:50   ` Konstantin Osipov
2018-10-05  8:56     ` Vladimir Davydov
2018-10-04 17:20 ` Vladimir Davydov [this message]
2018-10-04 21:50   ` [PATCH 06/13] gc: format consumer name in gc_consumer_register Konstantin Osipov
2018-10-04 17:20 ` [PATCH 07/13] gc: rename checkpoint_count to min_checkpoint_count Vladimir Davydov
2018-10-04 21:51   ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 08/13] gc: keep track of available checkpoints Vladimir Davydov
2018-10-04 21:59   ` Konstantin Osipov
2018-10-05  8:50     ` Vladimir Davydov
2018-10-04 17:20 ` [PATCH 09/13] gc: cleanup garbage collection procedure Vladimir Davydov
2018-10-04 22:00   ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 10/13] gc: improve box.info.gc output Vladimir Davydov
2018-10-04 22:01   ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 11/13] gc: separate checkpoint references from wal consumers Vladimir Davydov
2018-10-04 22:05   ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 12/13] gc: call gc_run unconditionally when consumer is advanced Vladimir Davydov
2018-10-04 22:26   ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 13/13] replication: ref checkpoint needed to join replica Vladimir Davydov
2018-10-04 22:27   ` Konstantin Osipov
2018-10-05 17:03 ` [PATCH 00/13] box: garbage collection refactoring and fixes 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=4706d4e8531ed4dd074e4767a4665d785ec55703.1538671546.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 06/13] gc: format consumer name in gc_consumer_register' \
    /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