From 92bb45f48be64167f2ed946a0624937c1e6b3832 Mon Sep 17 00:00:00 2001 From: Roman Tsisyk <roman@tarantool.org> Date: Tue, 25 Jul 2017 11:01:19 +0300 Subject: [PATCH] xrow: review fixes for SYNC refactoring * Pass sync as xrow_header_encode() argument, as suggested by Kostja. * Add SYNC support to Lua xrow reader. * Add the test cases. Follow up #2334 --- src/box/lua/xlog.c | 5 +++ src/box/xlog.cc | 6 ++-- src/box/xlog.h | 2 +- src/box/xrow.c | 10 +++--- src/box/xrow.h | 2 +- test/unit/xrow.cc | 8 +++-- test/unit/xrow.result | 5 +-- test/xlog/misc.result | 78 +++++++++++++++++++++++++++++++++++++++++ test/xlog/misc.test.lua | 36 +++++++++++++++++++ 9 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 test/xlog/misc.result create mode 100644 test/xlog/misc.test.lua diff --git a/src/box/lua/xlog.c b/src/box/lua/xlog.c index 805ea1ba1f..e92db3919d 100644 --- a/src/box/lua/xlog.c +++ b/src/box/lua/xlog.c @@ -202,6 +202,11 @@ lbox_xlog_parser_iterate(struct lua_State *L) lua_pushnumber(L, row.type); /* unknown key */ } lua_settable(L, -3); /* type */ + if (row.sync != 0) { + lbox_xlog_pushkey(L, iproto_key_name(IPROTO_SYNC)); + lua_pushinteger(L, row.sync); + lua_settable(L, -3); /* sync */ + } if (row.lsn != 0) { lbox_xlog_pushkey(L, iproto_key_name(IPROTO_LSN)); lua_pushinteger(L, row.lsn); diff --git a/src/box/xlog.cc b/src/box/xlog.cc index 8d625e6c80..b3088300ed 100644 --- a/src/box/xlog.cc +++ b/src/box/xlog.cc @@ -1161,7 +1161,7 @@ xlog_tx_write(struct xlog *log) * @retval >=0 the number of bytes written to buffer. */ ssize_t -xlog_write_row(struct xlog *log, struct xrow_header *packet) +xlog_write_row(struct xlog *log, const struct xrow_header *packet) { /* * Automatically reserve space for a fixheader when adding @@ -1181,9 +1181,7 @@ xlog_write_row(struct xlog *log, struct xrow_header *packet) /** encode row into iovec */ struct iovec iov[XROW_IOVMAX]; /** don't write sync to the disk */ - uint64_t sync = packet->sync; - int iovcnt = xrow_header_encode(packet, iov, 0); - packet->sync = sync; + int iovcnt = xrow_header_encode(packet, 0, iov, 0); if (iovcnt < 0) { obuf_rollback_to_svp(&log->obuf, &svp); return -1; diff --git a/src/box/xlog.h b/src/box/xlog.h index 4a6f062da2..253abfadaf 100644 --- a/src/box/xlog.h +++ b/src/box/xlog.h @@ -403,7 +403,7 @@ xlog_rename(struct xlog *l); * @retval -1 for error */ ssize_t -xlog_write_row(struct xlog *log, struct xrow_header *packet); +xlog_write_row(struct xlog *log, const struct xrow_header *packet); /** * Prevent xlog row buffer offloading, should be use diff --git a/src/box/xrow.c b/src/box/xrow.c index 0557059278..26736fc74a 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -128,8 +128,8 @@ xrow_decode_uuid(const char **pos, struct tt_uuid *out) } int -xrow_header_encode(const struct xrow_header *header, struct iovec *out, - size_t fixheader_len) +xrow_header_encode(const struct xrow_header *header, uint64_t sync, + struct iovec *out, size_t fixheader_len) { /* allocate memory for sign + header */ out->iov_base = region_alloc(&fiber()->gc, XROW_HEADER_LEN_MAX + @@ -150,9 +150,9 @@ xrow_header_encode(const struct xrow_header *header, struct iovec *out, map_size++; } - if (header->sync) { + if (sync) { d = mp_encode_uint(d, IPROTO_SYNC); - d = mp_encode_uint(d, header->sync); + d = mp_encode_uint(d, sync); map_size++; } @@ -509,7 +509,7 @@ int xrow_to_iovec(const struct xrow_header *row, struct iovec *out) { assert(mp_sizeof_uint(UINT32_MAX) == 5); - int iovcnt = xrow_header_encode(row, out, 5); + int iovcnt = xrow_header_encode(row, row->sync, out, 5); if (iovcnt < 0) return -1; ssize_t len = -5; diff --git a/src/box/xrow.h b/src/box/xrow.h index 53e650c6d3..ee1e9f09db 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -78,7 +78,7 @@ struct xrow_header { * @post retval <= XROW_IOVMAX */ int -xrow_header_encode(const struct xrow_header *header, +xrow_header_encode(const struct xrow_header *header, uint64_t sync, struct iovec *out, size_t fixheader_len); /** diff --git a/test/unit/xrow.cc b/test/unit/xrow.cc index f73b33fde6..c41724e415 100644 --- a/test/unit/xrow.cc +++ b/test/unit/xrow.cc @@ -203,7 +203,7 @@ test_greeting() void test_xrow_header_encode_decode() { - plan(9); + plan(10); struct xrow_header header; char buffer[2048]; char *pos = mp_encode_uint(buffer, 300); @@ -215,11 +215,12 @@ test_xrow_header_encode_decode() header.lsn = 400; header.tm = 123.456; header.bodycnt = 0; + uint64_t sync = 100500; struct iovec vec; - is(1, xrow_header_encode(&header, &vec, 200), "encode"); + is(1, xrow_header_encode(&header, sync, &vec, 200), "encode"); int fixheader_len = 200; pos = (char *)vec.iov_base + fixheader_len; - is(mp_decode_map((const char **)&pos), 4, "header map size"); + is(mp_decode_map((const char **)&pos), 5, "header map size"); struct xrow_header decoded_header; const char *begin = (const char *)vec.iov_base; @@ -232,6 +233,7 @@ test_xrow_header_encode_decode() is(header.replica_id, decoded_header.replica_id, "decoded replica_id"); is(header.lsn, decoded_header.lsn, "decoded lsn"); is(header.tm, decoded_header.tm, "decoded tm"); + is(decoded_header.sync, sync, "decoded sync"); is(decoded_header.bodycnt, 0, "decoded bodycnt"); check_plan(); diff --git a/test/unit/xrow.result b/test/unit/xrow.result index 69230916e6..88500f75e6 100644 --- a/test/unit/xrow.result +++ b/test/unit/xrow.result @@ -41,7 +41,7 @@ ok 39 - invalid 10 ok 40 - invalid 11 ok 1 - subtests - 1..9 + 1..10 ok 1 - bad msgpack end ok 2 - encode ok 3 - header map size @@ -50,5 +50,6 @@ ok 1 - subtests ok 6 - decoded replica_id ok 7 - decoded lsn ok 8 - decoded tm - ok 9 - decoded bodycnt + ok 9 - decoded sync + ok 10 - decoded bodycnt ok 2 - subtests diff --git a/test/xlog/misc.result b/test/xlog/misc.result new file mode 100644 index 0000000000..120ff70c80 --- /dev/null +++ b/test/xlog/misc.result @@ -0,0 +1,78 @@ +test_run = require('test_run').new() +--- +... +test_run:cmd('restart server default with cleanup=1') +fio = require('fio') +--- +... +xlog = require('xlog') +--- +... +netbox = require('net.box') +--- +... +box.schema.user.grant('guest', 'read,write,execute', 'universe') +--- +... +-- +-- Check that xlogs doesn't contain IPROTO_SYNC +-- +conn = netbox.connect(box.cfg.listen) +--- +... +-- insert some row using the binary protocol +conn.space._schema:insert({'test'}) +--- +- ['test'] +... +-- rotate xlog +box.snapshot() +--- +- ok +... +-- dump xlog +xlog_path = fio.pathjoin(box.cfg.wal_dir, string.format("%020d.xlog", 0)) +--- +... +result = {} +--- +... +fun, param, state = xlog.pairs(xlog_path) +--- +... +-- skip grants until our insert into _schema +repeat state, row = fun(param, state) until row.BODY.space_id == box.space._schema.id +--- +... +row.HEADER.type +--- +- INSERT +... +row.HEADER.sync +--- +- null +... +row.BODY +--- +- space_id: 272 + tuple: ['test'] +... +box.space._schema:delete('test') +--- +- ['test'] +... +-- +-- Clean up +-- +box.schema.user.revoke('guest', 'read,write,execute', 'universe') +--- +... +netbox = nil +--- +... +xlog = nil +--- +... +fio = nil +--- +... diff --git a/test/xlog/misc.test.lua b/test/xlog/misc.test.lua new file mode 100644 index 0000000000..6f65c1370b --- /dev/null +++ b/test/xlog/misc.test.lua @@ -0,0 +1,36 @@ +test_run = require('test_run').new() +test_run:cmd('restart server default with cleanup=1') + +fio = require('fio') +xlog = require('xlog') +netbox = require('net.box') + +box.schema.user.grant('guest', 'read,write,execute', 'universe') + +-- +-- Check that xlogs doesn't contain IPROTO_SYNC +-- + +conn = netbox.connect(box.cfg.listen) +-- insert some row using the binary protocol +conn.space._schema:insert({'test'}) +-- rotate xlog +box.snapshot() +-- dump xlog +xlog_path = fio.pathjoin(box.cfg.wal_dir, string.format("%020d.xlog", 0)) +result = {} +fun, param, state = xlog.pairs(xlog_path) +-- skip grants until our insert into _schema +repeat state, row = fun(param, state) until row.BODY.space_id == box.space._schema.id +row.HEADER.type +row.HEADER.sync +row.BODY +box.space._schema:delete('test') + +-- +-- Clean up +-- +box.schema.user.revoke('guest', 'read,write,execute', 'universe') +netbox = nil +xlog = nil +fio = nil -- GitLab