|
| 1 | +module Term : sig |
| 2 | + type t |
| 3 | + |
| 4 | + val zero : t |
| 5 | + val succ : t -> t |
| 6 | + val compare : t -> t -> int |
| 7 | + val of_string : string -> t |
| 8 | + val to_string : t -> string |
| 9 | +end |
| 10 | + |
1 | 11 | module type LOG = sig
|
2 | 12 | type elt
|
3 | 13 | type t
|
4 | 14 |
|
5 |
| - val append : elt -> t -> t option |
| 15 | + val append : elt -> t -> t option |
| 16 | + val last_term : t -> Term.t |
6 | 17 | end
|
7 | 18 |
|
8 | 19 | module type SERVER = sig
|
|
13 | 24 |
|
14 | 25 | module Make : functor (Server : SERVER) -> functor (Log : LOG) -> sig
|
15 | 26 | type 'a t
|
| 27 | + type error = [ `Bad_term | `Bad_previous ] |
16 | 28 |
|
17 |
| - val create : Server.t list -> [ `Follower ] t |
| 29 | + val create : me:Server.t -> log:Log.t -> Server.t list -> [ `Follower ] t |
18 | 30 |
|
19 | 31 | val servers : 'a t -> Server.t list
|
20 |
| - val set_servers : Server.t list -> 'a t -> 'a t |
21 | 32 |
|
22 |
| - val current_term : 'a t -> int |
| 33 | + val current_term : 'a t -> Term.t |
23 | 34 | val voted_for : 'a t -> Server.t option
|
24 | 35 |
|
25 | 36 | val log : 'a t -> Log.t
|
| 37 | + val set_log : Log.t -> 'a t -> 'a t |
26 | 38 |
|
27 | 39 | val leader : 'a t -> Server.t option
|
28 | 40 |
|
29 |
| - val next_index : [ `Leader ] t -> (Server.t * int) list |
30 |
| - val match_index : [ `Leader ] t -> (Server.t * int) list |
31 |
| - |
| 41 | + (* |
| 42 | + * Triggered when we are a follower and have not heard from the leader |
| 43 | + * in some timeout period |
| 44 | + *) |
32 | 45 | val heartbeat_timeout : [ `Follower] t -> [ `Candidate ] t
|
33 | 46 |
|
| 47 | + (* |
| 48 | + * This set of functions are used during a voting round |
| 49 | + * |
| 50 | + * request_vote - A server is requesting a vote from us. Returns [t option] |
| 51 | + * if it is granted and None if it is not |
| 52 | + * |
| 53 | + * receive_vote - A vote has been requested and received from the server |
| 54 | + * |
| 55 | + * is_now_leader - Tests if the current state machine can become a leader. |
| 56 | + * If so, return it. |
| 57 | + *) |
34 | 58 | val election_timeout : [ `Candidate ] t -> [ `Candidate ] t
|
35 |
| - val receive_vote : [ `Candidate ] t -> [ `Candidate ] t |
| 59 | + val request_vote : Server.t -> [ `Follower ] t -> [ `Follower ] t option |
| 60 | + val receive_vote : Server.t -> [ `Candidate ] t -> [ `Candidate ] t |
36 | 61 | val is_now_leader : [ `Candidate ] t -> [ `Leader ] t option
|
37 | 62 |
|
38 |
| - val receive_log : Log.t -> 'a t -> [ `Follower ] t |
| 63 | + val receive_log : Log.t -> [ `Candidate | `Follower ] t -> ([ `Follower ] t, [> error ]) Core.Result.t |
39 | 64 | val append_log : Log.t -> [ `Leader ] t -> [ `Leader ] t
|
40 | 65 |
|
41 | 66 | end
|
0 commit comments