From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 74EE66ECDC; Mon, 6 Dec 2021 06:03:59 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 74EE66ECDC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1638759839; bh=xIwI6OZjVMuK6/ch4ZMcxBwPnVhOxCZjXpcWv1uuW2A=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=tg9WFvzpKkXWVxI+K+TwUKDC6WUYKwTikmllZDK5gMMUXQDKaqF+U3Buhyrt+MjZD YQ+SatOHrl1vDoRM0pJB/Q0QKBB1hOVnd86gNAKmiL2OLG9DNiQELnP7guL6r7i9v+ carz5YtrAPv7ilFmfn4gpugGCBJpIdY/ScMZch1o= Received: from smtp38.i.mail.ru (smtp38.i.mail.ru [94.100.177.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4FF776ECDE for ; Mon, 6 Dec 2021 06:03:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4FF776ECDE Received: by smtp38.i.mail.ru with esmtpa (envelope-from ) id 1mu4Hn-0007aS-8D; Mon, 06 Dec 2021 06:03:27 +0300 To: v.shpilevoy@tarantool.org, vdavydov@tarantool.org Date: Mon, 6 Dec 2021 06:03:20 +0300 Message-Id: <76b802ed3cfa45a87f2610a9e05b71bc14dfb36a.1638757827.git.sergepetrenko@tarantool.org> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD93822B471089FF64D4E646BE16CEFF463156D8594F96ADA64182A05F5380850403F7A034859E56674098FA87BEDD8F42ADB227EB8D92A3A579FB6B48A1CA0F0E9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DC4D3EB6E237C32AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374F638C8F0F4AA0FB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8FA14E8364CC620380A1E1B4DB5ABA671117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCE2CCD8F0CAA010FB389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8A816C540FC8EEC30F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CAD098BC592226770040F9FF01DFDA4A84AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C35A87C19D41235D19BA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE7A342EAC7F3A94D1B731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC44C234C8B12C006B7A07FEF4BC0B92C68B35969AAEEF083DED18B279B650F7E5E0B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDBF87214F1A954108EDC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34060C3C6DE316ECE427C5D1F292C3EA45D8CE5AF212B86B7B385D3455BB8076859BB7A2ED6DB88B441D7E09C32AA3244CE678E9EC10D012AD69B98F7261FE3E6E725D5B54B2FE4575927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiGu4RiEaSSzoq29x7ji4I8 X-Mailru-Sender: 583F1D7ACE8F49BD7B46BC6C7C9DD5A8AA235155620D99CD001B9C23E0B679A3D1782EF084D872BC424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BCB0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 1/4] xrow: rework coio_read_xrow to keep parsed input X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" coio_read_xrow(_timeout_xc) uses an ibuf as a temporary storage for input. It parses the xrow upon receipt and immediately discards the input buffer. This means that the just parsed xrow's body may be used only until the next row is read: each new read may reuse the space where row's body was located. So once the user has to read multiple rows (say, a transaction) before processing them, he is forced to copy rows' bodies to some other location. Let's better let the user decide whether input should be immediately discarded or not. Introduce coio_read_xrow_ex(_timeout_xc), which doesn't discard the input upon parse, and uses ibuf->xpos instead of ibuf->rpos to point at the end of parsed data. This way the user is free to decide when to advance ibuf->rpos and discard the input. Introduce macros with old behaviour for xrow_read_xrow(_timeout_xc). Prerequisite #6329 --- src/box/xrow_io.cc | 28 ++++++++++++++-------------- src/box/xrow_io.h | 18 +++++++++++++++--- src/lib/small | 2 +- src/lua/buffer.lua | 2 ++ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/box/xrow_io.cc b/src/box/xrow_io.cc index 20e327239..9d0d4b12e 100644 --- a/src/box/xrow_io.cc +++ b/src/box/xrow_io.cc @@ -36,61 +36,61 @@ #include "msgpuck/msgpuck.h" void -coio_read_xrow(struct iostream *io, struct ibuf *in, struct xrow_header *row) +coio_read_xrow_ex(struct iostream *io, struct ibuf *in, struct xrow_header *row) { /* Read fixed header */ - if (ibuf_used(in) < 1) + if (ibuf_unparsed(in) < 1) coio_breadn(io, in, 1); /* Read length */ - if (mp_typeof(*in->rpos) != MP_UINT) { + if (mp_typeof(*in->xpos) != MP_UINT) { tnt_raise(ClientError, ER_INVALID_MSGPACK, "packet length"); } - ssize_t to_read = mp_check_uint(in->rpos, in->wpos); + ssize_t to_read = mp_check_uint(in->xpos, in->wpos); if (to_read > 0) coio_breadn(io, in, to_read); - uint32_t len = mp_decode_uint((const char **) &in->rpos); + uint32_t len = mp_decode_uint((const char **) &in->xpos); /* Read header and body */ - to_read = len - ibuf_used(in); + to_read = len - ibuf_unparsed(in); if (to_read > 0) coio_breadn(io, in, to_read); - xrow_header_decode_xc(row, (const char **) &in->rpos, in->rpos + len, + xrow_header_decode_xc(row, (const char **) &in->xpos, in->xpos + len, true); } void -coio_read_xrow_timeout_xc(struct iostream *io, struct ibuf *in, +coio_read_xrow_ex_timeout_xc(struct iostream *io, struct ibuf *in, struct xrow_header *row, ev_tstamp timeout) { ev_tstamp start, delay; coio_timeout_init(&start, &delay, timeout); /* Read fixed header */ - if (ibuf_used(in) < 1) + if (ibuf_unparsed(in) < 1) coio_breadn_timeout(io, in, 1, delay); coio_timeout_update(&start, &delay); /* Read length */ - if (mp_typeof(*in->rpos) != MP_UINT) { + if (mp_typeof(*in->xpos) != MP_UINT) { tnt_raise(ClientError, ER_INVALID_MSGPACK, "packet length"); } - ssize_t to_read = mp_check_uint(in->rpos, in->wpos); + ssize_t to_read = mp_check_uint(in->xpos, in->wpos); if (to_read > 0) coio_breadn_timeout(io, in, to_read, delay); coio_timeout_update(&start, &delay); - uint32_t len = mp_decode_uint((const char **) &in->rpos); + uint32_t len = mp_decode_uint((const char **) &in->xpos); /* Read header and body */ - to_read = len - ibuf_used(in); + to_read = len - ibuf_unparsed(in); if (to_read > 0) coio_breadn_timeout(io, in, to_read, delay); - xrow_header_decode_xc(row, (const char **) &in->rpos, in->rpos + len, + xrow_header_decode_xc(row, (const char **) &in->xpos, in->xpos + len, true); } diff --git a/src/box/xrow_io.h b/src/box/xrow_io.h index 4e81b6e0c..5ecdd108e 100644 --- a/src/box/xrow_io.h +++ b/src/box/xrow_io.h @@ -39,11 +39,23 @@ struct iostream; struct xrow_header; void -coio_read_xrow(struct iostream *io, struct ibuf *in, struct xrow_header *row); +coio_read_xrow_ex(struct iostream *io, struct ibuf *in, struct xrow_header *row); + +#define coio_read_xrow(io, in, row) \ + do { \ + coio_read_xrow_ex(io, in, row); \ + (in)->rpos = (in)->xpos; \ + } while (0) void -coio_read_xrow_timeout_xc(struct iostream *io, struct ibuf *in, - struct xrow_header *row, double timeout); +coio_read_xrow_ex_timeout_xc(struct iostream *io, struct ibuf *in, + struct xrow_header *row, double timeout); + +#define coio_read_xrow_timeout_xc(io, in, row, timeout) \ + do { \ + coio_read_xrow_ex_timeout_xc(io, in, row, timeout); \ + (in)->rpos = (in)->xpos; \ + } while (0) void coio_write_xrow(struct iostream *io, const struct xrow_header *row); diff --git a/src/lib/small b/src/lib/small index 3d15a7058..47ca9ee09 160000 --- a/src/lib/small +++ b/src/lib/small @@ -1 +1 @@ -Subproject commit 3d15a705817ff60ef6fe5e4b70ae4c09056927e3 +Subproject commit 47ca9ee09a9e1ae052c1111b3220751d3fe035b0 diff --git a/src/lua/buffer.lua b/src/lua/buffer.lua index 182c0b015..cab0544e6 100644 --- a/src/lua/buffer.lua +++ b/src/lua/buffer.lua @@ -23,6 +23,8 @@ struct ibuf char *buf; /** Start of input. */ char *rpos; + /** End of parsed input. */ + char *xpos; /** End of useful input */ char *wpos; /** End of ibuf. */ -- 2.30.1 (Apple Git-130)