From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp53.i.mail.ru (smtp53.i.mail.ru [94.100.177.113]) (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 207BF42EF60 for ; Thu, 18 Jun 2020 15:14:22 +0300 (MSK) From: Serge Petrenko Date: Thu, 18 Jun 2020 15:14:01 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/4] xrow: add ability to encode/decode ROLLBACK requests List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org ROLLBACK request contains the same data as CONFIRM request. The only difference is the request semantics. While a CONFIRM request releases all the limbo entries up to the given lsn, the ROLLBACK request rolls back all the entries with lsn greater than given one. Part-of #4848 --- src/box/iproto_constants.h | 9 +++++++++ src/box/xrow.c | 38 ++++++++++++++++++++++++++++++++++---- src/box/xrow.h | 23 +++++++++++++++++++++++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h index 1466b456f..45c8af236 100644 --- a/src/box/iproto_constants.h +++ b/src/box/iproto_constants.h @@ -221,6 +221,8 @@ enum iproto_type { /** A confirmation message for synchronous transactions. */ IPROTO_CONFIRM = 40, + /** A rollback message for synchronous transactions. */ + IPROTO_ROLLBACK = 41, /** PING request */ IPROTO_PING = 64, @@ -337,6 +339,13 @@ iproto_type_is_request(uint32_t type) return type > IPROTO_OK && type <= IPROTO_TYPE_STAT_MAX; } +/** CONFIRM/ROLLBACK entries for synchronous replication. */ +static inline bool +iproto_type_is_synchro_request(uint32_t type) +{ + return type == IPROTO_CONFIRM || type == IPROTO_ROLLBACK; +} + /** * The request is "synchronous": no other requests * on this connection should be taken before this one diff --git a/src/box/xrow.c b/src/box/xrow.c index 896e001b7..7a79a18dd 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -879,7 +879,8 @@ xrow_encode_dml(const struct request *request, struct region *region, } int -xrow_encode_confirm(struct xrow_header *row, uint32_t replica_id, int64_t lsn) +xrow_encode_confirm_rollback(struct xrow_header *row, uint32_t replica_id, + int64_t lsn) { size_t len = mp_sizeof_map(2) + mp_sizeof_uint(IPROTO_REPLICA_ID) + mp_sizeof_uint(replica_id) + mp_sizeof_uint(IPROTO_LSN) + @@ -903,13 +904,32 @@ xrow_encode_confirm(struct xrow_header *row, uint32_t replica_id, int64_t lsn) row->body[0].iov_len = len; row->bodycnt = 1; - row->type = IPROTO_CONFIRM; - return 0; } int -xrow_decode_confirm(struct xrow_header *row, uint32_t *replica_id, int64_t *lsn) +xrow_encode_confirm(struct xrow_header *row, uint32_t replica_id, int64_t lsn) +{ + int res = xrow_encode_confirm_rollback(row, replica_id, lsn); + if (res == 0) { + row->type = IPROTO_CONFIRM; + } + return res; +} + +int +xrow_encode_rollback(struct xrow_header *row, uint32_t replica_id, int64_t lsn) +{ + int res = xrow_encode_confirm_rollback(row, replica_id, lsn); + if (res == 0) { + row->type = IPROTO_ROLLBACK; + } + return res; +} + +int +xrow_decode_confirm_rollback(struct xrow_header *row, uint32_t *replica_id, + int64_t *lsn) { if (row->bodycnt == 0) { diag_set(ClientError, ER_INVALID_MSGPACK, "request body"); @@ -956,6 +976,16 @@ xrow_decode_confirm(struct xrow_header *row, uint32_t *replica_id, int64_t *lsn) return 0; } +int xrow_decode_confirm(struct xrow_header *row, uint32_t *replica_id, int64_t *lsn) +{ + return xrow_decode_confirm_rollback(row, replica_id, lsn); +} + +int xrow_decode_rollback(struct xrow_header *row, uint32_t *replica_id, int64_t *lsn) +{ + return xrow_decode_confirm_rollback(row, replica_id, lsn); +} + int xrow_to_iovec(const struct xrow_header *row, struct iovec *out) { diff --git a/src/box/xrow.h b/src/box/xrow.h index 027b6b14f..1def394e7 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -230,6 +230,29 @@ xrow_encode_confirm(struct xrow_header *row, uint32_t replica_id, int64_t lsn); int xrow_decode_confirm(struct xrow_header *row, uint32_t *replica_id, int64_t *lsn); +/** + * Encode the ROLLBACK row body and set row type to + * IPROTO_ROLLBACK. + * @param row xrow header. + * @param replica_id master's instance id. + * @param lsn lsn to rollback to. + * @retval -1 on error. + * @retval 0 success. + */ +int +xrow_encode_rollback(struct xrow_header *row, uint32_t replica_id, int64_t lsn); + +/** + * Decode the ROLLBACK row body. + * @param row xrow header. + * @param[out] replica_id master's instance id. + * @param[out] lsn lsn to rollback to. + * @retval -1 on error. + * @retval 0 success. + */ +int +xrow_decode_rollback(struct xrow_header *row, uint32_t *replica_id, int64_t *lsn); + /** * CALL/EVAL request. */ -- 2.24.3 (Apple Git-128)