From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH 03/10] ddl: synchronize func cache with actual data state
Date: Wed, 3 Jul 2019 22:30:05 +0300 [thread overview]
Message-ID: <7e73a91adcc4d51e0a57887d157e4b448466be9f.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.
---
src/box/alter.cc | 40 +++++++++++++++++++++++++++++++---------
test/box/function1.result | 34 ++++++++++++++++++++++++++++++++++
test/box/function1.test.lua | 13 +++++++++++++
3 files changed, 78 insertions(+), 9 deletions(-)
diff --git a/src/box/alter.cc b/src/box/alter.cc
index cc057298..062cf9f8 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -2587,14 +2587,31 @@ func_def_new_from_tuple(struct tuple *tuple)
return def;
}
-/** Remove a function from function cache */
static void
-func_cache_remove_func(struct trigger *trigger, void * /* event */)
+on_create_func_rollback(struct trigger *trigger, void * /* event */)
{
- struct func *old_func = (struct func *) trigger->data;
- func_cache_delete(old_func->def->fid);
- trigger_run_xc(&on_alter_func, old_func);
- func_delete(old_func);
+ /* Remove the new function from the cache and delete it. */
+ struct func *func = (struct func *)trigger->data;
+ func_cache_delete(func->def->fid);
+ trigger_run_xc(&on_alter_func, func);
+ func_delete(func);
+}
+
+static void
+on_drop_func_commit(struct trigger *trigger, void * /* event */)
+{
+ /* Delete the old function. */
+ struct func *func = (struct func *)trigger->data;
+ func_delete(func);
+}
+
+static void
+on_drop_func_rollback(struct trigger *trigger, void * /* event */)
+{
+ /* Insert the old function back into the cache. */
+ struct func *func = (struct func *)trigger->data;
+ func_cache_insert(func);
+ trigger_run_xc(&on_alter_func, func);
}
/**
@@ -2619,15 +2636,15 @@ on_replace_dd_func(struct trigger * /* trigger */, void *event)
access_check_ddl(def->name, def->fid, def->uid, SC_FUNCTION,
PRIV_C);
struct trigger *on_rollback =
- txn_alter_trigger_new(func_cache_remove_func, NULL);
+ txn_alter_trigger_new(on_create_func_rollback, NULL);
struct func *func = func_new(def);
if (func == NULL)
diag_raise();
def_guard.is_active = false;
func_cache_insert(func);
on_rollback->data = func;
+ txn_on_rollback(txn, on_rollback);
trigger_run_xc(&on_alter_func, func);
- txn_on_rollback(txn, on_rollback);
} else if (new_tuple == NULL) { /* DELETE */
uint32_t uid;
func_def_get_ids_from_tuple(old_tuple, &fid, &uid);
@@ -2644,8 +2661,13 @@ on_replace_dd_func(struct trigger * /* trigger */, void *event)
"function has grants");
}
struct trigger *on_commit =
- txn_alter_trigger_new(func_cache_remove_func, old_func);
+ txn_alter_trigger_new(on_drop_func_commit, old_func);
+ struct trigger *on_rollback =
+ txn_alter_trigger_new(on_drop_func_rollback, old_func);
+ func_cache_delete(old_func->def->fid);
txn_on_commit(txn, on_commit);
+ txn_on_rollback(txn, on_rollback);
+ trigger_run_xc(&on_alter_func, old_func);
} else { /* UPDATE, REPLACE */
assert(new_tuple != NULL && old_tuple != NULL);
/**
diff --git a/test/box/function1.result b/test/box/function1.result
index 439e19e9..ec1ab5e6 100644
--- a/test/box/function1.result
+++ b/test/box/function1.result
@@ -530,3 +530,37 @@ test_run:cmd("clear filter")
---
- true
...
+--
+-- Check that function cache is updated synchronously with _func changes.
+--
+box.begin() box.schema.func.create('test') f = box.func.test box.rollback()
+---
+...
+f ~= nil
+---
+- true
+...
+box.func.test == nil
+---
+- true
+...
+box.schema.func.create('test')
+---
+...
+f = box.func.test
+---
+...
+box.begin() box.space._func:delete{f.id} f = box.func.test box.rollback()
+---
+...
+f == nil
+---
+- true
+...
+box.func.test ~= nil
+---
+- true
+...
+box.func.test:drop()
+---
+...
diff --git a/test/box/function1.test.lua b/test/box/function1.test.lua
index 4ec9c04a..a891e192 100644
--- a/test/box/function1.test.lua
+++ b/test/box/function1.test.lua
@@ -185,3 +185,16 @@ box.schema.func.drop('secret_leak')
box.schema.func.drop('secret')
test_run:cmd("clear filter")
+
+--
+-- Check that function cache is updated synchronously with _func changes.
+--
+box.begin() box.schema.func.create('test') f = box.func.test box.rollback()
+f ~= nil
+box.func.test == nil
+box.schema.func.create('test')
+f = box.func.test
+box.begin() box.space._func:delete{f.id} f = box.func.test box.rollback()
+f == nil
+box.func.test ~= nil
+box.func.test:drop()
--
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 ` [PATCH 02/10] ddl: synchronize user cache with actual data state Vladimir Davydov
2019-07-03 19:43 ` Konstantin Osipov
2019-07-03 20:00 ` Vladimir Davydov
2019-07-04 7:42 ` [tarantool-patches] " Konstantin Osipov
2019-07-03 19:30 ` Vladimir Davydov [this message]
2019-07-04 8:12 ` [PATCH 03/10] ddl: synchronize func " 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=7e73a91adcc4d51e0a57887d157e4b448466be9f.1562181197.git.vdavydov.dev@gmail.com \
--to=vdavydov.dev@gmail.com \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH 03/10] ddl: synchronize func 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