From f62dbb18228e9135b1b293868c3e8ad832ceaa7f Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Tue, 4 Aug 2015 00:09:47 +0300 Subject: [PATCH] upsert: post-merge fixes Extract index_find() logic into space.h --- src/box/request.cc | 10 +++------- src/box/space.h | 9 +++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/box/request.cc b/src/box/request.cc index 3b0e35cf03..307232777e 100644 --- a/src/box/request.cc +++ b/src/box/request.cc @@ -81,9 +81,7 @@ execute_update(struct request *request, struct port *port) access_check_space(space, PRIV_W); /* Try to find the tuple by unique key. */ - Index *pk = index_find(space, request->index_id); - if (!pk->key_def->is_unique) - tnt_raise(ClientError, ER_MORE_THAN_ONE_TUPLE); + Index *pk = index_find_unique(space, request->index_id); const char *key = request->key; uint32_t part_count = mp_decode_array(&key); primary_key_validate(pk->key_def, key, part_count); @@ -123,7 +121,7 @@ execute_upsert(struct request *request, struct port * /* port */) struct txn *txn = txn_begin_stmt(request, space); access_check_space(space, PRIV_W); - Index *pk = index_find(space, 0); + Index *pk = index_find_unique(space, request->index_id); /* Try to find the tuple by primary key. */ const char *key = request->key; uint32_t part_count = mp_decode_array(&key); @@ -168,9 +166,7 @@ execute_delete(struct request *request, struct port *port) access_check_space(space, PRIV_W); /* Try to find the tuple by unique key. */ - Index *pk = index_find(space, request->index_id); - if (!pk->key_def->is_unique) - tnt_raise(ClientError, ER_MORE_THAN_ONE_TUPLE); + Index *pk = index_find_unique(space, request->index_id); const char *key = request->key; uint32_t part_count = mp_decode_array(&key); primary_key_validate(pk->key_def, key, part_count); diff --git a/src/box/space.h b/src/box/space.h index 71b5ad47b6..e3a59fd7d9 100644 --- a/src/box/space.h +++ b/src/box/space.h @@ -176,6 +176,15 @@ index_find(struct space *space, uint32_t index_id) return index; } +static inline Index * +index_find_unique(struct space *space, uint32_t index_id) +{ + Index *index = index_find(space, index_id); + if (!index->key_def->is_unique) + tnt_raise(ClientError, ER_MORE_THAN_ONE_TUPLE); + return index; +} + extern "C" void space_run_triggers(struct space *space, bool yesno); -- GitLab