From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH 5/6] space: call before_replace trigger even if space has no indexes
Date: Fri, 20 Jul 2018 20:43:34 +0300 [thread overview]
Message-ID: <35469846b9a1e53af007f600a120c716478d253b.1532107326.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1532107326.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1532107326.git.vdavydov.dev@gmail.com>
Needed for blackhole spaces (see the next patch), which don't support
indexes per se, but still may have a before_replace trigger installed.
---
src/box/space.c | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/box/space.c b/src/box/space.c
index fc59dbe3..871cc670 100644
--- a/src/box/space.c
+++ b/src/box/space.c
@@ -269,23 +269,20 @@ static int
space_before_replace(struct space *space, struct txn *txn,
struct request *request)
{
- if (space->index_count == 0) {
- /* Empty space, nothing to do. */
- return 0;
- }
-
struct region *gc = &fiber()->gc;
enum iproto_type type = request->type;
- struct index *pk = space->index[0];
+ struct index *pk = space_index(space, 0);
- const char *key;
- uint32_t part_count;
- struct index *index;
+ const char *key = NULL;
+ uint32_t part_count = 0;
+ struct index *index = NULL;
/*
* Lookup the old tuple.
*/
- if (type == IPROTO_UPDATE || type == IPROTO_DELETE) {
+ switch (type) {
+ case IPROTO_UPDATE:
+ case IPROTO_DELETE:
index = index_find_unique(space, request->index_id);
if (index == NULL)
return -1;
@@ -294,21 +291,27 @@ space_before_replace(struct space *space, struct txn *txn,
if (exact_key_validate(index->def->key_def,
key, part_count) != 0)
return -1;
- } else if (type == IPROTO_INSERT || type == IPROTO_REPLACE ||
- type == IPROTO_UPSERT) {
+ break;
+ case IPROTO_INSERT:
+ case IPROTO_REPLACE:
+ case IPROTO_UPSERT:
+ if (pk == NULL)
+ break;
index = pk;
key = tuple_extract_key_raw(request->tuple, request->tuple_end,
index->def->key_def, NULL);
if (key == NULL)
return -1;
part_count = mp_decode_array(&key);
- } else {
+ break;
+ default:
/* Unknown request type, nothing to do. */
return 0;
}
- struct tuple *old_tuple;
- if (index_get(index, key, part_count, &old_tuple) != 0)
+ struct tuple *old_tuple = NULL;
+ if (index != NULL &&
+ index_get(index, key, part_count, &old_tuple) != 0)
return -1;
/*
@@ -419,7 +422,8 @@ space_before_replace(struct space *space, struct txn *txn,
* We don't allow to change the value of the primary key
* in the same statement.
*/
- if (request_changed && old_tuple != NULL && new_tuple != NULL &&
+ if (pk != NULL && request_changed &&
+ old_tuple != NULL && new_tuple != NULL &&
tuple_compare(old_tuple, new_tuple, pk->def->key_def) != 0) {
diag_set(ClientError, ER_CANT_UPDATE_PRIMARY_KEY,
pk->def->name, space->def->name);
--
2.11.0
next prev parent reply other threads:[~2018-07-20 17:43 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-20 17:43 [PATCH 0/6] Introduce blackhole engine Vladimir Davydov
2018-07-20 17:43 ` [PATCH 1/6] Add generic engine, space, index method stubs Vladimir Davydov
2018-07-20 17:56 ` Konstantin Osipov
2018-07-21 12:24 ` Vladimir Davydov
2018-07-20 17:43 ` [PATCH 2/6] Merge sysview_index.[hc] and sysview_engine.[hc] Vladimir Davydov
2018-07-20 18:02 ` Konstantin Osipov
2018-07-21 12:24 ` Vladimir Davydov
2018-07-20 17:43 ` [PATCH 3/6] Rework memtx replace function Vladimir Davydov
2018-07-20 18:04 ` Konstantin Osipov
2018-07-21 12:24 ` Vladimir Davydov
2018-07-20 17:43 ` [PATCH 4/6] txn: unify txn_stmt tuples reference counting rules Vladimir Davydov
2018-07-20 18:31 ` Konstantin Osipov
2018-07-21 12:24 ` Vladimir Davydov
2018-07-20 17:43 ` Vladimir Davydov [this message]
2018-07-20 18:39 ` [PATCH 5/6] space: call before_replace trigger even if space has no indexes Konstantin Osipov
2018-07-21 12:26 ` Vladimir Davydov
2018-07-21 20:59 ` Konstantin Osipov
2018-07-23 10:15 ` Vladimir Davydov
2018-07-20 17:43 ` [PATCH 6/6] Introduce blackhole engine Vladimir Davydov
2018-07-20 18:42 ` Konstantin Osipov
2018-07-21 12:35 ` Vladimir Davydov
2018-07-23 11:02 ` Vladimir Davydov
2018-07-23 12:53 ` Vladimir Davydov
2018-07-23 18:30 ` [PATCH 0/6] " Konstantin Osipov
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=35469846b9a1e53af007f600a120c716478d253b.1532107326.git.vdavydov.dev@gmail.com \
--to=vdavydov.dev@gmail.com \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH 5/6] space: call before_replace trigger even if space has no indexes' \
/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