From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v3 04/11] Get rid of IPROTO_SERVER_IS_RO Date: Sat, 14 Jul 2018 23:49:19 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: Not needed anymore as we now use IPROTO_REQUEST_STATUS instead of IPROTO_REQUEST_VOTE. Let's remove it altogether and reuse its code for IPROTO_STATUS (they are never decoded together so no conflict should happen). Worst that can happen is we choose a read-only master when bootstrapping an older version of tarantool. --- src/box/iproto.cc | 9 +++------ src/box/iproto_constants.c | 7 +++---- src/box/iproto_constants.h | 3 +-- src/box/xrow.c | 29 ++++++----------------------- src/box/xrow.h | 28 +++++++++++----------------- 5 files changed, 24 insertions(+), 52 deletions(-) diff --git a/src/box/iproto.cc b/src/box/iproto.cc index 17f161a3..6e4f0f8b 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -61,8 +61,6 @@ #include "iproto_constants.h" #include "rmean.h" #include "errinj.h" -#include "applier.h" -#include "cfg.h" enum { IPROTO_SALT_SIZE = 32, @@ -1539,10 +1537,9 @@ tx_process_misc(struct cmsg *m) ::schema_version); break; case IPROTO_REQUEST_VOTE: - iproto_reply_request_vote_xc(out, msg->header.sync, - ::schema_version, - &replicaset.vclock, - cfg_geti("read_only")); + iproto_reply_vclock_xc(out, &replicaset.vclock, + msg->header.sync, + ::schema_version); break; case IPROTO_REQUEST_STATUS: box_process_status_request(&status); diff --git a/src/box/iproto_constants.c b/src/box/iproto_constants.c index bc7dfd7d..78c83c1d 100644 --- a/src/box/iproto_constants.c +++ b/src/box/iproto_constants.c @@ -86,8 +86,7 @@ const unsigned char iproto_key_type[IPROTO_KEY_MAX] = /* 0x26 */ MP_MAP, /* IPROTO_VCLOCK */ /* 0x27 */ MP_STR, /* IPROTO_EXPR */ /* 0x28 */ MP_ARRAY, /* IPROTO_OPS */ - /* 0x29 */ MP_BOOL, /* IPROTO_SERVER_IS_RO */ - /* 0x2a */ MP_MAP, /* IPROTO_STATUS */ + /* 0x29 */ MP_MAP, /* IPROTO_STATUS */ /* }}} */ }; @@ -168,8 +167,8 @@ const char *iproto_key_strs[IPROTO_KEY_MAX] = { "vector clock", /* 0x26 */ "expression", /* 0x27 */ "operations", /* 0x28 */ - "server is ro", /* 0x29 */ - "status", /* 0x2a */ + "status", /* 0x29 */ + NULL, /* 0x2a */ NULL, /* 0x2b */ NULL, /* 0x2c */ NULL, /* 0x2d */ diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h index ce4366ec..fe452817 100644 --- a/src/box/iproto_constants.h +++ b/src/box/iproto_constants.h @@ -77,8 +77,7 @@ enum iproto_key { IPROTO_VCLOCK = 0x26, IPROTO_EXPR = 0x27, /* EVAL */ IPROTO_OPS = 0x28, /* UPSERT but not UPDATE ops, because of legacy */ - IPROTO_SERVER_IS_RO = 0x29, - IPROTO_STATUS = 0x2a, + IPROTO_STATUS = 0x29, /* Leave a gap between request keys and response keys */ IPROTO_DATA = 0x30, IPROTO_ERROR = 0x31, diff --git a/src/box/xrow.c b/src/box/xrow.c index 4bc1f81e..8a87fd4d 100644 --- a/src/box/xrow.c +++ b/src/box/xrow.c @@ -311,13 +311,11 @@ iproto_reply_ok(struct obuf *out, uint64_t sync, uint32_t schema_version) } int -iproto_reply_request_vote(struct obuf *out, uint64_t sync, - uint32_t schema_version, const struct vclock *vclock, - bool read_only) +iproto_reply_vclock(struct obuf *out, const struct vclock *vclock, + uint64_t sync, uint32_t schema_version) { - size_t max_size = IPROTO_HEADER_LEN + mp_sizeof_map(2) + - mp_sizeof_uint(UINT32_MAX) + mp_sizeof_vclock(vclock) + - mp_sizeof_uint(UINT32_MAX) + mp_sizeof_bool(true); + size_t max_size = IPROTO_HEADER_LEN + mp_sizeof_map(1) + + mp_sizeof_uint(UINT32_MAX) + mp_sizeof_vclock(vclock); char *buf = obuf_reserve(out, max_size); if (buf == NULL) { @@ -327,9 +325,7 @@ iproto_reply_request_vote(struct obuf *out, uint64_t sync, } char *data = buf + IPROTO_HEADER_LEN; - data = mp_encode_map(data, 2); - data = mp_encode_uint(data, IPROTO_SERVER_IS_RO); - data = mp_encode_bool(data, read_only); + data = mp_encode_map(data, 1); data = mp_encode_uint(data, IPROTO_VCLOCK); data = mp_encode_vclock(data, vclock); size_t size = data - buf; @@ -981,7 +977,7 @@ xrow_encode_subscribe(struct xrow_header *row, int xrow_decode_subscribe(struct xrow_header *row, struct tt_uuid *replicaset_uuid, struct tt_uuid *instance_uuid, struct vclock *vclock, - uint32_t *version_id, bool *read_only) + uint32_t *version_id) { if (row->bodycnt == 0) { diag_set(ClientError, ER_INVALID_MSGPACK, "request body"); @@ -996,9 +992,6 @@ xrow_decode_subscribe(struct xrow_header *row, struct tt_uuid *replicaset_uuid, return -1; } - /* For backward compatibility initialize read-only with false. */ - if (read_only) - *read_only = false; d = data; uint32_t map_size = mp_decode_map(&d); for (uint32_t i = 0; i < map_size; i++) { @@ -1040,16 +1033,6 @@ xrow_decode_subscribe(struct xrow_header *row, struct tt_uuid *replicaset_uuid, } *version_id = mp_decode_uint(&d); break; - case IPROTO_SERVER_IS_RO: - if (read_only == NULL) - goto skip; - if (mp_typeof(*d) != MP_BOOL) { - diag_set(ClientError, ER_INVALID_MSGPACK, - "invalid STATUS"); - return -1; - } - *read_only = mp_decode_bool(&d); - break; default: skip: mp_next(&d); /* value */ } diff --git a/src/box/xrow.h b/src/box/xrow.h index 67910d52..1ea30fb1 100644 --- a/src/box/xrow.h +++ b/src/box/xrow.h @@ -269,7 +269,6 @@ xrow_encode_subscribe(struct xrow_header *row, * @param[out] instance_uuid. * @param[out] vclock. * @param[out] version_id. - * @param[out] read_only. * * @retval 0 Success. * @retval -1 Memory or format error. @@ -277,7 +276,7 @@ xrow_encode_subscribe(struct xrow_header *row, int xrow_decode_subscribe(struct xrow_header *row, struct tt_uuid *replicaset_uuid, struct tt_uuid *instance_uuid, struct vclock *vclock, - uint32_t *version_id, bool *read_only); + uint32_t *version_id); /** * Encode JOIN command. @@ -301,8 +300,7 @@ xrow_encode_join(struct xrow_header *row, const struct tt_uuid *instance_uuid); static inline int xrow_decode_join(struct xrow_header *row, struct tt_uuid *instance_uuid) { - return xrow_decode_subscribe(row, NULL, instance_uuid, NULL, NULL, - NULL); + return xrow_decode_subscribe(row, NULL, instance_uuid, NULL, NULL); } /** @@ -327,7 +325,7 @@ xrow_encode_vclock(struct xrow_header *row, const struct vclock *vclock); static inline int xrow_decode_vclock(struct xrow_header *row, struct vclock *vclock) { - return xrow_decode_subscribe(row, NULL, NULL, vclock, NULL, NULL); + return xrow_decode_subscribe(row, NULL, NULL, vclock, NULL); } /** @@ -391,18 +389,16 @@ iproto_reply_ok(struct obuf *out, uint64_t sync, uint32_t schema_version); * Encode iproto header with IPROTO_OK response code * and vclock in the body. * @param out Encode to. + * @param vclock Vclock to encode. * @param sync Request sync. * @param schema_version. - * @param vclock. - * @param read_only. * * @retval 0 Success. * @retval -1 Memory error. */ int -iproto_reply_request_vote(struct obuf *out, uint64_t sync, - uint32_t schema_version, const struct vclock *vclock, - bool read_only); +iproto_reply_vclock(struct obuf *out, const struct vclock *vclock, + uint64_t sync, uint32_t schema_version); /** * Encode a reply to an instance status request. @@ -627,7 +623,7 @@ xrow_decode_subscribe_xc(struct xrow_header *row, uint32_t *replica_version_id) { if (xrow_decode_subscribe(row, replicaset_uuid, instance_uuid, - vclock, replica_version_id, NULL) != 0) + vclock, replica_version_id) != 0) diag_raise(); } @@ -672,14 +668,12 @@ iproto_reply_ok_xc(struct obuf *out, uint64_t sync, uint32_t schema_version) diag_raise(); } -/** @copydoc iproto_reply_request_vote_xc. */ +/** @copydoc iproto_reply_vclock. */ static inline void -iproto_reply_request_vote_xc(struct obuf *out, uint64_t sync, - uint32_t schema_version, - const struct vclock *vclock, bool read_only) +iproto_reply_vclock_xc(struct obuf *out, const struct vclock *vclock, + uint64_t sync, uint32_t schema_version) { - if (iproto_reply_request_vote(out, sync, schema_version, - vclock, read_only) != 0) + if (iproto_reply_vclock(out, vclock, sync, schema_version) != 0) diag_raise(); } -- 2.11.0