From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH v3 02/11] xrow: factor out function for decoding vclock
Date: Sat, 14 Jul 2018 23:49:17 +0300 [thread overview]
Message-ID: <48d9fdcb763debb0deccc0d16aaf0752abbb38c7.1531598427.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1531598427.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1531598427.git.vdavydov.dev@gmail.com>
We will need it in other places.
---
src/box/xrow.c | 45 +++++++++++++++++++++------------------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/src/box/xrow.c b/src/box/xrow.c
index 11316906..56197d0e 100644
--- a/src/box/xrow.c
+++ b/src/box/xrow.c
@@ -64,6 +64,26 @@ mp_encode_vclock(char *data, const struct vclock *vclock)
return data;
}
+static int
+mp_decode_vclock(const char **data, struct vclock *vclock)
+{
+ vclock_create(vclock);
+ if (mp_typeof(**data) != MP_MAP)
+ return -1;
+ uint32_t size = mp_decode_map(data);
+ for (uint32_t i = 0; i < size; i++) {
+ if (mp_typeof(**data) != MP_UINT)
+ return -1;
+ uint32_t id = mp_decode_uint(data);
+ if (mp_typeof(**data) != MP_UINT)
+ return -1;
+ int64_t lsn = mp_decode_uint(data);
+ if (lsn > 0)
+ vclock_follow(vclock, id, lsn);
+ }
+ return 0;
+}
+
int
xrow_header_decode(struct xrow_header *header, const char **pos,
const char *end)
@@ -885,7 +905,6 @@ xrow_decode_subscribe(struct xrow_header *row, struct tt_uuid *replicaset_uuid,
/* For backward compatibility initialize read-only with false. */
if (read_only)
*read_only = false;
- const char *lsnmap = NULL;
d = data;
uint32_t map_size = mp_decode_map(&d);
for (uint32_t i = 0; i < map_size; i++) {
@@ -911,13 +930,11 @@ xrow_decode_subscribe(struct xrow_header *row, struct tt_uuid *replicaset_uuid,
case IPROTO_VCLOCK:
if (vclock == NULL)
goto skip;
- if (mp_typeof(*d) != MP_MAP) {
+ if (mp_decode_vclock(&d, vclock) != 0) {
diag_set(ClientError, ER_INVALID_MSGPACK,
"invalid VCLOCK");
return -1;
}
- lsnmap = d;
- mp_next(&d);
break;
case IPROTO_SERVER_VERSION:
if (version_id == NULL)
@@ -943,26 +960,6 @@ xrow_decode_subscribe(struct xrow_header *row, struct tt_uuid *replicaset_uuid,
mp_next(&d); /* value */
}
}
-
- if (lsnmap == NULL)
- return 0;
-
- /* Check & save LSNMAP */
- d = lsnmap;
- uint32_t lsnmap_size = mp_decode_map(&d);
- for (uint32_t i = 0; i < lsnmap_size; i++) {
- if (mp_typeof(*d) != MP_UINT) {
- map_error:
- diag_set(ClientError, ER_INVALID_MSGPACK, "VCLOCK");
- return -1;
- }
- uint32_t id = mp_decode_uint(&d);
- if (mp_typeof(*d) != MP_UINT)
- goto map_error;
- int64_t lsn = (int64_t) mp_decode_uint(&d);
- if (lsn > 0)
- vclock_follow(vclock, id, lsn);
- }
return 0;
}
--
2.11.0
next prev parent reply other threads:[~2018-07-14 20:49 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-14 20:49 [PATCH v3 00/11] Replica rejoin Vladimir Davydov
2018-07-14 20:49 ` [PATCH v3 01/11] recovery: clean up WAL dir scan code Vladimir Davydov
2018-07-19 7:08 ` Konstantin Osipov
2018-07-14 20:49 ` Vladimir Davydov [this message]
2018-07-19 7:08 ` [PATCH v3 02/11] xrow: factor out function for decoding vclock Konstantin Osipov
2018-07-14 20:49 ` [PATCH v3 03/11] Introduce IPROTO_REQUEST_STATUS command Vladimir Davydov
2018-07-19 7:10 ` Konstantin Osipov
2018-07-19 8:17 ` Vladimir Davydov
2018-07-21 10:25 ` Vladimir Davydov
2018-07-14 20:49 ` [PATCH v3 04/11] Get rid of IPROTO_SERVER_IS_RO Vladimir Davydov
2018-07-19 7:10 ` Konstantin Osipov
2018-07-21 12:07 ` Vladimir Davydov
2018-07-14 20:49 ` [PATCH v3 05/11] gc: keep track of vclocks instead of signatures Vladimir Davydov
2018-07-19 7:11 ` Konstantin Osipov
2018-07-14 20:49 ` [PATCH v3 06/11] Include oldest vclock available on the instance in IPROTO_STATUS Vladimir Davydov
2018-07-19 7:12 ` Konstantin Osipov
2018-07-21 12:07 ` Vladimir Davydov
2018-07-14 20:49 ` [PATCH v3 07/11] replication: rebootstrap instance on startup if it fell behind Vladimir Davydov
2018-07-19 7:19 ` Konstantin Osipov
2018-07-19 10:04 ` Vladimir Davydov
2018-07-23 20:19 ` Konstantin Osipov
2018-07-27 16:13 ` [PATCH] replication: print master uuid when (re)bootstrapping Vladimir Davydov
2018-07-31 8:34 ` Vladimir Davydov
2018-07-14 20:49 ` [PATCH v3 08/11] vinyl: simplify vylog recovery from backup Vladimir Davydov
2018-07-31 8:21 ` Vladimir Davydov
2018-07-14 20:49 ` [PATCH v3 09/11] vinyl: pass flags to vy_recovery_new Vladimir Davydov
2018-07-21 11:12 ` Vladimir Davydov
2018-07-14 20:49 ` [PATCH v3 10/11] Update test-run Vladimir Davydov
2018-07-21 11:13 ` Vladimir Davydov
2018-07-14 20:49 ` [PATCH v3 11/11] vinyl: implement rebootstrap support Vladimir Davydov
2018-07-31 8:23 ` Vladimir Davydov
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=48d9fdcb763debb0deccc0d16aaf0752abbb38c7.1531598427.git.vdavydov.dev@gmail.com \
--to=vdavydov.dev@gmail.com \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH v3 02/11] xrow: factor out function for decoding vclock' \
/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