From: Serge Petrenko <sergepetrenko@tarantool.org> To: Leonid Vasiliev <lvasiliev@tarantool.org>, v.shpilevoy@tarantool.org, sergos@tarantool.org, gorcunov@gmail.com Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH 7/8] xrow: introduce CONFIRM entry Date: Mon, 22 Jun 2020 13:14:18 +0300 [thread overview] Message-ID: <7e5892d4-97d5-eab5-6766-3be9e5541198@tarantool.org> (raw) In-Reply-To: <1bc2476a-01f9-a367-4138-c373915ce62e@tarantool.org> 19.06.2020 18:18, Leonid Vasiliev пишет: > LGTM. > All the following comments can be skipped silently. Hi! Thanks for the review! > > On 09.06.2020 15:20, Serge Petrenko wrote: >> Add methods to encode/decode CONFIRM entry. >> A CONFIRM entry will be written to WAL by synchronous replication master >> as soon as it finds that the transaction was applied on a quorum of >> replicas. >> CONFIRM rows share the same header with other rows in WAL,but their body >> differs: it's just a map containing replica_id and lsn of the last >> confirmed transaction. >> >> Part-of #4847 >> --- >> src/box/iproto_constants.h | 3 ++ >> src/box/xrow.c | 74 ++++++++++++++++++++++++++++++++++++++ >> src/box/xrow.h | 23 ++++++++++++ >> 3 files changed, 100 insertions(+) >> >> diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h >> index f8eee0f3f..1466b456f 100644 >> --- a/src/box/iproto_constants.h >> +++ b/src/box/iproto_constants.h >> @@ -219,6 +219,9 @@ enum iproto_type { >> /** The maximum typecode used for box.stat() */ >> IPROTO_TYPE_STAT_MAX, >> + /** A confirmation message for synchronous transactions. */ >> + IPROTO_CONFIRM = 40, >> + > > Seems like IPROTO_CONFIRM must be added to the documentation. If it's > true, please add @TarantoolBot. I agree, added doc requests for CONFIRM and ROLLBACK. > >> /** PING request */ >> IPROTO_PING = 64, >> /** Replication JOIN command */ >> diff --git a/src/box/xrow.c b/src/box/xrow.c >> index bb64864b2..f197e0d85 100644 >> --- a/src/box/xrow.c >> +++ b/src/box/xrow.c >> @@ -878,6 +878,80 @@ xrow_encode_dml(const struct request *request, >> struct region *region, >> return iovcnt; >> } >> +int >> +xrow_encode_confirm(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) + >> + mp_sizeof_uint(lsn); >> + char *buf = (char *)region_alloc(&fiber()->gc, len); >> + if (buf == NULL) { >> + diag_set(OutOfMemory, len, "region_alloc", "buf"); >> + return -1; >> + } >> + char *pos = buf; >> + >> + pos = mp_encode_map(pos, 2); >> + pos = mp_encode_uint(pos, IPROTO_REPLICA_ID); >> + pos = mp_encode_uint(pos, replica_id); >> + pos = mp_encode_uint(pos, IPROTO_LSN); >> + pos = mp_encode_uint(pos, lsn); >> + >> + row->body[0].iov_base = buf; >> + row->body[0].iov_len = len; >> + >> + row->type = IPROTO_CONFIRM; >> + >> + return 1; >> +} > > At the last version > memset(row, 0, sizeof(*row)); > was added. But, usually it is initialized at the beginning of the > function, because otherwise it is possible to do return without > initializing of the row. It does not look like a problem, the decision > is yours. I left it as is, looks strange if I memset the row before an error can happen IMO. > >> + >> +int >> +xrow_decode_confirm(struct xrow_header *row, uint32_t *replica_id, >> int64_t *lsn) >> +{ >> + if (row->bodycnt == 0) { >> + diag_set(ClientError, ER_INVALID_MSGPACK, "request body"); >> + return -1; >> + } >> + >> + assert(row->bodycnt == 1); >> + >> + const char * const data = (const char *)row->body[0].iov_base; >> + const char * const end = data + row->body[0].iov_len; >> + const char *d = data; >> + if (mp_check(&d, end) != 0 || mp_typeof(*data) != MP_MAP) { >> + xrow_on_decode_err(data, end, ER_INVALID_MSGPACK, >> + "request body"); >> + return -1; >> + } >> + >> + d = data; >> + uint32_t map_size = mp_decode_map(&d); >> + for (uint32_t i = 0; i < map_size; i++) { >> + if (mp_typeof(*d) != MP_UINT) { >> + mp_next(&d); >> + mp_next(&d); >> + continue; >> + } >> + uint8_t key = mp_decode_uint(&d); >> + if (key >= IPROTO_KEY_MAX || iproto_key_type[key] != >> + mp_typeof(*d)) { >> + xrow_on_decode_err(data, end, ER_INVALID_MSGPACK, >> + "request body"); >> + } >> + switch (key) { >> + case IPROTO_REPLICA_ID: >> + *replica_id = mp_decode_uint(&d); >> + break; >> + case IPROTO_LSN: >> + *lsn = mp_decode_uint(&d); >> + break; >> + default: >> + mp_next(&d); >> + } >> + } >> + return 0; >> +} >> + >> 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 2a0a9c852..75af71b77 100644 >> --- a/src/box/xrow.h >> +++ b/src/box/xrow.h >> @@ -207,6 +207,29 @@ int >> xrow_encode_dml(const struct request *request, struct region *region, >> struct iovec *iov); >> +/** >> + * Encode the CONFIRM to row body and set row type to >> + * IPROTO_CONFIRM. >> + * @param row xrow header. >> + * @param replica_id master's instance id. >> + * @param lsn last confirmed lsn. >> + * @retval -1 on error. >> + * @retval > 0 xrow bodycnt. >> + */ >> +int >> +xrow_encode_confirm(struct xrow_header *row, uint32_t replica_id, >> int64_t lsn); >> + >> +/** >> + * Decode the CONFIRM request body. >> + * @param row xrow header. >> + * @param[out] replica_id master's instance id. >> + * @param[out] lsn last confirmed lsn. >> + * @retwal -1 on error. >> + * @retwal 0 success. > > The typo is fixed by you in "xrow: fix comment typo". > Squashed it into this commit. >> + */ >> +int >> +xrow_decode_confirm(struct xrow_header *row, uint32_t *replica_id, >> int64_t *lsn); >> + >> /** >> * CALL/EVAL request. >> */ >> -- Serge Petrenko
next prev parent reply other threads:[~2020-06-22 10:14 UTC|newest] Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-09 12:20 [Tarantool-patches] [PATCH 0/8] wait for lsn and confirm Serge Petrenko 2020-06-09 12:20 ` [Tarantool-patches] [PATCH 1/8] replication: introduce space.is_sync option Serge Petrenko 2020-06-10 23:51 ` Vladislav Shpilevoy 2020-06-18 22:27 ` Leonid Vasiliev 2020-06-21 16:24 ` Vladislav Shpilevoy 2020-06-09 12:20 ` [Tarantool-patches] [PATCH 2/8] replication: introduce replication_sync_quorum cfg Serge Petrenko 2020-06-10 23:51 ` Vladislav Shpilevoy 2020-06-15 23:05 ` Vladislav Shpilevoy 2020-06-18 22:54 ` Leonid Vasiliev 2020-06-19 17:45 ` Serge Petrenko 2020-06-21 16:25 ` Vladislav Shpilevoy 2020-06-09 12:20 ` [Tarantool-patches] [PATCH 3/8] txn: add TXN_WAIT_ACK flag Serge Petrenko 2020-06-18 23:12 ` Leonid Vasiliev 2020-06-21 16:25 ` Vladislav Shpilevoy 2020-06-22 9:44 ` Serge Petrenko 2020-06-23 22:13 ` Vladislav Shpilevoy 2020-06-09 12:20 ` [Tarantool-patches] [PATCH 4/8] replication: make sync transactions wait quorum Serge Petrenko 2020-06-10 23:51 ` Vladislav Shpilevoy 2020-06-11 14:57 ` Vladislav Shpilevoy 2020-06-15 23:05 ` Vladislav Shpilevoy 2020-06-19 12:39 ` Leonid Vasiliev 2020-06-25 21:48 ` Vladislav Shpilevoy 2020-06-09 12:20 ` [Tarantool-patches] [PATCH 5/8] txn_limbo: follow-up fixes Serge Petrenko 2020-06-10 23:51 ` Vladislav Shpilevoy 2020-06-11 8:46 ` Serge Petrenko 2020-06-11 13:01 ` Vladislav Shpilevoy 2020-06-09 12:20 ` [Tarantool-patches] [PATCH 6/8] txn_limbo: fix instance id assignment Serge Petrenko 2020-06-10 23:51 ` Vladislav Shpilevoy 2020-06-09 12:20 ` [Tarantool-patches] [PATCH 7/8] xrow: introduce CONFIRM entry Serge Petrenko 2020-06-19 15:18 ` Leonid Vasiliev 2020-06-22 10:14 ` Serge Petrenko [this message] 2020-06-23 8:33 ` Serge Petrenko 2020-06-09 12:20 ` [Tarantool-patches] [PATCH 8/8] replication: write and read CONFIRM entries Serge Petrenko 2020-06-10 23:51 ` Vladislav Shpilevoy 2020-06-11 8:56 ` Serge Petrenko 2020-06-11 13:04 ` Vladislav Shpilevoy 2020-06-11 14:57 ` Vladislav Shpilevoy 2020-06-15 23:05 ` Vladislav Shpilevoy 2020-06-18 11:32 ` Leonid Vasiliev 2020-06-18 21:49 ` Vladislav Shpilevoy 2020-06-19 17:48 ` Serge Petrenko 2020-06-19 17:50 ` Serge Petrenko 2020-06-23 8:35 ` Serge Petrenko 2020-06-20 15:06 ` Leonid Vasiliev 2020-06-22 10:34 ` Serge Petrenko 2020-06-23 8:34 ` Serge Petrenko 2020-06-25 22:04 ` Vladislav Shpilevoy 2020-06-25 22:31 ` Vladislav Shpilevoy 2020-06-26 10:58 ` Serge Petrenko 2020-06-09 12:53 ` [Tarantool-patches] [PATCH 0/2] A few fixes for building Cyrill Gorcunov 2020-06-09 12:53 ` [Tarantool-patches] [PATCH 1/2] box/applier: fix typo Cyrill Gorcunov 2020-06-10 9:18 ` Sergey Ostanevich 2020-06-09 12:53 ` [Tarantool-patches] [PATCH 2/2] box: use tnt_raise for quorum check Cyrill Gorcunov 2020-06-10 9:17 ` Sergey Ostanevich 2020-06-10 10:45 ` Serge Petrenko 2020-06-22 21:51 ` [Tarantool-patches] [PATCH 0/8] wait for lsn and confirm 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=7e5892d4-97d5-eab5-6766-3be9e5541198@tarantool.org \ --to=sergepetrenko@tarantool.org \ --cc=gorcunov@gmail.com \ --cc=lvasiliev@tarantool.org \ --cc=sergos@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 7/8] xrow: introduce CONFIRM entry' \ /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