From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: kostja@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [PATCH v3 2/4] box: refactor key_validate_parts to return key_end Date: Wed, 17 Jul 2019 04:20:43 +0300 [thread overview] Message-ID: <d8cbbfe681f8daa0f75510b4875282035994a98a.1563326037.git.kshcherbatov@tarantool.org> (raw) In-Reply-To: <cover.1563326037.git.kshcherbatov@tarantool.org> The key_validate_parts helper is refactored to return a pointer to the end of a given key argument in case of success. This is required to effectively validate a sequence of keys in scope of functional multikey indexes. Needed for #1260 --- src/box/index.cc | 6 ++++-- src/box/key_def.c | 4 +++- src/box/key_def.h | 4 +++- src/box/lua/key_def.c | 5 +++-- src/box/vinyl.c | 4 +++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/box/index.cc b/src/box/index.cc index 7f26c9bc2..843d0e73d 100644 --- a/src/box/index.cc +++ b/src/box/index.cc @@ -126,8 +126,9 @@ key_validate(const struct index_def *index_def, enum iterator_type type, part_count); return -1; } + const char *key_end; if (key_validate_parts(index_def->key_def, key, - part_count, true) != 0) + part_count, true, &key_end) != 0) return -1; } return 0; @@ -143,7 +144,8 @@ exact_key_validate(struct key_def *key_def, const char *key, part_count); return -1; } - return key_validate_parts(key_def, key, part_count, false); + const char *key_end; + return key_validate_parts(key_def, key, part_count, false, &key_end); } char * diff --git a/src/box/key_def.c b/src/box/key_def.c index 2aa095091..ee758eefa 100644 --- a/src/box/key_def.c +++ b/src/box/key_def.c @@ -834,7 +834,8 @@ out: int key_validate_parts(const struct key_def *key_def, const char *key, - uint32_t part_count, bool allow_nullable) + uint32_t part_count, bool allow_nullable, + const char **key_end) { for (uint32_t i = 0; i < part_count; i++) { const struct key_part *part = &key_def->parts[i]; @@ -844,5 +845,6 @@ key_validate_parts(const struct key_def *key_def, const char *key, return -1; mp_next(&key); } + *key_end = key; return 0; } diff --git a/src/box/key_def.h b/src/box/key_def.h index ab4b7c087..df83d055c 100644 --- a/src/box/key_def.h +++ b/src/box/key_def.h @@ -443,13 +443,15 @@ key_def_find_pk_in_cmp_def(const struct key_def *cmp_def, * @param key MessagePack'ed data for matching. * @param part_count Field count in the key. * @param allow_nullable True if nullable parts are allowed. + * @param key_end[out] The end of the validated key. * * @retval 0 The key is valid. * @retval -1 The key is invalid. */ int key_validate_parts(const struct key_def *key_def, const char *key, - uint32_t part_count, bool allow_nullable); + uint32_t part_count, bool allow_nullable, + const char **key_end); /** * Return true if @a index_def defines a sequential key without diff --git a/src/box/lua/key_def.c b/src/box/lua/key_def.c index 052a1c85d..041b5ec98 100644 --- a/src/box/lua/key_def.c +++ b/src/box/lua/key_def.c @@ -338,9 +338,10 @@ lbox_key_def_compare_with_key(struct lua_State *L) struct region *region = &fiber()->gc; size_t region_svp = region_used(region); size_t key_len; - const char *key = lbox_encode_tuple_on_gc(L, 3, &key_len); + const char *key_end, *key = lbox_encode_tuple_on_gc(L, 3, &key_len); uint32_t part_count = mp_decode_array(&key); - if (key_validate_parts(key_def, key, part_count, true) != 0) { + if (key_validate_parts(key_def, key, part_count, true, + &key_end) != 0) { region_truncate(region, region_svp); tuple_unref(tuple); return luaT_error(L); diff --git a/src/box/vinyl.c b/src/box/vinyl.c index f68958ba1..cf7af26b7 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -1751,7 +1751,9 @@ vy_unique_key_validate(struct vy_lsm *lsm, const char *key, original_part_count, part_count); return -1; } - return key_validate_parts(lsm->cmp_def, key, part_count, false); + const char *key_end; + return key_validate_parts(lsm->cmp_def, key, part_count, false, + &key_end); } /** -- 2.22.0
next prev parent reply other threads:[~2019-07-17 1:20 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-07-17 1:20 [PATCH v3 0/4] box: functional indexes Kirill Shcherbatov 2019-07-17 1:20 ` [PATCH v3 1/4] box: introduce key_def->is_multikey flag Kirill Shcherbatov 2019-07-17 14:34 ` Konstantin Osipov 2019-07-18 11:20 ` [tarantool-patches] " Kirill Yukhin 2019-07-17 1:20 ` Kirill Shcherbatov [this message] 2019-07-18 9:41 ` [PATCH v3 2/4] box: refactor key_validate_parts to return key_end Konstantin Osipov 2019-07-18 11:21 ` [tarantool-patches] " Kirill Yukhin 2019-07-17 1:20 ` [PATCH v3 3/4] box: introduce tuple_extra infrastructure Kirill Shcherbatov 2019-07-18 9:47 ` Konstantin Osipov 2019-07-17 1:20 ` [PATCH v3 4/4] box: introduce functional indexes in memtx Kirill Shcherbatov 2019-07-18 9:50 ` [tarantool-patches] " Konstantin Osipov 2019-07-18 9:54 ` Konstantin Osipov 2019-07-18 9:55 ` Konstantin Osipov 2019-07-18 10:02 ` Konstantin Osipov 2019-07-22 14:45 ` 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=d8cbbfe681f8daa0f75510b4875282035994a98a.1563326037.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 v3 2/4] box: refactor key_validate_parts to return key_end' \ /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