From: Vladimir Davydov <vdavydov.dev@gmail.com> To: kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [PATCH 03/13] gc: make gc_consumer and gc_state structs transparent Date: Thu, 4 Oct 2018 20:20:05 +0300 [thread overview] Message-ID: <b8751e7fb0ca9f0e5c5451e5f0f431866cf0b28e.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 exasperating to write trivial external functions for each member of an opaque struct (gc_consumer_vclock, gc_consumer_name, etc) while we could simply access those fields directly if we made those structs transparent. Since we usually define structs as transparent if we need to use them outside a source file, let's do the same for gc_consumer and gc_state and remove all those one-line wrappers. --- src/box/box.cc | 2 +- src/box/gc.c | 63 +----------------------------------------------------- src/box/gc.h | 63 ++++++++++++++++++++++++++++++++++++------------------ src/box/lua/info.c | 4 ++-- 4 files changed, 46 insertions(+), 86 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 804fc00e..207e411c 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -1613,7 +1613,7 @@ box_process_vote(struct ballot *ballot) { ballot->is_ro = cfg_geti("read_only") != 0; vclock_copy(&ballot->vclock, &replicaset.vclock); - gc_vclock(&ballot->gc_vclock); + vclock_copy(&ballot->gc_vclock, &gc.wal_vclock); } /** Insert a new cluster into _schema */ diff --git a/src/box/gc.c b/src/box/gc.c index 3ab76626..a45806b6 100644 --- a/src/box/gc.c +++ b/src/box/gc.c @@ -48,44 +48,7 @@ #include "engine.h" /* engine_collect_garbage() */ #include "wal.h" /* wal_collect_garbage() */ -typedef rb_node(struct gc_consumer) gc_node_t; - -/** - * The object of this type is used to prevent garbage - * collection from removing files that are still in use. - */ -struct gc_consumer { - /** Link in gc_state::consumers. */ - gc_node_t node; - /** Human-readable name. */ - char *name; - /** The vclock tracked by this consumer. */ - struct vclock vclock; - /** Consumer type, indicating that consumer only consumes - * WAL files, or both - SNAP and WAL. - */ - enum gc_consumer_type type; -}; - -typedef rb_tree(struct gc_consumer) gc_tree_t; - -/** Garbage collection state. */ -struct gc_state { - /** Number of checkpoints to maintain. */ - int checkpoint_count; - /** Max vclock WAL garbage collection has been called for. */ - struct vclock wal_vclock; - /** Max vclock checkpoint garbage collection has been called for. */ - struct vclock checkpoint_vclock; - /** Registered consumers, linked by gc_consumer::node. */ - gc_tree_t consumers; - /** - * Latch serializing concurrent invocations of engine - * garbage collection callbacks. - */ - struct latch latch; -}; -static struct gc_state gc; +struct gc_state gc; /** * Comparator used for ordering gc_consumer objects by signature @@ -163,12 +126,6 @@ gc_free(void) } } -void -gc_vclock(struct vclock *vclock) -{ - vclock_copy(vclock, &gc.wal_vclock); -} - /** Find the consumer that uses the oldest checkpoint. */ struct gc_consumer * gc_tree_first_checkpoint(gc_tree_t *consumers) @@ -321,24 +278,6 @@ gc_consumer_advance(struct gc_consumer *consumer, const struct vclock *vclock) gc_run(); } -const char * -gc_consumer_name(const struct gc_consumer *consumer) -{ - return consumer->name; -} - -void -gc_consumer_vclock(const struct gc_consumer *consumer, struct vclock *vclock) -{ - vclock_copy(vclock, &consumer->vclock); -} - -int64_t -gc_consumer_signature(const struct gc_consumer *consumer) -{ - return vclock_sum(&consumer->vclock); -} - struct gc_consumer * gc_consumer_iterator_next(struct gc_consumer_iterator *it) { diff --git a/src/box/gc.h b/src/box/gc.h index 36a951bf..2c03770d 100644 --- a/src/box/gc.h +++ b/src/box/gc.h @@ -32,13 +32,14 @@ */ #include <stddef.h> -#include <stdint.h> + +#include "vclock.h" +#include "latch.h" #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ -struct vclock; struct gc_consumer; /** Consumer type: WAL consumer, or SNAP */ @@ -48,6 +49,45 @@ enum gc_consumer_type { GC_CONSUMER_ALL = 3, }; +typedef rb_node(struct gc_consumer) gc_node_t; + +/** + * The object of this type is used to prevent garbage + * collection from removing files that are still in use. + */ +struct gc_consumer { + /** Link in gc_state::consumers. */ + gc_node_t node; + /** Human-readable name. */ + char *name; + /** The vclock tracked by this consumer. */ + struct vclock vclock; + /** Consumer type, indicating that consumer only consumes + * WAL files, or both - SNAP and WAL. + */ + enum gc_consumer_type type; +}; + +typedef rb_tree(struct gc_consumer) gc_tree_t; + +/** Garbage collection state. */ +struct gc_state { + /** Number of checkpoints to maintain. */ + int checkpoint_count; + /** Max vclock WAL garbage collection has been called for. */ + struct vclock wal_vclock; + /** Max vclock checkpoint garbage collection has been called for. */ + struct vclock checkpoint_vclock; + /** Registered consumers, linked by gc_consumer::node. */ + gc_tree_t consumers; + /** + * Latch serializing concurrent invocations of engine + * garbage collection callbacks. + */ + struct latch latch; +}; +extern struct gc_state gc; + /** * Initialize the garbage collection state. */ @@ -61,12 +101,6 @@ void gc_free(void); /** - * Get the oldest available vclock. - */ -void -gc_vclock(struct vclock *vclock); - -/** * Invoke garbage collection in order to remove files left * from old checkpoints. The number of checkpoints saved by * this function is specified by box.cfg.checkpoint_count. @@ -112,19 +146,6 @@ gc_consumer_unregister(struct gc_consumer *consumer); void gc_consumer_advance(struct gc_consumer *consumer, const struct vclock *vclock); -/** Return the name of a consumer. */ -const char * -gc_consumer_name(const struct gc_consumer *consumer); - -/** Return the vclock a consumer tracks. */ -void -gc_consumer_vclock(const struct gc_consumer *consumer, struct vclock *vclock); - - -/** Return the vclock signature a consumer tracks. */ -int64_t -gc_consumer_signature(const struct gc_consumer *consumer); - /** * Iterator over registered consumers. The iterator is valid * as long as the caller doesn't yield. diff --git a/src/box/lua/info.c b/src/box/lua/info.c index d9ea73a6..85b21c65 100644 --- a/src/box/lua/info.c +++ b/src/box/lua/info.c @@ -397,11 +397,11 @@ lbox_info_gc_call(struct lua_State *L) lua_createtable(L, 0, 2); lua_pushstring(L, "name"); - lua_pushstring(L, gc_consumer_name(consumer)); + lua_pushstring(L, consumer->name); lua_settable(L, -3); lua_pushstring(L, "signature"); - luaL_pushint64(L, gc_consumer_signature(consumer)); + luaL_pushint64(L, vclock_sum(&consumer->vclock)); lua_settable(L, -3); lua_rawseti(L, -2, ++count); -- 2.11.0
next prev 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 ` Vladimir Davydov [this message] 2018-10-04 21:47 ` [PATCH 03/13] gc: make gc_consumer and gc_state structs transparent 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 ` [PATCH 06/13] gc: format consumer name in gc_consumer_register Vladimir Davydov 2018-10-04 21:50 ` 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=b8751e7fb0ca9f0e5c5451e5f0f431866cf0b28e.1538671546.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH 03/13] gc: make gc_consumer and gc_state structs transparent' \ /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