From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Kirill Shcherbatov Subject: [PATCH v3 2/4] box: refactor key_validate_parts to return key_end Date: Wed, 17 Jul 2019 04:20:43 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: kostja@tarantool.org, Kirill Shcherbatov List-ID: 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