Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Osipov <kostja@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Georgy Kirichenko <georgy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2 2/8] Get rid of autocommit from a txn structure
Date: Mon, 27 May 2019 23:51:34 +0300	[thread overview]
Message-ID: <20190527205134.GA15844@atlas> (raw)
In-Reply-To: <5ac79c845931bd0bef74d3a988762ceec54ab6b4.1558598679.git.georgy@tarantool.org>

* Georgy Kirichenko <georgy@tarantool.org> [19/05/23 12:14]:
> Move transaction auto start and auto commit behavior to the box level.
> >From now a transaction won't start and commit automatically without
> txn_begin/txn_commit invocations. This is a part of a bigger transaction
> refactoring in order to implement detachable transactions and a parallel
> applier.

I started looking at this patch and I don't fully understand it.

- why do you sometimes call fiber_gc() after txn_commit() and
  sometimes do not?

It used to be called before, and not called in some cases after
your change.

Here's the diff (it doesn't pass tests, which baffles me, could
you please explain?


---
 src/box/applier.cc |  4 +++-
 src/box/box.cc     | 52 ++++++++++++++++++++++++++--------------------
 src/box/journal.h  |  1 -
 3 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/src/box/applier.cc b/src/box/applier.cc
index 9d2989094..75698fea7 100644
--- a/src/box/applier.cc
+++ b/src/box/applier.cc
@@ -178,8 +178,10 @@ apply_initial_join_row(struct xrow_header *row)
 	struct request request;
 	xrow_decode_dml(row, &request, dml_request_key_map(row->type));
 	struct space *space = space_cache_find(request.space_id);
-	if (space == NULL)
+	if (space == NULL) {
+		txn_rollback();
 		return -1;
+	}
 	/* no access checks here - applier always works with admin privs */
 	if (space_apply_initial_join_row(space, &request)) {
 		txn_rollback();
diff --git a/src/box/box.cc b/src/box/box.cc
index 2a738fa36..a371af813 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -184,30 +184,27 @@ box_process_rw(struct request *request, struct space *space,
 		txn_rollback_stmt(txn);
 		goto fail;
 	}
-	/*
-	 * Pin the tuple locally before the commit,
-	 * otherwise it may go away during yield in
-	 * when WAL is written in autocommit mode.
-	 */
 	if (result != NULL)
 		*result = tuple;
 
 	if (result == NULL || tuple == NULL) {
-		if (!is_autocommit)
-			return txn_commit_stmt(txn, request);
-		/* Autocommit mode. */
-		if (txn_commit_stmt(txn, request) != 0) {
-			txn_rollback();
-			return -1;
+		if (txn_commit_stmt(txn, request) != 0)
+			goto fail;
+		if (is_autocommit) {
+			if (txn_commit(txn) != 0)
+				return -1;
+			fiber_gc();
 		}
-		if (txn_commit(txn) != 0)
-			return -1;
-		fiber_gc();
 		return 0;
 	}
+	/*
+	 * Pin the tuple locally before the commit,
+	 * otherwise it may go away during yield in
+	 * when WAL is written in autocommit mode.
+	 */
 	tuple_ref(tuple);
 
-	if (txn_commit_stmt(txn, request)) {
+	if (txn_commit_stmt(txn, request) != 0) {
 		/* Unref tuple and rollback if autocommit. */
 		tuple_unref(tuple);
 		goto fail;
@@ -328,25 +325,32 @@ apply_wal_row(struct xstream *stream, struct xrow_header *row)
 {
 	struct request request;
 	xrow_decode_dml_xc(row, &request, dml_request_key_map(row->type));
+	struct wal_stream *xstream =
+		container_of(stream, struct wal_stream, base);
+
 	if (request.type != IPROTO_NOP) {
 		struct space *space = space_cache_find_xc(request.space_id);
 		struct txn *txn = txn_begin();
-		if (txn == NULL || box_process_rw(&request, space, NULL) != 0 ||
-		    txn_commit(txn) != 0) {
-			say_error("error applying row: %s", request_str(&request));
-			if (txn != NULL)
-				txn_rollback();
-			diag_raise();
+		if (txn == NULL)
+			goto error;
+		if (box_process_rw(&request, space, NULL) != 0) {
+			txn_rollback();
+			goto error;
 		}
+		if (txn_commit(txn) != 0)
+			goto error;
+		fiber_gc();
 	}
-	struct wal_stream *xstream =
-		container_of(stream, struct wal_stream, base);
 	/**
 	 * Yield once in a while, but not too often,
 	 * mostly to allow signal handling to take place.
 	 */
 	if (++xstream->rows % xstream->yield == 0)
 		fiber_sleep(0);
+error:
+	say_error("error applying row: %s", request_str(&request));
+	diag_raise();
+
 }
 
 static void
@@ -1358,6 +1362,7 @@ box_register_replica(uint32_t id, const struct tt_uuid *uuid)
 	}
 	if (txn_commit(txn) != 0)
 		diag_raise();
+	fiber_gc();
 	assert(replica_by_uuid(uuid)->id == id);
 }
 
@@ -1689,6 +1694,7 @@ box_set_replicaset_uuid(const struct tt_uuid *replicaset_uuid)
 	}
 	if (txn_commit(txn) != 0)
 		diag_raise();
+	fiber_gc();
 }
 
 void
diff --git a/src/box/journal.h b/src/box/journal.h
index 77d3073c8..8ac32ee5e 100644
--- a/src/box/journal.h
+++ b/src/box/journal.h
@@ -32,7 +32,6 @@
  */
 #include <stdint.h>
 #include <stdbool.h>
-#include "trigger.h"
 #include "salad/stailq.h"
 
 #if defined(__cplusplus)

-- 
Konstantin Osipov, Moscow, Russia

  reply	other threads:[~2019-05-27 20:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23  8:19 [tarantool-patches] [PATCH v2 0/8] Make transaction autonomous from a fiber internals Georgy Kirichenko
2019-05-23  8:19 ` [tarantool-patches] [PATCH v2 1/8] Encode a dml statement to a transaction memory region Georgy Kirichenko
2019-05-28  1:21   ` [tarantool-patches] " Kirill Yukhin
2019-05-23  8:19 ` [tarantool-patches] [PATCH v2 2/8] Get rid of autocommit from a txn structure Georgy Kirichenko
2019-05-27 20:51   ` Konstantin Osipov [this message]
2019-05-31 19:21   ` [tarantool-patches] " Konstantin Osipov
2019-05-23  8:19 ` [tarantool-patches] [PATCH v2 3/8] Get rid of fiber_gc from txn_rollback Georgy Kirichenko
2019-05-31 19:27   ` [tarantool-patches] " Konstantin Osipov
2019-05-23  8:19 ` [tarantool-patches] [PATCH v2 4/8] Remove fiber from a journal_entry structure Georgy Kirichenko
2019-05-31 19:29   ` [tarantool-patches] " Konstantin Osipov
2019-05-23  8:19 ` [tarantool-patches] [PATCH v2 5/8] Commit engine before all triggers Georgy Kirichenko
2019-05-31 19:32   ` [tarantool-patches] " Konstantin Osipov
2019-06-03  8:07     ` Георгий Кириченко
2019-05-23  8:19 ` [tarantool-patches] [PATCH v2 6/8] Offload tx_prio processing to a fiber Georgy Kirichenko
2019-05-31 19:36   ` [tarantool-patches] " Konstantin Osipov
2019-06-03  8:04     ` Георгий Кириченко
2019-05-23  8:19 ` [tarantool-patches] [PATCH v2 7/8] Enable asyncronous wal writes Georgy Kirichenko
2019-05-31 19:41   ` [tarantool-patches] " Konstantin Osipov
2019-06-03  8:09     ` Георгий Кириченко
2019-05-23  8:19 ` [tarantool-patches] [PATCH v2 8/8] Introduce asynchronous txn commit Georgy Kirichenko
2019-05-31 19:43   ` [tarantool-patches] " Konstantin Osipov

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=20190527205134.GA15844@atlas \
    --to=kostja@tarantool.org \
    --cc=georgy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH v2 2/8] Get rid of autocommit from a txn structure' \
    /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