Skip to content
Snippets Groups Projects
Commit 43d42969 authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy
Browse files

raft: introduce on_update trigger

Raft state machine now has a trigger invoked each time when any of
the visible Raft attributes is changed: state, term, vote.

The trigger is needed to commit synchronous transactions of an old
leader, when a new leader is elected. This is done via a trigger
so as not to depend on box in raft code too much. That would make
it harder to extract it into a new module later.

The trigger is executed in the Raft worker fiber, so as not to
stop the state machine transitions anywhere, which currently don't
contain a single yield. And the synchronous transaction queue
clearance requires a yield, to write CONFIRM and ROLLBACK records
to WAL.

Part of #5339
parent 6b43f103
No related branches found
No related tags found
No related merge requests found
......@@ -643,6 +643,7 @@ raft_worker_handle_broadcast(void)
}
replicaset_foreach(replica)
relay_push_raft(replica->relay, &req);
trigger_run(&raft.on_update, NULL);
raft.is_broadcast_scheduled = false;
}
......@@ -903,6 +904,12 @@ raft_serialize_for_disk(struct raft_request *req)
req->vote = raft.vote;
}
void
raft_on_update(struct trigger *trigger)
{
trigger_add(&raft.on_update, trigger);
}
void
raft_cfg_is_enabled(bool is_enabled)
{
......@@ -1040,4 +1047,5 @@ void
raft_init(void)
{
ev_timer_init(&raft.timer, raft_sm_schedule_new_election_cb, 0, 0);
rlist_create(&raft.on_update);
}
......@@ -32,6 +32,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "tarantool_ev.h"
#include "trigger.h"
#if defined(__cplusplus)
extern "C" {
......@@ -150,6 +151,11 @@ struct raft {
struct fiber *worker;
/** Configured election timeout in seconds. */
double election_timeout;
/**
* Trigger invoked each time any of the Raft node visible attributes are
* changed.
*/
struct rlist on_update;
};
extern struct raft raft;
......@@ -251,6 +257,13 @@ raft_serialize_for_network(struct raft_request *req, struct vclock *vclock);
void
raft_serialize_for_disk(struct raft_request *req);
/**
* Add a trigger invoked each time any of the Raft node visible attributes are
* changed.
*/
void
raft_on_update(struct trigger *trigger);
/** Initialize Raft global data structures. */
void
raft_init(void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment