From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [PATCH v3 4/7] memtx: hide index implementation details from header Date: Fri, 22 Feb 2019 18:42:29 +0300 [thread overview] Message-ID: <6763eb64568e835a025b9d083c8afecdcd0a82ea.1550849496.git.kshcherbatov@tarantool.org> (raw) In-Reply-To: <cover.1550849496.git.kshcherbatov@tarantool.org> Refactored memtx_tree code so that memtx_tree.h, memtx_rtree.h, memtx_bitset.h, memtx_hash.h contained only the signature of the tree object constructor while all implementation details were in corresponding *.c files. Needed for #3961 --- src/box/memtx_bitset.c | 17 +++++++++-- src/box/memtx_bitset.h | 26 ++-------------- src/box/memtx_hash.c | 43 ++++++++++++++++++++++++-- src/box/memtx_hash.h | 44 +++------------------------ src/box/memtx_rtree.c | 12 ++++++-- src/box/memtx_rtree.h | 16 ++-------- src/box/memtx_space.c | 16 +++++----- src/box/memtx_tree.c | 62 ++++++++++++++++++++++++++++++++++++-- src/box/memtx_tree.h | 68 ++---------------------------------------- 9 files changed, 147 insertions(+), 157 deletions(-) diff --git a/src/box/memtx_bitset.c b/src/box/memtx_bitset.c index 9dbc4141d..64259cf44 100644 --- a/src/box/memtx_bitset.c +++ b/src/box/memtx_bitset.c @@ -36,12 +36,25 @@ #include "trivia/util.h" +#include "bitset/index.h" #include "fiber.h" +#include "index.h" #include "tuple.h" #include "memtx_engine.h" +struct memtx_bitset_index { + struct index base; + struct tt_bitset_index index; +#ifndef OLD_GOOD_BITSET + struct matras *id_to_tuple; + struct mh_bitset_index_t *tuple_to_id; + uint32_t spare_id; +#endif /*#ifndef OLD_GOOD_BITSET*/ +}; + #ifndef OLD_GOOD_BITSET #include "small/matras.h" +struct mh_bitset_index_t; struct bitset_hash_entry { struct tuple *tuple; @@ -491,7 +504,7 @@ static const struct index_vtab memtx_bitset_index_vtab = { /* .end_build = */ generic_index_end_build, }; -struct memtx_bitset_index * +struct index * memtx_bitset_index_new(struct memtx_engine *memtx, struct index_def *def) { assert(def->iid > 0); @@ -529,5 +542,5 @@ memtx_bitset_index_new(struct memtx_engine *memtx, struct index_def *def) #endif /* #ifndef OLD_GOOD_BITSET */ tt_bitset_index_create(&index->index, realloc); - return index; + return &index->base; } diff --git a/src/box/memtx_bitset.h b/src/box/memtx_bitset.h index 62971dd51..148d463d8 100644 --- a/src/box/memtx_bitset.h +++ b/src/box/memtx_bitset.h @@ -31,35 +31,15 @@ * SUCH DAMAGE. */ -/** - * @brief Index API wrapper for bitset_index - * @see bitset/index.h - */ -#include "index.h" -#include "bitset/index.h" - #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ +struct index; +struct index_def; struct memtx_engine; -#ifndef OLD_GOOD_BITSET -struct matras; -struct mh_bitset_index_t; -#endif /*#ifndef OLD_GOOD_BITSET*/ - -struct memtx_bitset_index { - struct index base; - struct tt_bitset_index index; -#ifndef OLD_GOOD_BITSET - struct matras *id_to_tuple; - struct mh_bitset_index_t *tuple_to_id; - uint32_t spare_id; -#endif /*#ifndef OLD_GOOD_BITSET*/ -}; - -struct memtx_bitset_index * +struct index * memtx_bitset_index_new(struct memtx_engine *memtx, struct index_def *def); #if defined(__cplusplus) diff --git a/src/box/memtx_hash.c b/src/box/memtx_hash.c index b35a52528..e7d64a9fb 100644 --- a/src/box/memtx_hash.c +++ b/src/box/memtx_hash.c @@ -31,6 +31,7 @@ #include "memtx_hash.h" #include "say.h" #include "fiber.h" +#include "index.h" #include "tuple.h" #include "memtx_engine.h" #include "space.h" @@ -39,6 +40,44 @@ #include <small/mempool.h> +static inline bool +memtx_hash_equal(struct tuple *tuple_a, struct tuple *tuple_b, + struct key_def *key_def) +{ + return tuple_compare(tuple_a, tuple_b, key_def) == 0; +} + +static inline bool +memtx_hash_equal_key(struct tuple *tuple, const char *key, + struct key_def *key_def) +{ + return tuple_compare_with_key(tuple, key, key_def->part_count, + key_def) == 0; +} + +#define LIGHT_NAME _index +#define LIGHT_DATA_TYPE struct tuple * +#define LIGHT_KEY_TYPE const char * +#define LIGHT_CMP_ARG_TYPE struct key_def * +#define LIGHT_EQUAL(a, b, c) memtx_hash_equal(a, b, c) +#define LIGHT_EQUAL_KEY(a, b, c) memtx_hash_equal_key(a, b, c) + +#include "salad/light.h" + +#undef LIGHT_NAME +#undef LIGHT_DATA_TYPE +#undef LIGHT_KEY_TYPE +#undef LIGHT_CMP_ARG_TYPE +#undef LIGHT_EQUAL +#undef LIGHT_EQUAL_KEY + +struct memtx_hash_index { + struct index base; + struct light_index_core hash_table; + struct memtx_gc_task gc_task; + struct light_index_iterator gc_iterator; +}; + /* {{{ MemtxHash Iterators ****************************************/ struct hash_iterator { @@ -450,7 +489,7 @@ static const struct index_vtab memtx_hash_index_vtab = { /* .end_build = */ generic_index_end_build, }; -struct memtx_hash_index * +struct index * memtx_hash_index_new(struct memtx_engine *memtx, struct index_def *def) { if (!mempool_is_initialized(&memtx->iterator_pool)) { @@ -474,7 +513,7 @@ memtx_hash_index_new(struct memtx_engine *memtx, struct index_def *def) light_index_create(&index->hash_table, MEMTX_EXTENT_SIZE, memtx_index_extent_alloc, memtx_index_extent_free, memtx, index->base.def->key_def); - return index; + return &index->base; } /* }}} */ diff --git a/src/box/memtx_hash.h b/src/box/memtx_hash.h index 10663fcfc..2dba3f5c5 100644 --- a/src/box/memtx_hash.h +++ b/src/box/memtx_hash.h @@ -30,52 +30,16 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include "index.h" -#include "memtx_engine.h" #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ -static inline bool -memtx_hash_equal(struct tuple *tuple_a, struct tuple *tuple_b, - struct key_def *key_def) -{ - return tuple_compare(tuple_a, tuple_b, key_def) == 0; -} +struct index; +struct index_def; +struct memtx_engine; -static inline bool -memtx_hash_equal_key(struct tuple *tuple, const char *key, - struct key_def *key_def) -{ - return tuple_compare_with_key(tuple, key, key_def->part_count, - key_def) == 0; -} - -#define LIGHT_NAME _index -#define LIGHT_DATA_TYPE struct tuple * -#define LIGHT_KEY_TYPE const char * -#define LIGHT_CMP_ARG_TYPE struct key_def * -#define LIGHT_EQUAL(a, b, c) memtx_hash_equal(a, b, c) -#define LIGHT_EQUAL_KEY(a, b, c) memtx_hash_equal_key(a, b, c) - -#include "salad/light.h" - -#undef LIGHT_NAME -#undef LIGHT_DATA_TYPE -#undef LIGHT_KEY_TYPE -#undef LIGHT_CMP_ARG_TYPE -#undef LIGHT_EQUAL -#undef LIGHT_EQUAL_KEY - -struct memtx_hash_index { - struct index base; - struct light_index_core hash_table; - struct memtx_gc_task gc_task; - struct light_index_iterator gc_iterator; -}; - -struct memtx_hash_index * +struct index * memtx_hash_index_new(struct memtx_engine *memtx, struct index_def *def); #if defined(__cplusplus) diff --git a/src/box/memtx_rtree.c b/src/box/memtx_rtree.c index 9cb93f150..5d2901ad9 100644 --- a/src/box/memtx_rtree.c +++ b/src/box/memtx_rtree.c @@ -30,9 +30,11 @@ */ #include "memtx_rtree.h" +#include <salad/rtree.h> #include <small/small.h> #include <small/mempool.h> +#include "index.h" #include "errinj.h" #include "fiber.h" #include "trivia/util.h" @@ -41,6 +43,12 @@ #include "space.h" #include "memtx_engine.h" +struct memtx_rtree_index { + struct index base; + unsigned dimension; + struct rtree tree; +}; + /* {{{ Utilities. *************************************************/ static inline int @@ -333,7 +341,7 @@ static const struct index_vtab memtx_rtree_index_vtab = { /* .end_build = */ generic_index_end_build, }; -struct memtx_rtree_index * +struct index * memtx_rtree_index_new(struct memtx_engine *memtx, struct index_def *def) { assert(def->iid > 0); @@ -377,5 +385,5 @@ memtx_rtree_index_new(struct memtx_engine *memtx, struct index_def *def) rtree_init(&index->tree, index->dimension, MEMTX_EXTENT_SIZE, memtx_index_extent_alloc, memtx_index_extent_free, memtx, distance_type); - return index; + return &index->base; } diff --git a/src/box/memtx_rtree.h b/src/box/memtx_rtree.h index 359aa898e..2941b805a 100644 --- a/src/box/memtx_rtree.h +++ b/src/box/memtx_rtree.h @@ -30,26 +30,16 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include <stddef.h> -#include <stdint.h> - -#include <salad/rtree.h> - -#include "index.h" #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ +struct index; +struct index_def; struct memtx_engine; -struct memtx_rtree_index { - struct index base; - unsigned dimension; - struct rtree tree; -}; - -struct memtx_rtree_index * +struct index * memtx_rtree_index_new(struct memtx_engine *memtx, struct index_def *def); #if defined(__cplusplus) diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c index 5f8cc98fd..92ec0b300 100644 --- a/src/box/memtx_space.c +++ b/src/box/memtx_space.c @@ -716,21 +716,21 @@ sequence_data_index_create_snapshot_iterator(struct index *index) static struct index * sequence_data_index_new(struct memtx_engine *memtx, struct index_def *def) { - struct memtx_hash_index *index = memtx_hash_index_new(memtx, def); + struct index *index = memtx_hash_index_new(memtx, def); if (index == NULL) return NULL; static struct index_vtab vtab; static bool vtab_initialized; if (!vtab_initialized) { - vtab = *index->base.vtab; + vtab = *index->vtab; vtab.create_snapshot_iterator = sequence_data_index_create_snapshot_iterator; vtab_initialized = true; } - index->base.vtab = &vtab; - return &index->base; + index->vtab = &vtab; + return index; } static struct index * @@ -751,13 +751,13 @@ memtx_space_create_index(struct space *space, struct index_def *index_def) switch (index_def->type) { case HASH: - return (struct index *)memtx_hash_index_new(memtx, index_def); + return memtx_hash_index_new(memtx, index_def); case TREE: - return (struct index *)memtx_tree_index_new(memtx, index_def); + return memtx_tree_index_new(memtx, index_def); case RTREE: - return (struct index *)memtx_rtree_index_new(memtx, index_def); + return memtx_rtree_index_new(memtx, index_def); case BITSET: - return (struct index *)memtx_bitset_index_new(memtx, index_def); + return memtx_bitset_index_new(memtx, index_def); default: unreachable(); return NULL; diff --git a/src/box/memtx_tree.c b/src/box/memtx_tree.c index fe66427fc..07d20473f 100644 --- a/src/box/memtx_tree.c +++ b/src/box/memtx_tree.c @@ -39,6 +39,64 @@ #include <third_party/qsort_arg.h> #include <small/mempool.h> +/** + * Struct that is used as a key in BPS tree definition. + */ +struct memtx_tree_key_data { + /** Sequence of msgpacked search fields. */ + const char *key; + /** Number of msgpacked search fields. */ + uint32_t part_count; +}; + +/** + * BPS tree element vs key comparator. + * Defined in header in order to allow compiler to inline it. + * @param tuple - tuple to compare. + * @param key_data - key to compare with. + * @param def - key definition. + * @retval 0 if tuple == key in terms of def. + * @retval <0 if tuple < key in terms of def. + * @retval >0 if tuple > key in terms of def. + */ +static int +memtx_tree_compare_key(const struct tuple *tuple, + const struct memtx_tree_key_data *key_data, + struct key_def *def) +{ + return tuple_compare_with_key(tuple, key_data->key, + key_data->part_count, def); +} + +#define BPS_TREE_NAME memtx_tree +#define BPS_TREE_BLOCK_SIZE (512) +#define BPS_TREE_EXTENT_SIZE MEMTX_EXTENT_SIZE +#define BPS_TREE_COMPARE(a, b, arg) tuple_compare(a, b, arg) +#define BPS_TREE_COMPARE_KEY(a, b, arg) memtx_tree_compare_key(a, b, arg) +#define bps_tree_elem_t struct tuple * +#define bps_tree_key_t struct memtx_tree_key_data * +#define bps_tree_arg_t struct key_def * + +#include "salad/bps_tree.h" + +#undef BPS_TREE_NAME +#undef BPS_TREE_BLOCK_SIZE +#undef BPS_TREE_EXTENT_SIZE +#undef BPS_TREE_COMPARE +#undef BPS_TREE_COMPARE_KEY +#undef bps_tree_elem_t +#undef bps_tree_key_t +#undef bps_tree_arg_t + +struct memtx_tree_index { + struct index base; + struct memtx_tree tree; + struct tuple **build_array; + size_t build_array_size, build_array_alloc_size; + struct memtx_gc_task gc_task; + struct memtx_tree_iterator gc_iterator; +}; + /* {{{ Utilities. *************************************************/ static int @@ -686,7 +744,7 @@ static const struct index_vtab memtx_tree_index_vtab = { /* .end_build = */ memtx_tree_index_end_build, }; -struct memtx_tree_index * +struct index * memtx_tree_index_new(struct memtx_engine *memtx, struct index_def *def) { if (!mempool_is_initialized(&memtx->iterator_pool)) { @@ -710,5 +768,5 @@ memtx_tree_index_new(struct memtx_engine *memtx, struct index_def *def) struct key_def *cmp_def = memtx_tree_index_cmp_def(index); memtx_tree_create(&index->tree, cmp_def, memtx_index_extent_alloc, memtx_index_extent_free, memtx); - return index; + return &index->base; } diff --git a/src/box/memtx_tree.h b/src/box/memtx_tree.h index bbc8b2419..edeaebab9 100644 --- a/src/box/memtx_tree.h +++ b/src/box/memtx_tree.h @@ -30,78 +30,16 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include <stddef.h> -#include <stdint.h> - -#include "index.h" -#include "memtx_engine.h" #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ +struct index; +struct index_def; struct memtx_engine; -/** - * Struct that is used as a key in BPS tree definition. - */ -struct memtx_tree_key_data -{ - /** Sequence of msgpacked search fields */ - const char *key; - /** Number of msgpacked search fields */ - uint32_t part_count; -}; - -/** - * BPS tree element vs key comparator. - * Defined in header in order to allow compiler to inline it. - * @param tuple - tuple to compare. - * @param key_data - key to compare with. - * @param def - key definition. - * @retval 0 if tuple == key in terms of def. - * @retval <0 if tuple < key in terms of def. - * @retval >0 if tuple > key in terms of def. - */ -static inline int -memtx_tree_compare_key(const struct tuple *tuple, - const struct memtx_tree_key_data *key_data, - struct key_def *def) -{ - return tuple_compare_with_key(tuple, key_data->key, - key_data->part_count, def); -} - -#define BPS_TREE_NAME memtx_tree -#define BPS_TREE_BLOCK_SIZE (512) -#define BPS_TREE_EXTENT_SIZE MEMTX_EXTENT_SIZE -#define BPS_TREE_COMPARE(a, b, arg) tuple_compare(a, b, arg) -#define BPS_TREE_COMPARE_KEY(a, b, arg) memtx_tree_compare_key(a, b, arg) -#define bps_tree_elem_t struct tuple * -#define bps_tree_key_t struct memtx_tree_key_data * -#define bps_tree_arg_t struct key_def * - -#include "salad/bps_tree.h" - -#undef BPS_TREE_NAME -#undef BPS_TREE_BLOCK_SIZE -#undef BPS_TREE_EXTENT_SIZE -#undef BPS_TREE_COMPARE -#undef BPS_TREE_COMPARE_KEY -#undef bps_tree_elem_t -#undef bps_tree_key_t -#undef bps_tree_arg_t - -struct memtx_tree_index { - struct index base; - struct memtx_tree tree; - struct tuple **build_array; - size_t build_array_size, build_array_alloc_size; - struct memtx_gc_task gc_task; - struct memtx_tree_iterator gc_iterator; -}; - -struct memtx_tree_index * +struct index * memtx_tree_index_new(struct memtx_engine *memtx, struct index_def *def); #if defined(__cplusplus) -- 2.20.1
next prev parent reply other threads:[~2019-02-22 15:42 UTC|newest] Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-02-22 15:42 [PATCH v3 0/7] box: introduce hint option for memtx tree index Kirill Shcherbatov 2019-02-22 15:42 ` [PATCH v3 1/7] memtx: introduce universal iterator_pool Kirill Shcherbatov 2019-02-22 18:37 ` [tarantool-patches] " Konstantin Osipov 2019-02-23 12:03 ` Kirill Shcherbatov 2019-02-25 16:14 ` Vladimir Davydov 2019-02-25 16:39 ` [tarantool-patches] " Kirill Shcherbatov 2019-02-25 17:14 ` Vladimir Davydov 2019-02-24 6:56 ` [tarantool-patches] " Vladimir Davydov 2019-02-24 17:15 ` Konstantin Osipov 2019-02-24 18:22 ` Vladimir Davydov 2019-02-25 16:46 ` [tarantool-patches] " Konstantin Osipov 2019-02-25 17:15 ` Vladimir Davydov 2019-02-22 15:42 ` [PATCH v3 2/7] lib: fix undef _api_name in bps_tree header Kirill Shcherbatov 2019-02-22 18:37 ` [tarantool-patches] " Konstantin Osipov 2019-02-25 15:32 ` Vladimir Davydov 2019-02-22 15:42 ` [PATCH v3 3/7] lib: introduce BPS_TREE_IDENTICAL custom comparator Kirill Shcherbatov 2019-02-25 15:33 ` Vladimir Davydov 2019-02-22 15:42 ` Kirill Shcherbatov [this message] 2019-02-22 18:40 ` [tarantool-patches] [PATCH v3 4/7] memtx: hide index implementation details from header Konstantin Osipov 2019-02-25 15:33 ` Vladimir Davydov 2019-02-22 15:42 ` [PATCH v3 5/7] memtx: rework memtx_tree to store arbitrary nodes Kirill Shcherbatov 2019-02-25 16:57 ` Vladimir Davydov 2019-02-26 12:10 ` [tarantool-patches] " Kirill Shcherbatov 2019-02-22 15:42 ` [PATCH v3 6/7] memtx: rename memtx_tree.c to memtx_tree_impl.h Kirill Shcherbatov 2019-02-22 15:42 ` [PATCH v3 7/7] memtx: introduce tuple compare hint Kirill Shcherbatov 2019-02-25 17:44 ` Vladimir Davydov 2019-02-26 12:10 ` [tarantool-patches] " Kirill Shcherbatov
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=6763eb64568e835a025b9d083c8afecdcd0a82ea.1550849496.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH v3 4/7] memtx: hide index implementation details from header' \ /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