[Tarantool-patches] [PATCH 08/12] raft: introduce vtab for disk and network

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Nov 20 02:43:05 MSK 2020


Thanks for the review!

>>   @@ -598,8 +553,7 @@ raft_worker_handle_broadcast(struct raft *raft)
>>           assert(raft->vote == raft->self);
>>           req.vclock = raft->vclock;
>>       }
>> -    replicaset_foreach(replica)
>> -        relay_push_raft(replica->relay, &req);
>> +    raft->vtab->broadcast(raft, &req);
> 
> 
> I'd introduce helpers, like raft_write() and raft_broadcast(),
> to hide raft->vtab->... calls. Up to you, though.

Introduced raft_write and raft_broadcast.

====================
diff --git a/src/box/raftlib.c b/src/box/raftlib.c
index cc9139a5b..2f5e90f21 100644
--- a/src/box/raftlib.c
+++ b/src/box/raftlib.c
@@ -62,6 +62,20 @@ raft_state_str(uint32_t state)
 	return "invalid (x)";
 };
 
+/** Shortcut for vtab 'broadcast' method. */
+static inline void
+raft_broadcast(struct raft *raft, const struct raft_request *req)
+{
+	raft->vtab->broadcast(raft, req);
+}
+
+/** Shortcut for vtab 'write' method. */
+static inline void
+raft_write(struct raft *raft, const struct raft_request *req)
+{
+	raft->vtab->write(raft, req);
+}
+
 /**
  * Check if Raft is completely synced with disk. Meaning all its critical values
  * are in WAL. Only in that state the node can become a leader or a candidate.
@@ -523,7 +537,7 @@ end_dump:
 		 * is a leader now, after the node is restarted, there will be
 		 * another leader elected by that time likely.
 		 */
-		raft->vtab->write(raft, &req);
+		raft_write(raft, &req);
 		say_info("RAFT: persisted state %s",
 			 raft_request_to_string(&req));
 
@@ -553,7 +567,7 @@ raft_worker_handle_broadcast(struct raft *raft)
 		assert(raft->vote == raft->self);
 		req.vclock = raft->vclock;
 	}
-	raft->vtab->broadcast(raft, &req);
+	raft_broadcast(raft, &req);
 	trigger_run(&raft->on_update, raft);
 	raft->is_broadcast_scheduled = false;
 }


More information about the Tarantool-patches mailing list