diff --git a/src/box/engine.h b/src/box/engine.h index e10eaec445850553048bb2eb5b7f3e351e547d07..5b96c744de8944a506f706517ecb38e24f02d35d 100644 --- a/src/box/engine.h +++ b/src/box/engine.h @@ -190,6 +190,16 @@ struct engine_vtab { int (*check_space_def)(struct space_def *); }; +enum { + /** + * If set, the engine will not participate in transaction + * control. In particular, this means that any operations + * done on this engine's spaces can mix in other engine's + * transactions w/o throwing ER_CROSS_ENGINE_TRANSACTION. + */ + ENGINE_BYPASS_TX = 1 << 0, +}; + struct engine { /** Virtual function table. */ const struct engine_vtab *vtab; @@ -197,6 +207,8 @@ struct engine { const char *name; /** Engine id. */ uint32_t id; + /** Engine flags. */ + uint32_t flags; /** Used for search for engine by name. */ struct rlist link; }; diff --git a/src/box/sysview.c b/src/box/sysview.c index fb4ecf2d54d752a619984bb38e3553f381065b77..a636c686e0af508649694304278a9777d8d58731 100644 --- a/src/box/sysview.c +++ b/src/box/sysview.c @@ -557,5 +557,6 @@ sysview_engine_new(void) sysview->base.vtab = &sysview_engine_vtab; sysview->base.name = "sysview"; + sysview->base.flags = ENGINE_BYPASS_TX; return sysview; } diff --git a/src/box/txn.c b/src/box/txn.c index fbce612a5103780b5d32e1579cc878bf962f9068..8947ac35c4239d9bf8aaebfbf92a60d9e667b85e 100644 --- a/src/box/txn.c +++ b/src/box/txn.c @@ -116,16 +116,15 @@ txn_rollback_to_svp(struct txn *txn, struct stailq_entry *svp) stailq_cut_tail(&txn->stmts, svp, &rollback); stailq_reverse(&rollback); stailq_foreach_entry(stmt, &rollback, next) { - if (stmt->space != NULL) { + if (txn->engine != NULL && stmt->space != NULL) engine_rollback_statement(txn->engine, txn, stmt); - stmt->space = NULL; - } if (stmt->row != NULL) { assert(txn->n_rows > 0); txn->n_rows--; - stmt->row = NULL; } txn_stmt_unref_tuples(stmt); + stmt->space = NULL; + stmt->row = NULL; } } @@ -158,6 +157,8 @@ txn_begin(bool is_autocommit) int txn_begin_in_engine(struct engine *engine, struct txn *txn) { + if (engine->flags & ENGINE_BYPASS_TX) + return 0; if (txn->engine == NULL) { txn->engine = engine; return engine_begin(engine, txn); diff --git a/src/box/txn.h b/src/box/txn.h index 70efb8c14224ee6c65c4c2c55be1505442397145..9a1f175aff3b466ac64b8bf9d937b6cb368d4b2b 100644 --- a/src/box/txn.h +++ b/src/box/txn.h @@ -249,7 +249,6 @@ txn_commit_ro_stmt(struct txn *txn) { assert(txn == in_txn()); if (txn) { - assert(txn->engine); /* nothing to do */ } else { fiber_gc(); diff --git a/test/box/on_replace.result b/test/box/on_replace.result index fcdb43794636a2a329e312d3aebf0a6adf27ac54..f2de06f9095d7451fe3fd2b7ad4939769c34b486 100644 --- a/test/box/on_replace.result +++ b/test/box/on_replace.result @@ -471,21 +471,21 @@ t = s:on_replace(function () s:create_index('sec') end, t) ... s:replace({2, 3}) --- -- error: A multi-statement transaction can not use multiple storage engines +- error: DDL does not support multi-statement transactions ... t = s:on_replace(function () box.schema.user.create('newu') end, t) --- ... s:replace({3, 4}) --- -- error: A multi-statement transaction can not use multiple storage engines +- 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: A multi-statement transaction can not use multiple storage engines +- error: Space _user does not support multi-statement transactions ... t = s:on_replace(function () box.space._user:delete{box.schema.GUEST_ID} end, t) --- @@ -506,21 +506,21 @@ t = s:on_replace(function () s:drop() end, t) ... s:replace({5, 6}) --- -- error: A multi-statement transaction can not use multiple storage engines +- error: DDL does not support multi-statement transactions ... t = s:on_replace(function () box.schema.func.create('newf') end, t) --- ... s:replace({6, 7}) --- -- error: A multi-statement transaction can not use multiple storage engines +- 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: A multi-statement transaction can not use multiple storage engines +- error: Space _priv does not support multi-statement transactions ... t = s:on_replace(function () s:rename('newname') end, t) --- diff --git a/test/box/transaction.result b/test/box/transaction.result index 841dcf77eb9f440c4dc4b8ee162277f2f1b09288..e0240842cec3917a846495db5e358961638ea1c7 100644 --- a/test/box/transaction.result +++ b/test/box/transaction.result @@ -69,21 +69,21 @@ box.rollback(); ... box.begin() box.schema.func.create('test'); --- -- error: A multi-statement transaction can not use multiple storage engines +- error: Space _func does not support multi-statement transactions ... box.rollback(); --- ... box.begin() box.schema.user.create('test'); --- -- error: A multi-statement transaction can not use multiple storage engines +- error: Space _user does not support multi-statement transactions ... box.rollback(); --- ... box.begin() box.schema.user.grant('guest', 'read', 'space', '_priv'); --- -- error: A multi-statement transaction can not use multiple storage engines +- error: Space _priv does not support multi-statement transactions ... box.rollback(); --- @@ -498,3 +498,34 @@ space:select{} space:drop() --- ... +-- +-- gh-3528: sysview engine shouldn't participate in transaction control +-- +space = box.schema.space.create('test', {id = 9000}) +--- +... +index = space:create_index('primary') +--- +... +test_run:cmd("setopt delimiter ';'") +--- +- true +... +box.begin() +space:auto_increment{box.space._vspace:get{space.id}} +space:auto_increment{box.space._vindex:get{space.id, index.id}} +box.commit(); +--- +... +test_run:cmd("setopt delimiter ''"); +--- +- true +... +space:select() +--- +- - [1, [9000, 1, 'test', 'memtx', 0, {}, []]] + - [2, [9000, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]] +... +space:drop() +--- +... diff --git a/test/box/transaction.test.lua b/test/box/transaction.test.lua index 14d1a690d88c77aa252339b3bfd4b81aa1bd8328..e1d258e6c837a50ab4151f00463388969908004f 100644 --- a/test/box/transaction.test.lua +++ b/test/box/transaction.test.lua @@ -232,3 +232,19 @@ test_run:cmd("setopt delimiter ''"); space:select{} space:drop() + +-- +-- gh-3528: sysview engine shouldn't participate in transaction control +-- +space = box.schema.space.create('test', {id = 9000}) +index = space:create_index('primary') + +test_run:cmd("setopt delimiter ';'") +box.begin() +space:auto_increment{box.space._vspace:get{space.id}} +space:auto_increment{box.space._vindex:get{space.id, index.id}} +box.commit(); +test_run:cmd("setopt delimiter ''"); + +space:select() +space:drop()