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 E2F496FC86; Wed, 24 Mar 2021 15:25:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E2F496FC86 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616588722; bh=mLRKbGwNx2TlnJC6vyBUT1FmJLsYtHIGGjmiQuHaobk=; 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=QBOjU0oBVlY7sHPW5UI9PQTHDf5j/1UN4rgG49OyPBCJ0Bn2SCl2coU5dMgErFI9B 1gL5Hz55yrdcoAbrBo0O3mhWeYrObC7XIKJYCfy1JlyJkWwJ5OWOD3Ye1T3ufbrHlq w1AVBbLXzTnum15VNjDEM7XXVAnEBmComfG2SZB8= Received: from smtp36.i.mail.ru (smtp36.i.mail.ru [94.100.177.96]) (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 CD8806BD36 for ; Wed, 24 Mar 2021 15:24:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CD8806BD36 Received: by smtp36.i.mail.ru with esmtpa (envelope-from ) id 1lP2Yf-0004oK-TK; Wed, 24 Mar 2021 15:24:22 +0300 To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Date: Wed, 24 Mar 2021 15:24:12 +0300 Message-Id: <31d242da3f691029c6fc670c902290a77fe36ae1.1616588119.git.sergepetrenko@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD95D6E7CC48CB1F5F1C82687294EF6886B62CC997B0B8C95C4182A05F5380850403970D95E56B8092F22C68B6BDCBA90D86EB45ECFD3D35F07F4AC8848B3ECD15D X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F65C230EDDCD559EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637FC0948D7756001208638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95C5DD32608FC869F5D89A5E23D75EC334E704A4F9D1E7B3316A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE74A95F4E53E8DCE969FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3643C8550F8485502117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CFC3EE3AD8B11647D1BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B665B51FCB6D83180676E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B3BBE47FD9DD3FB59A8DF7F3B2552694A2BEBFE083D3B9BA73A03B725D353964BB11811A4A51E3B096D1867E19FE14079BA9C0B312567BB23089D37D7C0E48F6CA18204E546F3947CC0F9454058DFE53C262FEC7FBD7D1F5BC8A9BA7A39EFB7666BA297DBC24807EA089D37D7C0E48F6C8AA50765F79006377AD8C0A31FFD7ED5EFF80C71ABB335746BA297DBC24807EA27F269C8F02392CD20465B3A5AADEC6827F269C8F02392CD5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183A4AFAF3EA6BDC44C234C8B12C006B7A5F433A0BE06BC46560C526AD4FC85CD3D8487B63C654BDC6B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDB63AF70AF8205D7DCDC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34B5900AD87B4159A4F72061D58A37013BF424D18F38C265E89A148D0442B9E1BF7CE86C7A2171265B1D7E09C32AA3244CC9761E2DA23C08F1B7149B3868A05E8D55E75C8D0ED9F6EE927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXjhXhGERY7yL/0lKdcCMeuM X-Mailru-Sender: 583F1D7ACE8F49BDD2846D59FC20E9F86C523D0B3819F67E0F5C3699CDDE0618DD40DC63F2C6AA45424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 2/7] applier: extract tx boundary checks from applier_read_tx into a separate routine 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" Introduce a new routine, set_next_tx_row(), which checks tx boundary violation and appends the new row to the current tx in case everything is ok. set_next_tx_row() is extracted from applier_read_tx() because it's a common part of transaction assembly both for recovery and applier. The only difference for recovery will be that the routine which's responsible for tx assembly won't read rows. It'll be a callback ran on each new row being read from WAL. Prerequisite #5874 Part-of #5566 --- src/box/applier.cc | 117 +++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/src/box/applier.cc b/src/box/applier.cc index 326cf18d2..65afa5e98 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -657,6 +657,64 @@ applier_read_tx_row(struct applier *applier) return tx_row; } +static inline int64_t +set_next_tx_row(struct stailq *rows, struct applier_tx_row *tx_row, int64_t tsn) +{ + struct xrow_header *row = &tx_row->row; + + if (iproto_type_is_error(row->type)) + xrow_decode_error_xc(row); + + /* Replication request. */ + if (row->replica_id >= VCLOCK_MAX) { + /* + * A safety net, this can only occur if we're fed a strangely + * broken xlog. row->replica_id == 0, when reading heartbeats + * from an anonymous instance. + */ + tnt_raise(ClientError, ER_UNKNOWN_REPLICA, + int2str(row->replica_id), + tt_uuid_str(&REPLICASET_UUID)); + } + if (tsn == 0) { + /* + * Transaction id must be derived from the log sequence number + * of the first row in the transaction. + */ + tsn = row->tsn; + if (row->lsn != tsn) + tnt_raise(ClientError, ER_PROTOCOL, + "Transaction id must be equal to LSN of the " + "first row in the transaction."); + } else if (tsn != row->tsn) { + tnt_raise(ClientError, ER_UNSUPPORTED, "replication", + "interleaving transactions"); + } + + assert(row->bodycnt <= 1); + if (row->is_commit) { + /* Signal the caller that we've reached the tx end. */ + tsn = 0; + } else if (row->bodycnt == 1) { + /* + * Save row body to gc region. Not done for single-statement + * transactions and the last row of multi-statement transactions + * knowing that the input buffer will not be used while the + * transaction is applied. + */ + void *new_base = region_alloc(&fiber()->gc, row->body->iov_len); + if (new_base == NULL) + tnt_raise(OutOfMemory, row->body->iov_len, "region", + "xrow body"); + memcpy(new_base, row->body->iov_base, row->body->iov_len); + /* Adjust row body pointers. */ + row->body->iov_base = new_base; + } + + stailq_add_tail(rows, &tx_row->next); + return tsn; +} + /** * Read one transaction from network using applier's input buffer. * Transaction rows are placed onto fiber gc region. @@ -672,63 +730,8 @@ applier_read_tx(struct applier *applier, struct stailq *rows) stailq_create(rows); do { struct applier_tx_row *tx_row = applier_read_tx_row(applier); - struct xrow_header *row = &tx_row->row; - - if (iproto_type_is_error(row->type)) - xrow_decode_error_xc(row); - - /* Replication request. */ - if (row->replica_id >= VCLOCK_MAX) { - /* - * A safety net, this can only occur - * if we're fed a strangely broken xlog. - * row->replica_id == 0, when reading - * heartbeats from an anonymous instance. - */ - tnt_raise(ClientError, ER_UNKNOWN_REPLICA, - int2str(row->replica_id), - tt_uuid_str(&REPLICASET_UUID)); - } - if (tsn == 0) { - /* - * Transaction id must be derived from the log sequence - * number of the first row in the transaction. - */ - tsn = row->tsn; - if (row->lsn != tsn) - tnt_raise(ClientError, ER_PROTOCOL, - "Transaction id must be equal to " - "LSN of the first row in the " - "transaction."); - } - if (tsn != row->tsn) - tnt_raise(ClientError, ER_UNSUPPORTED, - "replication", - "interleaving transactions"); - - assert(row->bodycnt <= 1); - if (row->bodycnt == 1 && !row->is_commit) { - /* - * Save row body to gc region. - * Not done for single-statement - * transactions knowing that the input - * buffer will not be used while the - * transaction is applied. - */ - void *new_base = region_alloc(&fiber()->gc, - row->body->iov_len); - if (new_base == NULL) - tnt_raise(OutOfMemory, row->body->iov_len, - "region", "xrow body"); - memcpy(new_base, row->body->iov_base, - row->body->iov_len); - /* Adjust row body pointers. */ - row->body->iov_base = new_base; - } - stailq_add_tail(rows, &tx_row->next); - - } while (!stailq_last_entry(rows, struct applier_tx_row, - next)->row.is_commit); + tsn = set_next_tx_row(rows, tx_row, tsn); + } while (tsn != 0); } static void -- 2.24.3 (Apple Git-128)