* [PATCH] lua: fix operation type passing to on_replace triggers
@ 2019-06-03 14:24 Serge Petrenko
2019-06-03 14:33 ` Vladimir Davydov
0 siblings, 1 reply; 2+ messages in thread
From: Serge Petrenko @ 2019-06-03 14:24 UTC (permalink / raw)
To: vdavydov.dev; +Cc: tarantool-patches, Serge Petrenko
This commit fixes a regression introduced by commit
5ab0763b856d495d1d61055f946f6c0cf87dd065
(pass operation type to lua triggers)
When passing operation type to the trigger, we relied on a corresponding
xrow_header, which would later be written to the log. When before_replace
triggers are fired, there is no row connected to the txn statement yet,
so we faked one to pass operations. We, however, didn't account for
temporary spaces, which never have a row associated with a corresponding
txn stmt. This lead to a segfault on an attemt to use on_replace triggers
with temporary spaces.
Add a fake row for temporary spaces to pass operation type in on_replace
triggers and add some tests.
Closes #4266
---
https://github.com/tarantool/tarantool/issues/4266
https://github.com/tarantool/tarantool/tree/sp/gh-4266-temp-space-insert
src/box/txn.c | 19 ++++++++++++++++++-
test/box/before_replace.result | 25 +++++++++++++++++++++++++
test/box/before_replace.test.lua | 15 +++++++++++++++
test/box/on_replace.result | 25 +++++++++++++++++++++++++
test/box/on_replace.test.lua | 15 +++++++++++++++
5 files changed, 98 insertions(+), 1 deletion(-)
diff --git a/src/box/txn.c b/src/box/txn.c
index da749d7cc..88e61baea 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -312,7 +312,24 @@ txn_commit_stmt(struct txn *txn, struct request *request)
*/
if (stmt->space != NULL && !rlist_empty(&stmt->space->on_replace) &&
stmt->space->run_triggers && (stmt->old_tuple || stmt->new_tuple)) {
- if (trigger_run(&stmt->space->on_replace, txn) != 0)
+ int rc = 0;
+ if(!space_is_temporary(stmt->space)) {
+ rc = trigger_run(&stmt->space->on_replace, txn);
+ } else {
+ /*
+ * There is no row attached to txn_stmt for
+ * temporary spaces, since DML operations on them
+ * are not written to WAL. Fake a row to pass operation
+ * type to lua on_replace triggers.
+ */
+ assert(stmt->row == NULL);
+ struct xrow_header temp_header;
+ temp_header.type = request->type;
+ stmt->row = &temp_header;
+ rc = trigger_run(&stmt->space->on_replace, txn);
+ stmt->row = NULL;
+ }
+ if (rc != 0)
goto fail;
}
--txn->in_sub_stmt;
diff --git a/test/box/before_replace.result b/test/box/before_replace.result
index 9580f05af..5054fdefd 100644
--- a/test/box/before_replace.result
+++ b/test/box/before_replace.result
@@ -833,3 +833,28 @@ save_type
s:drop()
---
...
+--
+-- gh-4266 triggers on temporary space fail
+--
+s = box.schema.space.create('test', {temporary = true})
+---
+...
+_ = s:create_index('pk')
+---
+...
+save_type = ''
+---
+...
+_ = s:before_replace(function(old,new, name, type) save_type = type return new end)
+---
+...
+_ = s:insert{1}
+---
+...
+save_type
+---
+- INSERT
+...
+s:drop()
+---
+...
diff --git a/test/box/before_replace.test.lua b/test/box/before_replace.test.lua
index 656e20661..c46ec25a0 100644
--- a/test/box/before_replace.test.lua
+++ b/test/box/before_replace.test.lua
@@ -291,3 +291,18 @@ _ = s:upsert({3,4,5}, {{'+', 2, 1}})
save_type
s:drop()
+
+--
+-- gh-4266 triggers on temporary space fail
+--
+s = box.schema.space.create('test', {temporary = true})
+
+_ = s:create_index('pk')
+
+save_type = ''
+
+_ = s:before_replace(function(old,new, name, type) save_type = type return new end)
+_ = s:insert{1}
+save_type
+
+s:drop()
diff --git a/test/box/on_replace.result b/test/box/on_replace.result
index 963dac2cb..b2a4b2179 100644
--- a/test/box/on_replace.result
+++ b/test/box/on_replace.result
@@ -752,3 +752,28 @@ save_type
s:drop()
---
...
+--
+-- gh-4266 triggers on temporary space fail
+--
+s = box.schema.space.create('test', {temporary = true})
+---
+...
+_ = s:create_index('pk')
+---
+...
+save_type = ''
+---
+...
+_ = s:on_replace(function(old,new, name, type) save_type = type end)
+---
+...
+_ = s:insert{1}
+---
+...
+save_type
+---
+- INSERT
+...
+s:drop()
+---
+...
diff --git a/test/box/on_replace.test.lua b/test/box/on_replace.test.lua
index edb0ad65e..a6150b0ee 100644
--- a/test/box/on_replace.test.lua
+++ b/test/box/on_replace.test.lua
@@ -298,3 +298,18 @@ _ = s:upsert({3,4,5}, {{'+', 2, 1}})
save_type
s:drop()
+
+--
+-- gh-4266 triggers on temporary space fail
+--
+s = box.schema.space.create('test', {temporary = true})
+
+_ = s:create_index('pk')
+
+save_type = ''
+
+_ = s:on_replace(function(old,new, name, type) save_type = type end)
+_ = s:insert{1}
+save_type
+
+s:drop()
--
2.20.1 (Apple Git-117)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-03 14:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03 14:24 [PATCH] lua: fix operation type passing to on_replace triggers Serge Petrenko
2019-06-03 14:33 ` Vladimir Davydov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox