From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH 5/6] xrow: make NOP requests bodiless
Date: Wed, 13 Jun 2018 19:10:37 +0300 [thread overview]
Message-ID: <17ae2aebf74d562326bac5201a55db5a3dc591d8.1528906027.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1528906027.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1528906027.git.vdavydov.dev@gmail.com>
A NOP request has no body, but since it is treated as DML, we still
encode a zero-size map for its body. This complicates conversion of
local requests to NOP in relay as we can't omit xrow_encode_dml (see
the next patch), so let's allow DML requests to be bodiless.
Needed for #3443
---
src/box/box.cc | 1 -
src/box/lua/xlog.c | 15 ++++++++-------
src/box/xrow.c | 19 ++++++++++---------
test/box/before_replace.result | 4 ++--
test/box/before_replace.test.lua | 2 +-
5 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/src/box/box.cc b/src/box/box.cc
index 8248cc77..7c8e6bf8 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -273,7 +273,6 @@ recovery_journal_create(struct recovery_journal *journal, struct vclock *v)
static inline void
apply_row(struct xstream *stream, struct xrow_header *row)
{
- assert(row->bodycnt == 1); /* always 1 for read */
(void) stream;
struct request request;
xrow_decode_dml_xc(row, &request, dml_request_key_map(row->type));
diff --git a/src/box/lua/xlog.c b/src/box/lua/xlog.c
index 70384c1d..2271c829 100644
--- a/src/box/lua/xlog.c
+++ b/src/box/lua/xlog.c
@@ -219,13 +219,14 @@ lbox_xlog_parser_iterate(struct lua_State *L)
lua_settable(L, -3); /* HEADER */
- assert(row.bodycnt == 1); /* always 1 for read */
- lua_pushstring(L, "BODY");
- lua_newtable(L);
- lbox_xlog_parse_body(L, row.type, (char *)row.body[0].iov_base,
- row.body[0].iov_len);
- lua_settable(L, -3); /* BODY */
-
+ if (row.bodycnt > 0) {
+ assert(row.bodycnt == 1);
+ lua_pushstring(L, "BODY");
+ lua_newtable(L);
+ lbox_xlog_parse_body(L, row.type, row.body[0].iov_base,
+ row.body[0].iov_len);
+ lua_settable(L, -3); /* BODY */
+ }
return 2;
}
diff --git a/src/box/xrow.c b/src/box/xrow.c
index 48fbff27..64d845f7 100644
--- a/src/box/xrow.c
+++ b/src/box/xrow.c
@@ -405,11 +405,12 @@ int
xrow_decode_dml(struct xrow_header *row, struct request *request,
uint64_t key_map)
{
- if (row->bodycnt == 0) {
- diag_set(ClientError, ER_INVALID_MSGPACK,
- "missing request body");
- return -1;
- }
+ memset(request, 0, sizeof(*request));
+ request->header = row;
+ request->type = row->type;
+
+ if (row->bodycnt == 0)
+ goto done;
assert(row->bodycnt == 1);
const char *data = (const char *) row->body[0].iov_base;
@@ -422,10 +423,6 @@ error:
return -1;
}
- memset(request, 0, sizeof(*request));
- request->header = row;
- request->type = row->type;
-
uint32_t size = mp_decode_map(&data);
for (uint32_t i = 0; i < size; i++) {
if (! iproto_dml_body_has_key(data, end)) {
@@ -480,6 +477,7 @@ error:
diag_set(ClientError, ER_INVALID_MSGPACK, "packet end");
return -1;
}
+done:
if (key_map) {
enum iproto_key key = (enum iproto_key) bit_ctz_u64(key_map);
diag_set(ClientError, ER_MISSING_REQUEST_FIELD,
@@ -567,6 +565,9 @@ xrow_encode_dml(const struct request *request, struct iovec *iov)
map_size++;
}
+ if (map_size == 0)
+ return 0;
+
assert(pos <= begin + len);
mp_encode_map(begin, map_size);
iov[0].iov_base = begin;
diff --git a/test/box/before_replace.result b/test/box/before_replace.result
index 2b6c1801..cd0a3be1 100644
--- a/test/box/before_replace.result
+++ b/test/box/before_replace.result
@@ -660,9 +660,9 @@ row.HEADER.type
---
- NOP
...
-#row.BODY
+row.BODY == nil
---
-- 0
+- true
...
-- gh-3128 before_replace with run_triggers
s2 = box.schema.space.create("test2")
diff --git a/test/box/before_replace.test.lua b/test/box/before_replace.test.lua
index 9b4f49cf..dd464384 100644
--- a/test/box/before_replace.test.lua
+++ b/test/box/before_replace.test.lua
@@ -221,7 +221,7 @@ path = fio.pathjoin(box.cfg.wal_dir, string.format('%020d.xlog', box.info.lsn -
fun, param, state = xlog.pairs(path)
state, row = fun(param, state)
row.HEADER.type
-#row.BODY
+row.BODY == nil
-- gh-3128 before_replace with run_triggers
s2 = box.schema.space.create("test2")
--
2.11.0
next prev parent reply other threads:[~2018-06-13 16:10 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-13 16:10 [PATCH 0/6] Introduce replica local spaces Vladimir Davydov
2018-06-13 16:10 ` [PATCH 1/6] txn: remove unused C++ wrappers Vladimir Davydov
2018-06-27 17:08 ` Konstantin Osipov
2018-06-13 16:10 ` [PATCH 2/6] xrow: fix ret code on decode failure Vladimir Davydov
2018-06-27 17:29 ` Konstantin Osipov
2018-06-13 16:10 ` [PATCH 3/6] iproto: fix IPROTO_SERVER_IS_RO key code Vladimir Davydov
2018-06-27 17:48 ` Konstantin Osipov
2018-06-13 16:10 ` [PATCH 4/6] txn: do not require space id for nop requests Vladimir Davydov
2018-06-27 17:45 ` Konstantin Osipov
2018-06-28 9:13 ` Vladimir Davydov
2018-06-28 10:23 ` Konstantin Osipov
2018-06-28 10:35 ` Vladimir Davydov
2018-06-28 10:54 ` Konstantin Osipov
2018-06-28 11:10 ` Vladimir Davydov
2018-06-13 16:10 ` Vladimir Davydov [this message]
2018-06-27 17:49 ` [PATCH 5/6] xrow: make NOP requests bodiless Konstantin Osipov
2018-06-13 16:10 ` [PATCH 6/6] Introduce replica local spaces Vladimir Davydov
2018-06-13 21:26 ` [tarantool-patches] " Vladislav Shpilevoy
2018-06-27 18:24 ` Konstantin Osipov
2018-06-27 18:27 ` 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=17ae2aebf74d562326bac5201a55db5a3dc591d8.1528906027.git.vdavydov.dev@gmail.com \
--to=vdavydov.dev@gmail.com \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH 5/6] xrow: make NOP requests bodiless' \
/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