From: Georgy Kirichenko <georgy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Georgy Kirichenko <georgy@tarantool.org>
Subject: [tarantool-patches] [PATCH v5 3/7] txn: get rid of fiber_gc from txn_rollback
Date: Sat, 22 Jun 2019 00:48:17 +0300 [thread overview]
Message-ID: <45c90bd7f82c44dd4965159100c7c436cb6e21bb.1561153472.git.georgy@tarantool.org> (raw)
In-Reply-To: <cover.1561153472.git.georgy@tarantool.org>
Refactoring: don't touch a fiber gc storage on a transaction rollback
explicitly. This relaxes dependencies between fiber and transaction
life cycles.
Prerequisites: #1254
---
src/box/applier.cc | 9 ++++++---
src/box/box.cc | 6 ++++--
src/box/call.c | 22 ++++++++++++++++------
src/box/memtx_engine.c | 3 ++-
src/box/txn.c | 23 ++++++++++++-----------
src/box/txn.h | 7 +++++--
src/box/vy_scheduler.c | 10 +++++++---
7 files changed, 52 insertions(+), 28 deletions(-)
diff --git a/src/box/applier.cc b/src/box/applier.cc
index d12a835d0..6f93759a8 100644
--- a/src/box/applier.cc
+++ b/src/box/applier.cc
@@ -190,7 +190,8 @@ apply_initial_join_row(struct xrow_header *row)
fiber_gc();
return rc;
rollback:
- txn_rollback();
+ txn_rollback(txn);
+ fiber_gc();
return -1;
}
@@ -235,7 +236,8 @@ apply_final_join_row(struct xrow_header *row)
if (txn == NULL)
return -1;
if (apply_row(row) != 0) {
- txn_rollback();
+ txn_rollback(txn);
+ fiber_gc();
return -1;
}
if (txn_commit(txn) != 0)
@@ -633,7 +635,8 @@ applier_apply_tx(struct stailq *rows)
return txn_commit(txn);
rollback:
- txn_rollback();
+ txn_rollback(txn);
+ fiber_gc();
return -1;
}
diff --git a/src/box/box.cc b/src/box/box.cc
index a32f1ba0f..d53b0cdc5 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -213,8 +213,10 @@ box_process_rw(struct request *request, struct space *space,
return 0;
rollback:
- if (is_autocommit)
- txn_rollback();
+ if (is_autocommit) {
+ txn_rollback(txn);
+ fiber_gc();
+ }
error:
if (return_tuple)
tuple_unref(tuple);
diff --git a/src/box/call.c b/src/box/call.c
index 56da53fb3..7f6fc8bba 100644
--- a/src/box/call.c
+++ b/src/box/call.c
@@ -208,14 +208,18 @@ box_process_call(struct call_request *request, struct port *port)
if (orig_credentials)
fiber_set_user(fiber(), orig_credentials);
+ struct txn *txn = in_txn();
if (rc != 0) {
- txn_rollback();
+ if (txn != NULL)
+ txn_rollback(txn);
+ fiber_gc();
return -1;
}
- if (in_txn()) {
+ if (txn != NULL) {
diag_set(ClientError, ER_FUNCTION_TX_ACTIVE);
- txn_rollback();
+ txn_rollback(txn);
+ fiber_gc();
return -1;
}
@@ -229,14 +233,20 @@ box_process_eval(struct call_request *request, struct port *port)
/* Check permissions */
if (access_check_universe(PRIV_X) != 0)
return -1;
+ struct txn *txn;
if (box_lua_eval(request, port) != 0) {
- txn_rollback();
+ txn = in_txn();
+ if (txn != NULL)
+ txn_rollback(txn);
+ fiber_gc();
return -1;
}
- if (in_txn()) {
+ txn = in_txn();
+ if (txn != NULL) {
diag_set(ClientError, ER_FUNCTION_TX_ACTIVE);
- txn_rollback();
+ txn_rollback(txn);
+ fiber_gc();
return -1;
}
diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c
index dae9955b2..f371d147f 100644
--- a/src/box/memtx_engine.c
+++ b/src/box/memtx_engine.c
@@ -274,7 +274,8 @@ memtx_engine_recover_snapshot_row(struct memtx_engine *memtx,
return -1;
/* no access checks here - applier always works with admin privs */
if (space_apply_initial_join_row(space, &request) != 0) {
- txn_rollback();
+ txn_rollback(txn);
+ fiber_gc();
return -1;
}
int rc = txn_commit(txn);
diff --git a/src/box/txn.c b/src/box/txn.c
index 583ae6ce0..1eb4db6a3 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -345,8 +345,10 @@ txn_write_to_wal(struct txn *txn)
struct journal_entry *req = journal_entry_new(txn->n_new_rows +
txn->n_applier_rows,
&txn->region);
- if (req == NULL)
+ if (req == NULL) {
+ txn_rollback(txn);
return -1;
+ }
struct txn_stmt *stmt;
struct xrow_header **remote_row = req->rows;
@@ -419,7 +421,7 @@ txn_commit(struct txn *txn)
if (txn->n_new_rows + txn->n_applier_rows > 0) {
txn->signature = txn_write_to_wal(txn);
if (txn->signature < 0)
- goto fail;
+ return -1;
}
/*
* Engine can be NULL if transaction contains IPROTO_NOP
@@ -443,7 +445,7 @@ txn_commit(struct txn *txn)
txn_free(txn);
return 0;
fail:
- txn_rollback();
+ txn_rollback(txn);
return -1;
}
@@ -457,11 +459,9 @@ txn_rollback_stmt(struct txn *txn)
}
void
-txn_rollback()
+txn_rollback(struct txn *txn)
{
- struct txn *txn = in_txn();
- if (txn == NULL)
- return;
+ assert(txn == in_txn());
trigger_clear(&txn->fiber_on_stop);
if (txn->engine)
engine_rollback(txn->engine, txn);
@@ -473,8 +473,6 @@ txn_rollback()
panic("rollback trigger failed");
}
- /** Free volatile txn memory. */
- fiber_gc();
fiber_set_txn(fiber(), NULL);
txn_free(txn);
}
@@ -550,11 +548,14 @@ int
box_txn_rollback()
{
struct txn *txn = in_txn();
+ if (txn == NULL)
+ return 0;
if (txn && txn->in_sub_stmt) {
diag_set(ClientError, ER_ROLLBACK_IN_SUB_STMT);
return -1;
}
- txn_rollback(); /* doesn't throw */
+ txn_rollback(txn); /* doesn't throw */
+ fiber_gc();
return 0;
}
@@ -632,6 +633,6 @@ txn_on_stop(struct trigger *trigger, void *event)
{
(void) trigger;
(void) event;
- txn_rollback(); /* doesn't yield or fail */
+ txn_rollback(in_txn()); /* doesn't yield or fail */
}
diff --git a/src/box/txn.h b/src/box/txn.h
index 33926f6f3..f20428fad 100644
--- a/src/box/txn.h
+++ b/src/box/txn.h
@@ -221,9 +221,12 @@ txn_begin();
int
txn_commit(struct txn *txn);
-/** Rollback a transaction, if any. */
+/**
+ * Rollback a transaction.
+ * @pre txn == in_txn()
+ */
void
-txn_rollback();
+txn_rollback(struct txn *txn);
/**
* Roll back the transaction but keep the object around.
diff --git a/src/box/vy_scheduler.c b/src/box/vy_scheduler.c
index ed8f7dd86..0df55818f 100644
--- a/src/box/vy_scheduler.c
+++ b/src/box/vy_scheduler.c
@@ -889,18 +889,22 @@ vy_deferred_delete_batch_process_f(struct cmsg *cmsg)
for (int i = 0; i < batch->count; i++) {
if (vy_deferred_delete_process_one(deferred_delete_space,
pk->space_id, pk->mem_format,
- &batch->stmt[i]) != 0)
- goto fail;
+ &batch->stmt[i]) != 0) {
+ goto fail_rollback;
+ }
}
if (txn_commit(txn) != 0)
goto fail;
fiber_gc();
return;
+
+fail_rollback:
+ txn_rollback(txn);
+ fiber_gc();
fail:
batch->is_failed = true;
diag_move(diag_get(), &batch->diag);
- txn_rollback();
}
/**
--
2.22.0
next prev parent reply other threads:[~2019-06-21 21:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-21 21:48 [tarantool-patches] [PATCH v5 0/7] Parallel applier Georgy Kirichenko
2019-06-21 21:48 ` [tarantool-patches] [PATCH v5 1/7] txn: unref statement at txn_free Georgy Kirichenko
2019-06-21 21:48 ` [tarantool-patches] [PATCH v5 2/7] txn: get rid of autocommit from a txn structure Georgy Kirichenko
2019-06-21 21:48 ` Georgy Kirichenko [this message]
2019-06-21 21:48 ` [tarantool-patches] [PATCH v5 4/7] wal: introduce a journal entry finalization callback Georgy Kirichenko
2019-06-21 21:48 ` [tarantool-patches] [PATCH v5 5/7] txn: introduce asynchronous txn commit Georgy Kirichenko
2019-06-21 21:48 ` [tarantool-patches] [PATCH v5 6/7] applier: apply transaction in parallel Georgy Kirichenko
2019-06-21 21:48 ` [tarantool-patches] [PATCH v5 7/7] test: fix flaky test Georgy Kirichenko
2019-06-25 16:08 ` [tarantool-patches] [PATCH v5 0/7] Parallel applier 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=45c90bd7f82c44dd4965159100c7c436cb6e21bb.1561153472.git.georgy@tarantool.org \
--to=georgy@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH v5 3/7] txn: get rid of fiber_gc from txn_rollback' \
/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