Tarantool development patches archive
 help / color / mirror / Atom feed
From: Ilya Markov <imarkov@tarantool.org>
To: georgy@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] [wal 1/1] wal: Update request header after sequence update
Date: Tue, 17 Apr 2018 10:39:16 +0300	[thread overview]
Message-ID: <c582937d2c9698cc2b63ec6895a78e45410b90aa.1523950414.git.imarkov@tarantool.org> (raw)

When tuple in insert/replace request has NULL value
in the field incremented by sequence,
request body is changed, NULL is replaced by value taken from
sequence.
But request header is not updated.
So Redo log, which takes body from header if header exists,
writes the old version of request to wal.

Fixed this with updating header value after handling the sequence.

Closes #3247
---
branch gh-3247-wrong-sequence-primary-index

 src/box/request.c              |  7 +++++
 test/replication/misc.result   | 66 ++++++++++++++++++++++++++++++++++++++++++
 test/replication/misc.test.lua | 21 ++++++++++++++
 3 files changed, 94 insertions(+)

diff --git a/src/box/request.c b/src/box/request.c
index 646da42..0b3c5fb 100644
--- a/src/box/request.c
+++ b/src/box/request.c
@@ -195,5 +195,12 @@ request_handle_sequence(struct request *request, struct space *space)
 		if (likely(mp_read_int64(&key, &value) == 0))
 			return sequence_update(seq, value);
 	}
+	/*
+	 * As the request body was changed, we have to update body in header.
+	 */
+	if (request->header != NULL) {
+		request->header->bodycnt =
+			xrow_encode_dml(request, request->header->body);
+	}
 	return 0;
 }
diff --git a/test/replication/misc.result b/test/replication/misc.result
index 879c7fe..3d1089d 100644
--- a/test/replication/misc.result
+++ b/test/replication/misc.result
@@ -139,6 +139,72 @@ test_run:cmd("switch default")
 ---
 - true
 ...
+-- gh-3247 wrong sequence replication
+test_run:cmd("switch autobootstrap1")
+---
+- true
+...
+net_box = require('net.box')
+---
+...
+engine = test_run:get_cfg('engine')
+---
+...
+_ = box.schema.space.create("space1", {engine=engine})
+---
+...
+_ = box.schema.sequence.create('seq')
+---
+...
+_ = box.space.space1:create_index('primary', {sequence='seq'} )
+---
+...
+_ = box.space.space1:create_index('idx', { type = 'tree', unique = false, parts = {2, 'number'} })
+---
+...
+box.schema.user.grant('guest', "read,write", "space", 'space1')
+---
+...
+box.schema.user.grant('guest', "read,write", "sequence", 'seq')
+---
+...
+c = net_box.connect(box.cfg.listen)
+---
+...
+c.space.space1:insert{box.NULL, "data"}
+---
+- error: 'Tuple field 2 type does not match one required by operation: expected number'
+...
+c.space.space1:insert{box.NULL, 1, "data"}
+---
+- [2, 1, 'data']
+...
+box.space.space1:select{}
+---
+- - [2, 1, 'data']
+...
+test_run:cmd("switch autobootstrap2")
+---
+- true
+...
+box.space.space1:select{}
+---
+- - [2, 1, 'data']
+...
+test_run:cmd("switch autobootstrap1")
+---
+- true
+...
+box.space.space1:drop()
+---
+...
+box.sequence.seq:drop()
+---
+...
+test_run:cmd("switch default")
+---
+- true
+...
 test_run:drop_cluster(SERVERS)
 ---
 ...
diff --git a/test/replication/misc.test.lua b/test/replication/misc.test.lua
index 8752182..b00154e 100644
--- a/test/replication/misc.test.lua
+++ b/test/replication/misc.test.lua
@@ -56,6 +56,27 @@ end ;
 test_run:cmd("setopt delimiter ''");
 test_timeout()
 test_run:cmd("switch default")
+-- gh-3247 wrong sequence replication
+test_run:cmd("switch autobootstrap1")
+net_box = require('net.box')
+engine = test_run:get_cfg('engine')
+_ = box.schema.space.create("space1", {engine=engine})
+_ = box.schema.sequence.create('seq')
+_ = box.space.space1:create_index('primary', {sequence='seq'} )
+_ = box.space.space1:create_index('idx', { type = 'tree', unique = false, parts = {2, 'number'} })
+box.schema.user.grant('guest', "read,write", "space", 'space1')
+box.schema.user.grant('guest', "read,write", "sequence", 'seq')
+c = net_box.connect(box.cfg.listen)
+c.space.space1:insert{box.NULL, "data"}
+c.space.space1:insert{box.NULL, 1, "data"}
+box.space.space1:select{}
+test_run:cmd("switch autobootstrap2")
+box.space.space1:select{}
+test_run:cmd("switch autobootstrap1")
+box.space.space1:drop()
+box.sequence.seq:drop()
+
+test_run:cmd("switch default")
 test_run:drop_cluster(SERVERS)
 
 box.schema.user.revoke('guest', 'replication')
-- 
2.7.4

             reply	other threads:[~2018-04-17  7:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17  7:39 Ilya Markov [this message]
2018-04-18  7:10 ` [tarantool-patches] " Georgy Kirichenko
2018-04-18 11:47 ` [tarantool-patches] " 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=c582937d2c9698cc2b63ec6895a78e45410b90aa.1523950414.git.imarkov@tarantool.org \
    --to=imarkov@tarantool.org \
    --cc=georgy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [wal 1/1] wal: Update request header after sequence update' \
    /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