From 0ade0880e6f7ff46b9e3c35d718e32698a8b4ae6 Mon Sep 17 00:00:00 2001
From: Vladimir Davydov <vdavydov.dev@gmail.com>
Date: Fri, 13 Jul 2018 20:32:33 +0300
Subject: [PATCH] Get rid of IPROTO_SERVER_IS_RO

Not needed anymore as we now use the new IPROTO_VOTE command instead of
IPROTO_VOTE_DEPRECATED. Let's remove it altogether and reuse its code
for IPROTO_BALLOT (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             | 30 ++++++------------------------
 src/box/xrow.h             | 30 ++++++++++++------------------
 5 files changed, 25 insertions(+), 54 deletions(-)

diff --git a/src/box/iproto.cc b/src/box/iproto.cc
index 4eb6c98263..bb7d2b868b 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_VOTE_DEPRECATED:
-			iproto_reply_vote_deprecated_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_VOTE:
 			box_process_vote(&ballot);
diff --git a/src/box/iproto_constants.c b/src/box/iproto_constants.c
index 3e25204e9a..e35738b4bc 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_BALLOT */
+	/* 0x29 */	MP_MAP, /* IPROTO_BALLOT */
 	/* }}} */
 };
 
@@ -168,8 +167,8 @@ const char *iproto_key_strs[IPROTO_KEY_MAX] = {
 	"vector clock",     /* 0x26 */
 	"expression",       /* 0x27 */
 	"operations",       /* 0x28 */
-	"server is ro",     /* 0x29 */
-	"ballot",           /* 0x2a */
+	"ballot",           /* 0x29 */
+	NULL,               /* 0x2a */
 	NULL,               /* 0x2b */
 	NULL,               /* 0x2c */
 	NULL,               /* 0x2d */
diff --git a/src/box/iproto_constants.h b/src/box/iproto_constants.h
index 108ae00ef9..d3d20f02b6 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_BALLOT = 0x2a,
+	IPROTO_BALLOT = 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 bd85d6bd4a..2a73372d1b 100644
--- a/src/box/xrow.c
+++ b/src/box/xrow.c
@@ -311,14 +311,11 @@ iproto_reply_ok(struct obuf *out, uint64_t sync, uint32_t schema_version)
 }
 
 int
-iproto_reply_vote_deprecated(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) {
@@ -328,9 +325,7 @@ iproto_reply_vote_deprecated(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;
@@ -982,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");
@@ -997,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++) {
@@ -1041,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 01a9544ea2..be2774bb19 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);
 }
 
 /**
@@ -389,20 +387,18 @@ 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. This function is DEPRECATED.
+ * 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_vote_deprecated(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 IPROTO_VOTE 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_vote_deprecated. */
+/** @copydoc iproto_reply_vclock. */
 static inline void
-iproto_reply_vote_deprecated_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_vote_deprecated(out, sync, schema_version,
-					 vclock, read_only) != 0)
+	if (iproto_reply_vclock(out, vclock, sync, schema_version) != 0)
 		diag_raise();
 }
 
-- 
GitLab