[Tarantool-patches] [PATCH v2 08/11] raft: relay status updates to followers
Serge Petrenko
sergepetrenko at tarantool.org
Tue Sep 22 11:48:06 MSK 2020
22.09.2020 01:47, Vladislav Shpilevoy пишет:
> Consider my commit on top of your changes:
>
> ====================
> [tosquash] raft: vclock should be out parameter; reduce diff
>
> Firstly I made raft_serialize_for_network() use its vclock
> parameter as an out parameter. Because it is Raft's deal what
> vclock it wants to send. It can't be dictated by the function
> caller.
>
> Secondly, I renamed data back to buf in xrow.c in order to reduce
> diff from the previous patches.
LGTM
>
> diff --git a/src/box/raft.c b/src/box/raft.c
> index c2ef9ff39..2bf8490ea 100644
> --- a/src/box/raft.c
> +++ b/src/box/raft.c
> @@ -115,8 +115,10 @@ raft_serialize_for_network(struct raft_request *req, struct vclock *vclock)
> * Raft does not own vclock, so it always expects it passed externally.
> * Vclock is sent out only by candidate instances.
> */
> - if (req->state == RAFT_STATE_CANDIDATE)
> + if (req->state == RAFT_STATE_CANDIDATE) {
> req->vclock = vclock;
> + vclock_copy(vclock, &replicaset.vclock);
> + }
> }
>
> void
> diff --git a/src/box/xrow.c b/src/box/xrow.c
> index 250794a3e..da5c6ffae 100644
> --- a/src/box/xrow.c
> +++ b/src/box/xrow.c
> @@ -996,26 +996,24 @@ xrow_encode_raft(struct xrow_header *row, struct region *region,
> row->body[0].iov_base = buf;
> row->group_id = GROUP_LOCAL;
> row->bodycnt = 1;
> - char *data = buf;
> + const char *begin = buf;
>
> - data = mp_encode_map(data, map_size);
> - data = mp_encode_uint(data, IPROTO_RAFT_TERM);
> - data = mp_encode_uint(data, r->term);
> + buf = mp_encode_map(buf, map_size);
> + buf = mp_encode_uint(buf, IPROTO_RAFT_TERM);
> + buf = mp_encode_uint(buf, r->term);
> if (r->vote != 0) {
> - data = mp_encode_uint(data, IPROTO_RAFT_VOTE);
> - data = mp_encode_uint(data, r->vote);
> + buf = mp_encode_uint(buf, IPROTO_RAFT_VOTE);
> + buf = mp_encode_uint(buf, r->vote);
> }
> if (r->state != 0) {
> - data = mp_encode_uint(data, IPROTO_RAFT_STATE);
> - data = mp_encode_uint(data, r->state);
> + buf = mp_encode_uint(buf, IPROTO_RAFT_STATE);
> + buf = mp_encode_uint(buf, r->state);
> }
> if (r->vclock != NULL) {
> - data = mp_encode_uint(data, IPROTO_RAFT_VCLOCK);
> - data = mp_encode_vclock_ignore0(data, r->vclock);
> + buf = mp_encode_uint(buf, IPROTO_RAFT_VCLOCK);
> + buf = mp_encode_vclock_ignore0(buf, r->vclock);
> }
> -
> - row->body[0].iov_len = data - buf ;
> -
> + row->body[0].iov_len = buf - begin;
> return 0;
> }
>
--
Serge Petrenko
More information about the Tarantool-patches
mailing list