Skip to content
Snippets Groups Projects
Commit 87fb9470 authored by Georgy Kirichenko's avatar Georgy Kirichenko Committed by Roman Tsisyk
Browse files

Disable ddl for on_replace triggers

Do not allow ddl if fired from on_replace trigger.

Fixes #1968
parent 35020149
No related branches found
No related tags found
No related merge requests found
......@@ -1150,7 +1150,7 @@ static void
on_replace_dd_space(struct trigger * /* trigger */, void *event)
{
struct txn *txn = (struct txn *) event;
txn_check_autocommit(txn, "Space _space");
txn_check_singlestatement(txn, "Space _space");
struct txn_stmt *stmt = txn_current_stmt(txn);
struct tuple *old_tuple = stmt->old_tuple;
struct tuple *new_tuple = stmt->new_tuple;
......@@ -1312,7 +1312,7 @@ static void
on_replace_dd_index(struct trigger * /* trigger */, void *event)
{
struct txn *txn = (struct txn *) event;
txn_check_autocommit(txn, "Space _index");
txn_check_singlestatement(txn, "Space _index");
struct txn_stmt *stmt = txn_current_stmt(txn);
struct tuple *old_tuple = stmt->old_tuple;
struct tuple *new_tuple = stmt->new_tuple;
......@@ -1480,7 +1480,7 @@ on_replace_dd_truncate(struct trigger * /* trigger */, void *event)
{
struct txn *txn = (struct txn *) event;
struct txn_stmt *stmt = txn_current_stmt(txn);
txn_check_autocommit(txn, "Space _truncate");
txn_check_singlestatement(txn, "Space _truncate");
struct tuple *new_tuple = stmt->new_tuple;
if (new_tuple == NULL) {
......@@ -1747,7 +1747,7 @@ on_replace_dd_user(struct trigger * /* trigger */, void *event)
{
struct txn *txn = (struct txn *) event;
struct txn_stmt *stmt = txn_current_stmt(txn);
txn_check_autocommit(txn, "Space _user");
txn_check_singlestatement(txn, "Space _user");
struct tuple *old_tuple = stmt->old_tuple;
struct tuple *new_tuple = stmt->new_tuple;
......@@ -1879,7 +1879,7 @@ static void
on_replace_dd_func(struct trigger * /* trigger */, void *event)
{
struct txn *txn = (struct txn *) event;
txn_check_autocommit(txn, "Space _func");
txn_check_singlestatement(txn, "Space _func");
struct txn_stmt *stmt = txn_current_stmt(txn);
struct tuple *old_tuple = stmt->old_tuple;
struct tuple *new_tuple = stmt->new_tuple;
......@@ -2083,7 +2083,7 @@ static void
on_replace_dd_priv(struct trigger * /* trigger */, void *event)
{
struct txn *txn = (struct txn *) event;
txn_check_autocommit(txn, "Space _priv");
txn_check_singlestatement(txn, "Space _priv");
struct txn_stmt *stmt = txn_current_stmt(txn);
struct tuple *old_tuple = stmt->old_tuple;
struct tuple *new_tuple = stmt->new_tuple;
......@@ -2129,7 +2129,7 @@ static void
on_replace_dd_schema(struct trigger * /* trigger */, void *event)
{
struct txn *txn = (struct txn *) event;
txn_check_autocommit(txn, "Space _schema");
txn_check_singlestatement(txn, "Space _schema");
struct txn_stmt *stmt = txn_current_stmt(txn);
struct tuple *old_tuple = stmt->old_tuple;
struct tuple *new_tuple = stmt->new_tuple;
......@@ -2208,7 +2208,7 @@ on_replace_dd_cluster(struct trigger *trigger, void *event)
{
(void) trigger;
struct txn *txn = (struct txn *) event;
txn_check_autocommit(txn, "Space _cluster");
txn_check_singlestatement(txn, "Space _cluster");
struct txn_stmt *stmt = txn_current_stmt(txn);
struct tuple *old_tuple = stmt->old_tuple;
struct tuple *new_tuple = stmt->new_tuple;
......
......@@ -298,9 +298,10 @@ txn_rollback()
}
void
txn_check_autocommit(struct txn *txn, const char *where)
txn_check_singlestatement(struct txn *txn, const char *where)
{
if (txn->is_autocommit == false) {
if (!txn->is_autocommit ||
stailq_last(&txn->stmts) != stailq_first(&txn->stmts)) {
tnt_raise(ClientError, ER_UNSUPPORTED,
where, "multi-statement transactions");
}
......
......@@ -218,7 +218,7 @@ txn_rollback_stmt();
* transaction and must be run in autocommit mode.
*/
void
txn_check_autocommit(struct txn *txn, const char *where);
txn_check_singlestatement(struct txn *txn, const char *where);
/** The current statement of the transaction. */
static inline struct txn_stmt *
......
......@@ -453,3 +453,79 @@ first:drop()
second:drop()
---
...
s = box.schema.space.create('test_on_repl_ddl')
---
...
_ = s:create_index('pk')
---
...
t = s:on_replace(function () box.schema.space.create('some_space') end)
---
...
s:replace({1, 2})
---
- error: Space _schema does not support multi-statement transactions
...
t = s:on_replace(function () s:create_index('sec') end, t)
---
...
s:replace({2, 3})
---
- error: Space _index does not support multi-statement transactions
...
t = s:on_replace(function () box.schema.user.create('newu') end, t)
---
...
s:replace({3, 4})
---
- error: Space _user does not support multi-statement transactions
...
t = s:on_replace(function () box.schema.role.create('newr') end, t)
---
...
s:replace({4, 5})
---
- error: Space _user does not support multi-statement transactions
...
t = s:on_replace(function () s:drop() end, t)
---
...
s:replace({5, 6})
---
- error: Space _index does not support multi-statement transactions
...
t = s:on_replace(function () box.schema.func.create('newf') end, t)
---
...
s:replace({6, 7})
---
- error: Space _func does not support multi-statement transactions
...
t = s:on_replace(function () box.schema.user.grant('guest', 'read,write', 'space', 'test_on_repl_ddl') end, t)
---
...
s:replace({7, 8})
---
- error: Space _priv does not support multi-statement transactions
...
t = s:on_replace(function () s:rename('newname') end, t)
---
...
s:replace({8, 9})
---
- error: Space _space does not support multi-statement transactions
...
t = s:on_replace(function () s.index.pk:rename('newname') end, t)
---
...
s:replace({9, 10})
---
- error: Space _index does not support multi-statement transactions
...
s:select()
---
- []
...
s:drop()
---
...
......@@ -176,3 +176,26 @@ first:on_replace(nil, trigger_id)
first:drop()
second:drop()
s = box.schema.space.create('test_on_repl_ddl')
_ = s:create_index('pk')
t = s:on_replace(function () box.schema.space.create('some_space') end)
s:replace({1, 2})
t = s:on_replace(function () s:create_index('sec') end, t)
s:replace({2, 3})
t = s:on_replace(function () box.schema.user.create('newu') end, t)
s:replace({3, 4})
t = s:on_replace(function () box.schema.role.create('newr') end, t)
s:replace({4, 5})
t = s:on_replace(function () s:drop() end, t)
s:replace({5, 6})
t = s:on_replace(function () box.schema.func.create('newf') end, t)
s:replace({6, 7})
t = s:on_replace(function () box.schema.user.grant('guest', 'read,write', 'space', 'test_on_repl_ddl') end, t)
s:replace({7, 8})
t = s:on_replace(function () s:rename('newname') end, t)
s:replace({8, 9})
t = s:on_replace(function () s.index.pk:rename('newname') end, t)
s:replace({9, 10})
s:select()
s:drop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment