From 7d904b2a7cee505bd92af9ef47b39ef177639483 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov@gmail.com>
Date: Wed, 25 Mar 2020 17:31:10 +0300
Subject: [PATCH] replication: merge replica_by_id into replicaset

For some reason the replica_by_id member (which is an
array of pointers) is allocated dynamically. Moreover
VCLOCK_MAX = 32 by now and extending it to some new
limit will require a way more efforts than just increase
the number.

Thus reserve memory for replica_by_id inside replicaset
statically. This allows to simplify code a bit and
drop calloc/free calls.

The former code comes from edd76a2a0ae17e3d without any
explanation why the dynamic member is needed.

Acked-by: Konstantin Osipov <kostja.osipov@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 src/box/replication.cc | 2 --
 src/box/replication.h  | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/box/replication.cc b/src/box/replication.cc
index 1345f189bd..7c10fb6f20 100644
--- a/src/box/replication.cc
+++ b/src/box/replication.cc
@@ -89,7 +89,6 @@ replication_init(void)
 	rlist_create(&replicaset.anon);
 	vclock_create(&replicaset.vclock);
 	fiber_cond_create(&replicaset.applier.cond);
-	replicaset.replica_by_id = (struct replica **)calloc(VCLOCK_MAX, sizeof(struct replica *));
 	latch_create(&replicaset.applier.order_latch);
 
 	vclock_create(&replicaset.applier.vclock);
@@ -112,7 +111,6 @@ replication_free(void)
 		relay_cancel(replica->relay);
 
 	diag_destroy(&replicaset.applier.diag);
-	free(replicaset.replica_by_id);
 }
 
 int
diff --git a/src/box/replication.h b/src/box/replication.h
index 2ef1255b3c..9df91e6118 100644
--- a/src/box/replication.h
+++ b/src/box/replication.h
@@ -251,7 +251,7 @@ struct replicaset {
 		struct diag diag;
 	} applier;
 	/** Map of all known replica_id's to correspponding replica's. */
-	struct replica **replica_by_id;
+	struct replica *replica_by_id[VCLOCK_MAX];
 };
 extern struct replicaset replicaset;
 
-- 
GitLab