From: Sergey Ostanevich <sergos@tarantool.org>
To: Ilya Kosarev <i.kosarev@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v5 3/8] refactoring: recombine error conditions in triggers
Date: Wed, 27 Nov 2019 16:28:47 +0300 [thread overview]
Message-ID: <20191127132847.GC1718@tarantool.org> (raw)
In-Reply-To: <e490c59c76be29147baa758123dfe282a79fddec.1574390065.git.i.kosarev@tarantool.org>
Hi!
LGTM
Sergos
On 22 Nov 05:46, Ilya Kosarev wrote:
> Some error conditions in triggers and underlying functions were
> combined to look better. On the other hand, in
> on_replace_dd_fk_constraint we now return an error immediately if
> child space were not found instead of searching for both child and
> parent spaces before search results inspection.
>
> Part of #4247
> ---
> src/box/alter.cc | 35 +++++++++++++++--------------------
> 1 file changed, 15 insertions(+), 20 deletions(-)
>
> diff --git a/src/box/alter.cc b/src/box/alter.cc
> index 16e3f7d37..aaaf53493 100644
> --- a/src/box/alter.cc
> +++ b/src/box/alter.cc
> @@ -3621,9 +3621,8 @@ on_replace_dd_collation(struct trigger * /* trigger */, void *event)
> int
> priv_def_create_from_tuple(struct priv_def *priv, struct tuple *tuple)
> {
> - if (tuple_field_u32(tuple, BOX_PRIV_FIELD_ID, &(priv->grantor_id)) != 0)
> - return -1;
> - if (tuple_field_u32(tuple, BOX_PRIV_FIELD_UID, &(priv->grantee_id)) != 0)
> + if (tuple_field_u32(tuple, BOX_PRIV_FIELD_ID, &(priv->grantor_id)) != 0 ||
> + tuple_field_u32(tuple, BOX_PRIV_FIELD_UID, &(priv->grantee_id)) != 0)
> return -1;
>
> const char *object_type =
> @@ -3882,9 +3881,8 @@ modify_priv(struct trigger *trigger, void *event)
> (void) event;
> struct tuple *tuple = (struct tuple *)trigger->data;
> struct priv_def priv;
> - if (priv_def_create_from_tuple(&priv, tuple) != 0)
> - return -1;
> - if (grant_or_revoke(&priv) != 0)
> + if (priv_def_create_from_tuple(&priv, tuple) != 0 ||
> + grant_or_revoke(&priv) != 0)
> return -1;
> return 0;
> }
> @@ -3903,11 +3901,9 @@ on_replace_dd_priv(struct trigger * /* trigger */, void *event)
> struct priv_def priv;
>
> if (new_tuple != NULL && old_tuple == NULL) { /* grant */
> - if (priv_def_create_from_tuple(&priv, new_tuple) != 0)
> - return -1;
> - if (priv_def_check(&priv, PRIV_GRANT) != 0)
> - return -1;
> - if (grant_or_revoke(&priv) != 0)
> + if (priv_def_create_from_tuple(&priv, new_tuple) != 0 ||
> + priv_def_check(&priv, PRIV_GRANT) != 0 ||
> + grant_or_revoke(&priv) != 0)
> return -1;
> struct trigger *on_rollback =
> txn_alter_trigger_new(revoke_priv, new_tuple);
> @@ -3916,9 +3912,8 @@ on_replace_dd_priv(struct trigger * /* trigger */, void *event)
> txn_stmt_on_rollback(stmt, on_rollback);
> } else if (new_tuple == NULL) { /* revoke */
> assert(old_tuple);
> - if (priv_def_create_from_tuple(&priv, old_tuple) != 0)
> - return -1;
> - if (priv_def_check(&priv, PRIV_REVOKE) != 0)
> + if (priv_def_create_from_tuple(&priv, old_tuple) != 0 ||
> + priv_def_check(&priv, PRIV_REVOKE) != 0)
> return -1;
> priv.access = 0;
> if (grant_or_revoke(&priv) != 0)
> @@ -3929,11 +3924,9 @@ on_replace_dd_priv(struct trigger * /* trigger */, void *event)
> return -1;
> txn_stmt_on_rollback(stmt, on_rollback);
> } else { /* modify */
> - if (priv_def_create_from_tuple(&priv, new_tuple) != 0)
> - return -1;
> - if (priv_def_check(&priv, PRIV_GRANT) != 0)
> - return -1;
> - if (grant_or_revoke(&priv) != 0)
> + if (priv_def_create_from_tuple(&priv, new_tuple) != 0 ||
> + priv_def_check(&priv, PRIV_GRANT) != 0 ||
> + grant_or_revoke(&priv) != 0)
> return -1;
> struct trigger *on_rollback =
> txn_alter_trigger_new(modify_priv, old_tuple);
> @@ -5264,8 +5257,10 @@ on_replace_dd_fk_constraint(struct trigger * /* trigger*/, void *event)
> return -1;
> auto fk_def_guard = make_scoped_guard([=] { free(fk_def); });
> struct space *child_space = space_cache_find(fk_def->child_id);
> + if (child_space == NULL)
> + return -1;
> struct space *parent_space = space_cache_find(fk_def->parent_id);
> - if (child_space == NULL or parent_space == NULL)
> + if (parent_space == NULL)
> return -1;
> struct fk_constraint *old_fk=
> fk_constraint_remove(&child_space->child_fk_constraint,
> --
> 2.17.1
>
next prev parent reply other threads:[~2019-11-27 13:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-22 2:46 [Tarantool-patches] [PATCH v5 0/8] refactoring: remove exceptions from triggers follow-ups Ilya Kosarev
2019-11-22 2:46 ` [Tarantool-patches] [PATCH v5 1/8] refactoring: wrap new operator calls in triggers Ilya Kosarev
2019-11-26 15:07 ` Sergey Ostanevich
2019-11-22 2:46 ` [Tarantool-patches] [PATCH v5 2/8] refactoring: specify struct name in allocation diagnostics Ilya Kosarev
2019-11-27 13:25 ` Sergey Ostanevich
2019-11-22 2:46 ` [Tarantool-patches] [PATCH v5 3/8] refactoring: recombine error conditions in triggers Ilya Kosarev
2019-11-27 13:28 ` Sergey Ostanevich [this message]
2019-11-22 2:46 ` [Tarantool-patches] [PATCH v5 4/8] refactoring: set diagnostics if sequence_by_id fails Ilya Kosarev
2019-11-27 13:40 ` Sergey Ostanevich
2019-11-22 2:46 ` [Tarantool-patches] [PATCH v5 5/8] refactoring: clear triggers from fresh exceptions Ilya Kosarev
2019-11-27 14:59 ` Sergey Ostanevich
2019-11-22 2:46 ` [Tarantool-patches] [PATCH v5 6/8] refactoring: update comment for index_def_check_tuple Ilya Kosarev
2019-11-27 14:59 ` Sergey Ostanevich
2019-11-22 2:46 ` [Tarantool-patches] [PATCH v5 7/8] refactoring: remove redundant line in txn_alter_trigger_new Ilya Kosarev
2019-11-27 15:00 ` Sergey Ostanevich
2019-11-22 2:46 ` [Tarantool-patches] [PATCH v5 8/8] refactoring: remove try..catch wrapper around trigger->run Ilya Kosarev
2019-11-27 15:01 ` Sergey Ostanevich
2019-12-02 7:41 ` [Tarantool-patches] [PATCH v5 0/8] refactoring: remove exceptions from triggers follow-ups Kirill Yukhin
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=20191127132847.GC1718@tarantool.org \
--to=sergos@tarantool.org \
--cc=i.kosarev@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v5 3/8] refactoring: recombine error conditions in triggers' \
/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