From: Vladimir Davydov <vdavydov.dev@gmail.com> To: kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [PATCH 02/10] ddl: synchronize user cache with actual data state Date: Wed, 3 Jul 2019 22:30:04 +0300 [thread overview] Message-ID: <7d3e055e64ee3de2fb6486e4615849574b569bf4.1562181197.git.vdavydov.dev@gmail.com> (raw) In-Reply-To: <cover.1562181197.git.vdavydov.dev@gmail.com> In-Reply-To: <cover.1562181197.git.vdavydov.dev@gmail.com> To implement transactional DDL, we must make sure that in-memory schema is updated synchronously with system space updates, i.e. on_replace, not on_commit. See also commit 22bedebe715c ("ddl: synchronize privileges cache with actual data state"). --- src/box/alter.cc | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/box/alter.cc b/src/box/alter.cc index 7c4d949f..cc057298 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -2445,22 +2445,18 @@ user_def_new_from_tuple(struct tuple *tuple) } static void -user_cache_remove_user(struct trigger * /* trigger */, void *event) +user_cache_remove_user(struct trigger *trigger, void * /* event */) { - struct txn *txn = (struct txn *) event; - struct txn_stmt *stmt = txn_last_stmt(txn); - uint32_t uid = tuple_field_u32_xc(stmt->old_tuple ? - stmt->old_tuple : stmt->new_tuple, - BOX_USER_FIELD_ID); + struct tuple *tuple = (struct tuple *)trigger->data; + uint32_t uid = tuple_field_u32_xc(tuple, BOX_USER_FIELD_ID); user_cache_delete(uid); } static void -user_cache_alter_user(struct trigger * /* trigger */, void *event) +user_cache_alter_user(struct trigger *trigger, void * /* event */) { - struct txn *txn = (struct txn *) event; - struct txn_stmt *stmt = txn_last_stmt(txn); - struct user_def *user = user_def_new_from_tuple(stmt->new_tuple); + struct tuple *tuple = (struct tuple *)trigger->data; + struct user_def *user = user_def_new_from_tuple(tuple); auto def_guard = make_scoped_guard([=] { free(user); }); /* Can throw if, e.g. too many users. */ user_cache_replace(user); @@ -2490,7 +2486,7 @@ on_replace_dd_user(struct trigger * /* trigger */, void *event) (void) user_cache_replace(user); def_guard.is_active = false; struct trigger *on_rollback = - txn_alter_trigger_new(user_cache_remove_user, NULL); + txn_alter_trigger_new(user_cache_remove_user, new_tuple); txn_on_rollback(txn, on_rollback); } else if (new_tuple == NULL) { /* DELETE */ access_check_ddl(old_user->def->name, old_user->def->uid, @@ -2510,9 +2506,10 @@ on_replace_dd_user(struct trigger * /* trigger */, void *event) tnt_raise(ClientError, ER_DROP_USER, old_user->def->name, "the user has objects"); } - struct trigger *on_commit = - txn_alter_trigger_new(user_cache_remove_user, NULL); - txn_on_commit(txn, on_commit); + user_cache_delete(uid); + struct trigger *on_rollback = + txn_alter_trigger_new(user_cache_alter_user, old_tuple); + txn_on_rollback(txn, on_rollback); } else { /* UPDATE, REPLACE */ assert(old_user != NULL && new_tuple != NULL); /* @@ -2524,9 +2521,11 @@ on_replace_dd_user(struct trigger * /* trigger */, void *event) access_check_ddl(user->name, user->uid, user->uid, old_user->def->type, PRIV_A); auto def_guard = make_scoped_guard([=] { free(user); }); - struct trigger *on_commit = - txn_alter_trigger_new(user_cache_alter_user, NULL); - txn_on_commit(txn, on_commit); + user_cache_replace(user); + def_guard.is_active = false; + struct trigger *on_rollback = + txn_alter_trigger_new(user_cache_alter_user, old_tuple); + txn_on_rollback(txn, on_rollback); } } -- 2.11.0
next prev parent reply other threads:[~2019-07-03 19:30 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-07-03 19:30 [PATCH 00/10] Prepare box/alter.cc for transactional DDL Vladimir Davydov 2019-07-03 19:30 ` [PATCH 01/10] ddl: unreference view on space drop synchronously Vladimir Davydov 2019-07-03 19:37 ` Konstantin Osipov 2019-07-03 19:30 ` Vladimir Davydov [this message] 2019-07-03 19:43 ` [PATCH 02/10] ddl: synchronize user cache with actual data state Konstantin Osipov 2019-07-03 20:00 ` Vladimir Davydov 2019-07-04 7:42 ` [tarantool-patches] " Konstantin Osipov 2019-07-03 19:30 ` [PATCH 03/10] ddl: synchronize func " Vladimir Davydov 2019-07-04 8:12 ` Konstantin Osipov 2019-07-03 19:30 ` [PATCH 04/10] ddl: synchronize sequence " Vladimir Davydov 2019-07-04 8:16 ` Konstantin Osipov 2019-07-03 19:30 ` [PATCH 05/10] ddl: fix _space_sequence rollback Vladimir Davydov 2019-07-03 19:30 ` [PATCH 06/10] ddl: restore sequence value if drop is rolled back Vladimir Davydov 2019-07-03 19:30 ` [PATCH 07/10] ddl: don't use txn_last_stmt on _collation commit/rollback Vladimir Davydov 2019-07-03 19:30 ` [PATCH 08/10] ddl: don't use txn_last_stmt on _trigger commit/rollback Vladimir Davydov 2019-07-03 19:30 ` [PATCH 09/10] ddl: don't use txn_last_stmt on _ck_constraint commit/rollback Vladimir Davydov 2019-07-03 19:30 ` [PATCH 10/10] ddl: don't use txn_last_stmt on _cluster commit/rollback Vladimir Davydov 2019-07-04 15:01 ` [PATCH 00/10] Prepare box/alter.cc for transactional DDL Vladimir Davydov
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=7d3e055e64ee3de2fb6486e4615849574b569bf4.1562181197.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH 02/10] ddl: synchronize user cache with actual data state' \ /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