From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 03/13] gc: make gc_consumer and gc_state structs transparent Date: Thu, 4 Oct 2018 20:20:05 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: 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 -#include + +#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