From 5ebbed7711d442e9b5ea21703c4aa5ba613a1a5d Mon Sep 17 00:00:00 2001
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Date: Tue, 28 May 2024 23:01:38 +0200
Subject: [PATCH] relay: rename vclock args and make const

It wasn't clear which of them are inputs and which are outputs.
The patch explicitly marks the input vclocks as const. It makes
the code a bit easier to read inside of relay.cc knowing that
these vclocks shouldn't change.

Alongside "replica_clock" in subscribe is renamed to
"start_vclock". To make it consistent with relay_final_join(), and
to signify that technically it doesn't have to be a replica
vclock. It isn't really. Box.cc alters the replica's vclock before
giving it to relay, which means it is no longer "replica clock".

In scope of #10047

NO_TEST=refactoring
NO_CHANGELOG=refactoring
NO_DOC=refactoring
---
 src/box/relay.cc | 11 ++++++-----
 src/box/relay.h  |  5 +++--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/box/relay.cc b/src/box/relay.cc
index 7035821d76..4c550c6b3c 100644
--- a/src/box/relay.cc
+++ b/src/box/relay.cc
@@ -532,7 +532,8 @@ relay_final_join_f(va_list ap)
 
 void
 relay_final_join(struct replica *replica, struct iostream *io, uint64_t sync,
-		 struct vclock *start_vclock, struct vclock *stop_vclock)
+		 const struct vclock *start_vclock,
+		 const struct vclock *stop_vclock)
 {
 	/*
 	 * As a new thread is started for the final join stage, its cancellation
@@ -1092,7 +1093,7 @@ relay_subscribe_f(va_list ap)
 /** Replication acceptor fiber handler. */
 void
 relay_subscribe(struct replica *replica, struct iostream *io, uint64_t sync,
-		struct vclock *replica_clock, uint32_t replica_version_id,
+		const struct vclock *start_vclock, uint32_t replica_version_id,
 		uint32_t replica_id_filter, uint64_t sent_raft_term)
 {
 	assert(replica->anon || replica->id != REPLICA_ID_NIL);
@@ -1112,9 +1113,9 @@ relay_subscribe(struct replica *replica, struct iostream *io, uint64_t sync,
 	/*
 	 * Save the first vclock as 'received'. Because it was really received.
 	 */
-	vclock_copy(&relay->last_recv_ack.vclock, replica_clock);
-	relay->r = recovery_new(wal_dir(), false, replica_clock);
-	vclock_copy(&relay->tx.vclock, replica_clock);
+	vclock_copy(&relay->last_recv_ack.vclock, start_vclock);
+	relay->r = recovery_new(wal_dir(), false, start_vclock);
+	vclock_copy(&relay->tx.vclock, start_vclock);
 	relay->version_id = replica_version_id;
 
 	relay->id_filter |= replica_id_filter;
diff --git a/src/box/relay.h b/src/box/relay.h
index f33b076d81..87b7d7c591 100644
--- a/src/box/relay.h
+++ b/src/box/relay.h
@@ -135,7 +135,8 @@ relay_initial_join(struct iostream *io, uint64_t sync, struct vclock *vclock,
  */
 void
 relay_final_join(struct replica *replica, struct iostream *io, uint64_t sync,
-		 struct vclock *start_vclock, struct vclock *stop_vclock);
+		 const struct vclock *start_vclock,
+		 const struct vclock *stop_vclock);
 
 /**
  * Subscribe a replica to updates.
@@ -144,7 +145,7 @@ relay_final_join(struct replica *replica, struct iostream *io, uint64_t sync,
  */
 void
 relay_subscribe(struct replica *replica, struct iostream *io, uint64_t sync,
-		struct vclock *replica_vclock, uint32_t replica_version_id,
+		const struct vclock *start_vclock, uint32_t replica_version_id,
 		uint32_t replica_id_filter, uint64_t sent_raft_term);
 
 #endif /* TARANTOOL_REPLICATION_RELAY_H_INCLUDED */
-- 
GitLab