[PATCH v5 1/4] memtx: rework memtx_tree to store arbitrary nodes

Vladimir Davydov vdavydov.dev at gmail.com
Mon Mar 11 13:34:01 MSK 2019


On Thu, Mar 07, 2019 at 12:44:05PM +0300, Kirill Shcherbatov wrote:
> Reworked memtx_tree class to use arbitrary containers as a tree
> nodes. This makes possible to implement tuple hints in subsequent
> patches.

The comment and the subject line are confusing: what arbitrary
containers are you talking about? Looks like it's left from the
previous version of the patch that used templates. Please fix.

> 
> Needed for #3961
> ---
>  src/box/memtx_tree.c | 289 ++++++++++++++++++++++++++-----------------
>  1 file changed, 178 insertions(+), 111 deletions(-)
> 
> diff --git a/src/box/memtx_tree.c b/src/box/memtx_tree.c
> index 250df7f2d..688f09597 100644
> --- a/src/box/memtx_tree.c
> +++ b/src/box/memtx_tree.c
> @@ -50,30 +50,70 @@ struct memtx_tree_key_data {
>  };
>  
>  /**
> - * 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.
> + * Struct that is used as a elem in BPS tree definition.
>   */
> -static int
> -memtx_tree_compare_key(const struct tuple *tuple,
> -		       const struct memtx_tree_key_data *key_data,
> -		       struct key_def *def)
> +struct memtx_tree_data {
> +	/* Tuple that this node is represents. */
> +	struct tuple *tuple;
> +};
> +
> +/**
> + * Test whether BPS tree elements are identical i.e. represents

s/represents/represent

> + * the same tuple and metadata.

the same tuple at the same position in the tree.

> + * @param a - First BPS tree element to compare.
> + * @param b - Second BPS tree element to compare.
> + * @retval true - When elements a and b are identical.
> + * @retval fa;se - Otherwise.

s/fa;se/false

> + */
> +static bool
> +memtx_tree_data_identical(const struct memtx_tree_data *a,
> +			  const struct memtx_tree_data *b)
>  {
> -	return tuple_compare_with_key(tuple, key_data->key,
> -				      key_data->part_count, def);
> +	return a->tuple == b->tuple;
> +}
> +
> +/**
> + * BPS tree element clear.
> + * @param data - BPS tree element to clear.
> + */
> +static void
> +memtx_tree_data_clear(struct memtx_tree_data *data)
> +{
> +	data->tuple = NULL;
> +}

Please remove this trivial helper function - even after multikey indexes
are introduced, this function will remain the same.

> +
> +/**
> + * Initialize BPS tree element.
> + */
> +static void
> +memtx_tree_data_set(struct memtx_tree_data *data, struct tuple *tuple,
> +		    struct key_def *key_def)
> +{
> +	(void)key_def;
> +	data->tuple = tuple;
> +}

Please remove this trivial helper function as well, as it's only used in
'build_next' and 'replace' index callbacks, which will differ for hinted
and multikey trees anyway.

> +
> +/**
> + * Initialize BPS tree key element.
> + */
> +static void
> +memtx_tree_key_data_set(struct memtx_tree_key_data *key_data, const char *key,
> +			uint32_t part_count, struct key_def *key_def)

This function is only used in 'get' and 'create_iterator' index
callbacks. Rather than using it, you should set different callbacks
for multikey and hinted trees. Please remove it, too.

> +{
> +	(void)key_def;
> +	key_data->key = key;
> +	key_data->part_count = part_count;
>  }

> @@ -614,21 +678,23 @@ static int
>  memtx_tree_index_build_next(struct index *base, struct tuple *tuple)
>  {
>  	struct memtx_tree_index *index = (struct memtx_tree_index *)base;
> +	struct key_def *key_def = index->tree.arg;
>  	if (index->build_array == NULL) {
> -		index->build_array = (struct tuple **)malloc(MEMTX_EXTENT_SIZE);
> +		index->build_array =
> +			(struct memtx_tree_data *)malloc(MEMTX_EXTENT_SIZE);

Nit: pointless type cast, please remove.



More information about the Tarantool-patches mailing list