From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 3792E3053A for ; Thu, 29 Nov 2018 13:41:18 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RNAzgp0H6ht0 for ; Thu, 29 Nov 2018 13:41:18 -0500 (EST) Received: from smtp5.mail.ru (smtp5.mail.ru [94.100.179.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id A5B902FBD7 for ; Thu, 29 Nov 2018 13:41:14 -0500 (EST) Subject: [tarantool-patches] Re: [PATCH v1 6/6] sql: make sql checks on server side References: From: Kirill Shcherbatov Message-ID: Date: Thu, 29 Nov 2018 21:41:12 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, Vladislav Shpilevoy 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;