From: Serge Petrenko <sergepetrenko@tarantool.org> To: v.shpilevoy@tarantool.org, gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH 2/4] xrow: add ability to encode/decode ROLLBACK requests Date: Thu, 18 Jun 2020 15:14:01 +0300 [thread overview] Message-ID: <c019cb4048fc6cf26c4b5c9f0ac80ae0e0fa96d6.1592482315.git.sergepetrenko@tarantool.org> (raw) In-Reply-To: <cover.1592482315.git.sergepetrenko@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)
next prev parent reply other threads:[~2020-06-18 12:14 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-18 12:13 [Tarantool-patches] [PATCH 0/4] sync replication: add rollback processing Serge Petrenko 2020-06-18 12:14 ` [Tarantool-patches] [PATCH 1/4] xrow: fix comment typo Serge Petrenko 2020-06-18 22:15 ` Vladislav Shpilevoy 2020-06-18 22:15 ` Vladislav Shpilevoy 2020-06-19 17:28 ` Serge Petrenko 2020-06-18 12:14 ` Serge Petrenko [this message] 2020-06-18 14:46 ` [Tarantool-patches] [PATCH 2/4] xrow: add ability to encode/decode ROLLBACK requests Cyrill Gorcunov 2020-06-19 17:30 ` Serge Petrenko 2020-06-18 12:14 ` [Tarantool-patches] [PATCH 3/4] txn_limbo: add timeout when waiting for acks Serge Petrenko 2020-06-18 12:14 ` [Tarantool-patches] [PATCH 4/4] txn_limbo: add ROLLBACK processing Serge Petrenko 2020-06-18 22:15 ` Vladislav Shpilevoy 2020-06-19 17:35 ` Serge Petrenko 2020-06-21 15:53 ` Vladislav Shpilevoy 2020-06-19 17:53 ` Serge Petrenko 2020-06-23 8:37 ` Serge Petrenko 2020-06-25 22:14 ` Vladislav Shpilevoy 2020-06-25 22:43 ` Vladislav Shpilevoy
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=c019cb4048fc6cf26c4b5c9f0ac80ae0e0fa96d6.1592482315.git.sergepetrenko@tarantool.org \ --to=sergepetrenko@tarantool.org \ --cc=gorcunov@gmail.com \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 2/4] xrow: add ability to encode/decode ROLLBACK requests' \ /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