From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, kostja@tarantool.org
Cc: vdavydov.dev@gmail.com, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [PATCH v4 2/4] box: generalize memtx_multikey_tree methods
Date: Wed, 24 Jul 2019 10:36:08 +0300 [thread overview]
Message-ID: <fcbb74f62fcef8d81ad05f29ed9e78da5c73653e.1563953154.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1563953154.git.kshcherbatov@tarantool.org>
Updated multikey memtx_tree methods a bit to make possible to
reuse them in case of functional indexes. The BPS_TREE_IDENTICAL
is only used in bps_tree_delete_identical (when BPS_TREE_NO_DEBUG
macro is defined) therefore it may be reused to delete an
identical entry in case of functional index in further patches.
Needed for #1260
---
src/box/memtx_tree.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/src/box/memtx_tree.c b/src/box/memtx_tree.c
index 3edf94044..5f5848c69 100644
--- a/src/box/memtx_tree.c
+++ b/src/box/memtx_tree.c
@@ -73,7 +73,7 @@ static bool
memtx_tree_data_identical(const struct memtx_tree_data *a,
const struct memtx_tree_data *b)
{
- return a->tuple == b->tuple && a->hint == b->hint;
+ return a->tuple == b->tuple;
}
#define BPS_TREE_NAME memtx_tree
@@ -85,6 +85,7 @@ memtx_tree_data_identical(const struct memtx_tree_data *a,
tuple_compare_with_key((&a)->tuple, (&a)->hint, (b)->key,\
(b)->part_count, (b)->hint, arg)
#define BPS_TREE_IDENTICAL(a, b) memtx_tree_data_identical(&a, &b)
+#define BPS_TREE_NO_DEBUG 1
#define bps_tree_elem_t struct memtx_tree_data
#define bps_tree_key_t struct memtx_tree_key_data *
#define bps_tree_arg_t struct key_def *
@@ -97,6 +98,7 @@ memtx_tree_data_identical(const struct memtx_tree_data *a,
#undef BPS_TREE_COMPARE
#undef BPS_TREE_COMPARE_KEY
#undef BPS_TREE_IDENTICAL
+#undef BPS_TREE_NO_DEBUG
#undef bps_tree_elem_t
#undef bps_tree_key_t
#undef bps_tree_arg_t
@@ -591,13 +593,15 @@ memtx_tree_index_replace(struct index *base, struct tuple *old_tuple,
static int
memtx_tree_index_replace_multikey_one(struct memtx_tree_index *index,
struct tuple *old_tuple, struct tuple *new_tuple,
- enum dup_replace_mode mode, int multikey_idx,
- struct tuple **replaced_tuple)
+ enum dup_replace_mode mode, hint_t hint,
+ struct memtx_tree_data *replaced_data,
+ bool *is_multikey_conflict)
{
struct memtx_tree_data new_data, dup_data;
new_data.tuple = new_tuple;
- new_data.hint = multikey_idx;
+ new_data.hint = hint;
dup_data.tuple = NULL;
+ *is_multikey_conflict = false;
if (memtx_tree_insert(&index->tree, new_data, &dup_data) != 0) {
diag_set(OutOfMemory, MEMTX_EXTENT_SIZE, "memtx_tree_index",
"replace");
@@ -610,7 +614,7 @@ memtx_tree_index_replace_multikey_one(struct memtx_tree_index *index,
* times, the previous key occurrence is pushed
* out of the index.
*/
- dup_data.tuple = NULL;
+ *is_multikey_conflict = true;
} else if ((errcode = replace_check_dup(old_tuple, dup_data.tuple,
mode)) != 0) {
/* Rollback replace. */
@@ -624,7 +628,7 @@ memtx_tree_index_replace_multikey_one(struct memtx_tree_index *index,
}
return -1;
}
- *replaced_tuple = dup_data.tuple;
+ *replaced_data = dup_data;
return 0;
}
@@ -681,16 +685,19 @@ memtx_tree_index_replace_multikey(struct index *base, struct tuple *old_tuple,
tuple_multikey_count(new_tuple, cmp_def);
for (; (uint32_t) multikey_idx < multikey_count;
multikey_idx++) {
- struct tuple *replaced_tuple;
+ bool is_multikey_conflict;
+ struct memtx_tree_data replaced_data;
err = memtx_tree_index_replace_multikey_one(index,
old_tuple, new_tuple, mode,
- multikey_idx, &replaced_tuple);
+ multikey_idx, &replaced_data,
+ &is_multikey_conflict);
if (err != 0)
break;
- if (replaced_tuple != NULL) {
+ if (replaced_data.tuple != NULL &&
+ !is_multikey_conflict) {
assert(*result == NULL ||
- *result == replaced_tuple);
- *result = replaced_tuple;
+ *result == replaced_data.tuple);
+ *result = replaced_data.tuple;
}
}
if (err != 0) {
--
2.22.0
next prev parent reply other threads:[~2019-07-24 7:36 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-24 7:36 [PATCH v4 0/4] box: functional indexes Kirill Shcherbatov
2019-07-24 7:36 ` [PATCH v4 1/4] box: introduce tuple_chunk infrastructure Kirill Shcherbatov
2019-07-24 7:36 ` Kirill Shcherbatov [this message]
2019-07-24 19:24 ` [PATCH v4 2/4] box: generalize memtx_multikey_tree methods Konstantin Osipov
2019-07-24 7:36 ` [PATCH v4 3/4] box: refactor memtx_tree_delete_identical Kirill Shcherbatov
2019-07-24 19:24 ` Konstantin Osipov
2019-07-24 7:36 ` [PATCH v4 4/4] box: introduce functional indexes Kirill Shcherbatov
2019-07-24 12:24 ` [tarantool-patches] " Kirill Shcherbatov
2019-07-24 19:41 ` Konstantin Osipov
2019-07-24 20:04 ` Konstantin Osipov
2019-07-24 20:22 ` Konstantin Osipov
2019-07-25 11:20 ` [tarantool-patches] " Kirill Shcherbatov
2019-07-24 20:44 ` Konstantin Osipov
2019-07-25 11:22 ` [tarantool-patches] " Kirill Shcherbatov
2019-07-24 21:07 ` Konstantin Osipov
2019-07-25 8:27 ` [tarantool-patches] " Kirill Shcherbatov
2019-07-25 8:40 ` Konstantin Osipov
2019-07-25 11:18 ` Kirill Shcherbatov
2019-07-24 21:17 ` Konstantin Osipov
2019-07-24 21:56 ` Konstantin Osipov
2019-07-25 8:33 ` [tarantool-patches] " Kirill Shcherbatov
2019-07-24 12:25 ` [tarantool-patches] [PATCH v4 4/5] box: fix memtx_tree_index_build_array_deduplicate 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=fcbb74f62fcef8d81ad05f29ed9e78da5c73653e.1563953154.git.kshcherbatov@tarantool.org \
--to=kshcherbatov@tarantool.org \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=vdavydov.dev@gmail.com \
--subject='Re: [PATCH v4 2/4] box: generalize memtx_multikey_tree methods' \
/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