[tarantool-patches] [PATCH v4 04/20] refactoring: remove exceptions from replica_check_id

Ilya Kosarev i.kosarev at tarantool.org
Mon Sep 23 18:56:55 MSK 2019


replica_check_id is used in on_replace_dd_cluster trigger
therefore it has to be cleared from exceptions. Now it doesn't
throw any more. It's usages are updated.

Part of #4247
---
 src/box/alter.cc       |  6 ++++--
 src/box/replication.cc | 21 ++++++++++++++-------
 src/box/replication.h  |  2 +-
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 1fce160f5..d4cb9e8d8 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -3627,7 +3627,8 @@ on_replace_dd_cluster(struct trigger *trigger, void *event)
 		/* Check fields */
 		uint32_t replica_id =
 			tuple_field_u32_xc(new_tuple, BOX_CLUSTER_FIELD_ID);
-		replica_check_id(replica_id);
+		if (replica_check_id(replica_id) != 0)
+			return -1;
 		tt_uuid replica_uuid;
 		tuple_field_uuid_xc(new_tuple, BOX_CLUSTER_FIELD_UUID,
 				    &replica_uuid);
@@ -3665,7 +3666,8 @@ on_replace_dd_cluster(struct trigger *trigger, void *event)
 		assert(old_tuple != NULL);
 		uint32_t replica_id =
 			tuple_field_u32_xc(old_tuple, BOX_CLUSTER_FIELD_ID);
-		replica_check_id(replica_id);
+		if (replica_check_id(replica_id) != 0)
+			return -1;
 
 		struct trigger *on_commit;
 		on_commit = txn_alter_trigger_new(unregister_replica,
diff --git a/src/box/replication.cc b/src/box/replication.cc
index 82bf496c8..786941f5c 100644
--- a/src/box/replication.cc
+++ b/src/box/replication.cc
@@ -114,15 +114,19 @@ replication_free(void)
 	free(replicaset.replica_by_id);
 }
 
-void
+int
 replica_check_id(uint32_t replica_id)
 {
-        if (replica_id == REPLICA_ID_NIL)
-		tnt_raise(ClientError, ER_REPLICA_ID_IS_RESERVED,
+	if (replica_id == REPLICA_ID_NIL) {
+		diag_set(ClientError, ER_REPLICA_ID_IS_RESERVED,
 			  (unsigned) replica_id);
-	if (replica_id >= VCLOCK_MAX)
-		tnt_raise(LoggedError, ER_REPLICA_MAX,
+		return -1;
+	}
+	if (replica_id >= VCLOCK_MAX) {
+		diag_set(ClientError, ER_REPLICA_MAX,
 			  (unsigned) replica_id);
+		return -1;
+	}
 	/*
 	 * It's okay to update the instance id while it is joining to
 	 * a cluster as long as the id is set by the time bootstrap is
@@ -133,9 +137,12 @@ replica_check_id(uint32_t replica_id)
 	 * case it will replay this operation during the final join
 	 * stage.
 	 */
-        if (!replicaset.is_joining && replica_id == instance_id)
-		tnt_raise(ClientError, ER_LOCAL_INSTANCE_ID_IS_READ_ONLY,
+	if (!replicaset.is_joining && replica_id == instance_id) {
+		diag_set(ClientError, ER_LOCAL_INSTANCE_ID_IS_READ_ONLY,
 			  (unsigned) replica_id);
+		return -1;
+	}
+	return 0;
 }
 
 /* Return true if replica doesn't have id, relay and applier */
diff --git a/src/box/replication.h b/src/box/replication.h
index 19f283c7d..470420592 100644
--- a/src/box/replication.h
+++ b/src/box/replication.h
@@ -352,7 +352,7 @@ replica_on_relay_stop(struct replica *replica);
 #if defined(__cplusplus)
 } /* extern "C" */
 
-void
+int
 replica_check_id(uint32_t replica_id);
 
 /**
-- 
2.17.1





More information about the Tarantool-patches mailing list