From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org,
Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v1 6/6] sql: make sql checks on server side
Date: Thu, 29 Nov 2018 21:41:12 +0300 [thread overview]
Message-ID: <b23ee603-a33d-f5c3-07d3-7a65b4901b83@tarantool.org> (raw)
In-Reply-To: <d363c1ceb0f93b9c3457c373042edad6a5138443.1543496928.git.kshcherbatov@tarantool.org>
Working with Functional Indexes patch I've found this problem here.
Believe that space trigger should not be a part of DDL logic
diff --git a/src/box/alter.cc b/src/box/alter.cc
index aa75457ac..8226d7624 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -1408,33 +1408,6 @@ on_drop_space_rollback(struct trigger *trigger, void *event)
space_cache_replace(NULL, space);
}
-/**
- * SQL-specific actions for space.
- */
-static void
-on_space_before_replace(struct trigger *trigger, void *event)
-{
- uint32_t space_id = (uint32_t)(uintptr_t)trigger->data;
- struct space *space = space_cache_find(space_id);
- assert(space != NULL);
- struct txn *txn = (struct txn *) event;
- struct txn_stmt *stmt = txn_current_stmt(txn);
- if (stmt == NULL)
- return;
- struct tuple *new_tuple = stmt->new_tuple;
- struct tuple *old_tuple = stmt->old_tuple;
- if (new_tuple != NULL && space->sql_checks != NULL) {
- const char *new_tuple_raw = tuple_data(new_tuple);
- const char *old_tuple_raw = old_tuple != NULL ?
- tuple_data(old_tuple) : NULL;
- if (sql_checks_run(space->sql_checks,
- space->def->opts.checks_ast, space->def,
- old_tuple_raw, new_tuple_raw) != 0) {
- diag_raise();
- }
- }
-}
-
/**
* Run the triggers registered on commit of a change in _space.
*/
@@ -1753,21 +1726,6 @@ on_replace_dd_space(struct trigger * /* trigger */, void *event)
txn_on_rollback(txn, on_rollback_view);
select_guard.is_active = false;
}
- /* Setup SQL-actions trigger if required. */
- if (def->opts.checks_ast != NULL) {
- struct trigger *sql_actions_trigger =
- (struct trigger *)malloc(sizeof(struct trigger));
- if (sql_actions_trigger == NULL) {
- tnt_raise(OutOfMemory, sizeof(struct trigger),
- "calloc",
- "on_space_before_replace");
- }
- trigger_create(sql_actions_trigger,
- on_space_before_replace,
- (void *)(uintptr_t)space->def->id,
- (trigger_f0)free);
- trigger_add(&space->before_replace, sql_actions_trigger);
- }
} else if (new_tuple == NULL) { /* DELETE */
access_check_ddl(old_space->def->name, old_space->def->id,
old_space->def->uid, SC_SPACE, PRIV_D);
diff --git a/src/box/space.c b/src/box/space.c
index 6da0e6e9a..b139a0905 100644
--- a/src/box/space.c
+++ b/src/box/space.c
@@ -109,6 +109,33 @@ space_fill_index_map(struct space *space)
}
}
+/**
+ * SQL-specific actions for space.
+ */
+static void
+on_space_before_replace(struct trigger *trigger, void *event)
+{
+ uint32_t space_id = (uint32_t)(uintptr_t)trigger->data;
+ struct space *space = space_cache_find(space_id);
+ assert(space != NULL);
+ struct txn *txn = (struct txn *) event;
+ struct txn_stmt *stmt = txn_current_stmt(txn);
+ if (stmt == NULL)
+ return;
+ struct tuple *new_tuple = stmt->new_tuple;
+ struct tuple *old_tuple = stmt->old_tuple;
+ if (new_tuple != NULL && space->sql_checks != NULL) {
+ const char *new_tuple_raw = tuple_data(new_tuple);
+ const char *old_tuple_raw = old_tuple != NULL ?
+ tuple_data(old_tuple) : NULL;
+ if (sql_checks_run(space->sql_checks,
+ space->def->opts.checks_ast, space->def,
+ old_tuple_raw, new_tuple_raw) != 0) {
+ diag_raise();
+ }
+ }
+}
+
int
space_create(struct space *space, struct engine *engine,
const struct space_vtab *vtab, struct space_def *def,
@@ -172,6 +199,18 @@ space_create(struct space *space, struct engine *engine,
if (unlikely(checks == NULL))
goto fail_free_indexes;
space->sql_checks = checks;
+
+ struct trigger *sql_actions_trigger =
+ (struct trigger *)malloc(sizeof(struct trigger));
+ if (sql_actions_trigger == NULL) {
+ diag_set(OutOfMemory, sizeof(struct trigger),
+ "calloc", "on_space_before_replace");
+ goto fail_free_indexes;
+ }
+ trigger_create(sql_actions_trigger, on_space_before_replace,
+ (void *)(uintptr_t)space->def->id,
+ (trigger_f0)free);
+ trigger_add(&space->before_replace, sql_actions_trigger);
}
return 0;
prev parent reply other threads:[~2018-11-29 18:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-29 13:09 [tarantool-patches] [PATCH v1 0/6] sql: Checks " Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 1/6] box: rename space->opts checks to checks_ast Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 2/6] sql: disallow use of TYPEOF in Check Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 3/6] box: exported sql_bind structure and API Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 4/6] sql: release OP_Idx{Insert,Replace} p2 argument Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 5/6] sql: fix incomplete UPDATE on IdxInsert failured Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 6/6] sql: make sql checks on server side Kirill Shcherbatov
2018-11-29 14:09 ` [tarantool-patches] " Kirill Shcherbatov
2018-11-29 18:41 ` Kirill Shcherbatov [this message]
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=b23ee603-a33d-f5c3-07d3-7a65b4901b83@tarantool.org \
--to=kshcherbatov@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='[tarantool-patches] Re: [PATCH v1 6/6] sql: make sql checks on server side' \
/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