[Tarantool-patches] [PATCH v12 5/8] replication: merge replica_by_id into replicaset

Cyrill Gorcunov gorcunov at gmail.com
Tue Apr 7 18:14:58 MSK 2020


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 at gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at 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 1345f189b..7c10fb6f2 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 2ef1255b3..9df91e611 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;
 
-- 
2.20.1



More information about the Tarantool-patches mailing list