Skip to content

Commit

Permalink
Merge pull request #25 from Cjen1/improve_restart_perf
Browse files Browse the repository at this point in the history
Improve the failure recovery properties
  • Loading branch information
Cjen1 authored Dec 30, 2023
2 parents 1110ef5 + d0b5393 commit df22912
Show file tree
Hide file tree
Showing 28 changed files with 853 additions and 771 deletions.
47 changes: 19 additions & 28 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
name: Build and runtest
name: "CI"

on:
push:
branches:
- main
pull_request:
push:
branches: [main]

jobs:
build:
name: Check build
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix develop -c dune build
format:
name: Check formatting
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix develop -c dune build @fmt
runtest:
name: Run tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix develop -c dune runtest
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v1
- name: Run tests
run: |
nix develop -c dune runtest
- name: Format
run: |
nix develop -c dune build @fmt
4 changes: 3 additions & 1 deletion bin/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ let run op sockaddrs id retry_timeout =
sockaddrs
|> List.mapi (fun idx addr ->
( idx
, fun sw -> (Eio.Net.connect ~sw env#net addr :> Eio.Flow.two_way_ty Eio.Flow.two_way) ) )
, fun sw ->
( Eio.Net.connect ~sw env#net addr
:> Eio.Flow.two_way_ty Eio.Flow.two_way ) ) )
in
Eio.traceln "Creating conns to: %a"
Fmt.(braces @@ list ~sep:comma Eio.Net.Sockaddr.pp)
Expand Down
27 changes: 15 additions & 12 deletions bin/dune
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
(executable
(name cli)
(modules cli)
(libraries ocons.core cmdliner))
(name cli)
(modules cli)
(libraries ocons.core cmdliner))

(executable
(name bench)
(modules bench)
(libraries ocons.core cmdliner))
(name bench)
(modules bench)
(libraries ocons.core cmdliner))

(executable
(name echo)
(modules echo)
(libraries ocons.core cmdliner))
(name echo)
(modules echo)
(libraries ocons.core cmdliner))

(executable
(name test_alloc)
(modules test_alloc)
(libraries core core_bench core_unix.command_unix))
(name test_alloc)
(modules test_alloc)
(libraries core core_bench core_unix.command_unix))
3 changes: 1 addition & 2 deletions bin/test_alloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ let alloc_test =
let test `init =
let large = make_data 1000 in
let extern = ref None in
fun () ->
extern := Some large
fun () -> extern := Some large
in
Bench.Test.create_with_initialization ~name:"alloc_with_reference" test

Expand Down
10 changes: 5 additions & 5 deletions impl/bench/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name ctree_bench)
(modules ctree_bench)
(libraries impl_core core_bench.inline_benchmarks)
(preprocess (pps ppx_jane ppx_deriving.show))
)
(name ctree_bench)
(modules ctree_bench)
(libraries impl_core core_bench.inline_benchmarks)
(preprocess
(pps ppx_jane ppx_deriving.show)))
16 changes: 9 additions & 7 deletions impl/lib/conspire_command_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ module type Value = sig
end

module CommandTree (Value : Value) = struct
module Key = struct
module Key = struct
include Md5
let pp ppf v =
Fmt.pf ppf "%s" (Md5.to_hex v)

let pp ppf v = Fmt.pf ppf "%s" (Md5.to_hex v)
end

type key = Key.t [@@deriving show, bin_io, equal, compare]

let make_key =
let open struct
let open struct
type relevant_key_data = key * Value.t [@@deriving bin_io]
end in
fun parent_key value ->
Md5.digest_bin_prot bin_writer_relevant_key_data (parent_key, value)
Md5.digest_bin_prot bin_writer_relevant_key_data (parent_key, value)

(* Map of vector clocks to values
Aim to replicate this to other nodes
Expand All @@ -44,7 +45,8 @@ module CommandTree (Value : Value) = struct

let root_key = Md5.digest_string ""

let get_key_of_node node = match node with None -> root_key | Some {key; _} -> key
let get_key_of_node node =
match node with None -> root_key | Some {key; _} -> key

let get_idx_of_node node =
match node with None -> 0 | Some {node= idx, _, _; _} -> idx
Expand Down Expand Up @@ -224,7 +226,7 @@ module CommandTree (Value : Value) = struct
Some GT
| Some ({node= ia, _, _; _} as na), Some ({node= ib, _, _; _} as nb) -> (
let rec on_path t curr ({key= kt; node= it, _, _; _} as target) =
assert (get_idx_of_node curr >= it);
assert (get_idx_of_node curr >= it) ;
match curr with
| None ->
false
Expand Down
12 changes: 6 additions & 6 deletions impl/lib/conspire_dc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ open! Core
open Types
module Time = Time_float_unix

let pp_time_float_unix : Time.t Fmt.t =
fun ppf v -> Fmt.pf ppf "%0.5f" (Utils.time_to_float v)

module Value = struct
let pp_command = Command.pp

type t = command list * Time.t
type t = command list * (Time.t[@printer pp_time_float_unix])
[@@deriving compare, equal, hash, bin_io, sexp, show]

let empty = ([], Time.epoch)
Expand All @@ -26,13 +29,10 @@ end
*)

module DelayReorderBuffer = struct
let pp_time_float_unix : Time.t Fmt.t =
fun ppf v -> Fmt.pf ppf "%0.5f" (Utils.time_to_float v)

type 'a t =
{ mutable store: 'a list Map.M(Time).t
[@polyprinter fun pa -> Utils.pp_map pp_time_float_unix pa]
; mutable hwm: Time.t
; mutable hwm: Time.t [@printer pp_time_float_unix]
; interval: Time.Span.t
; compare: 'a -> 'a -> int }
[@@deriving show {with_path= false}]
Expand Down Expand Up @@ -121,7 +121,7 @@ module Types = struct
; clock= (clock :> float Eio.Time.clock_ty Eio.Time.clock) }

type message =
| Commands of (Command.t list * Time.t)
| Commands of (Command.t list * (Time.t[@printer pp_time_float_unix]))
| Conspire of Conspire.message
[@@deriving show, bin_io]

Expand Down
16 changes: 10 additions & 6 deletions impl/lib/conspire_f.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ module Make (Value : Value) = struct

type t =
{ rep: Rep.rep
; other_nodes_state: state Map.M(Int).t [@printer Utils.pp_map Fmt.int pp_state]
; other_nodes_state: state Map.M(Int).t
[@printer Utils.pp_map Fmt.int pp_state]
; config: config [@opaque]
; commit_log: Value.t Log.t }
[@@deriving show {with_path= false}]

let reporter_conflict, run_c =
Ocons_core.Utils.InternalReporter.rate_reporter "conflict"

let acceptor_reply t src =
let local = t.rep.state in
let remote = Map.find_exn t.other_nodes_state src in
Expand All @@ -148,6 +152,7 @@ module Make (Value : Value) = struct
let res = CTree.compare_keys t.rep.store local.vval remote.vval in
match res with
| None ->
reporter_conflict () ;
(* conflict *)
Utils.dtraceln "CONFLICT from %d" src ;
Utils.dtraceln "local %a does not prefix of remote %a"
Expand Down Expand Up @@ -240,8 +245,7 @@ module Make (Value : Value) = struct
check_commit t

let acceptor_term_tick t term' =
if t.rep.state.term < term' then
t.rep.state.term <- term'
if t.rep.state.term < term' then t.rep.state.term <- term'

let handle_steady_state t src (msg : Rep.success) =
let option_bind o ~f = Option.value_map o ~default:(Ok ()) ~f in
Expand All @@ -261,9 +265,8 @@ module Make (Value : Value) = struct
set_state remote new_state ;
acceptor_reply t src ;
check_commit t ;
check_conflict_recovery t;
acceptor_term_tick t new_state.term;
) ;
check_conflict_recovery t ;
acceptor_term_tick t new_state.term ) ;
Result.return ()

let handle_message t src (msg : Rep.message) :
Expand All @@ -280,6 +283,7 @@ module Make (Value : Value) = struct
Error `MustAck

let create (config : config) =
run_c := true ;
let rep = Rep.create config.other_replica_ids in
let other_nodes_state =
List.map config.other_replica_ids ~f:(fun i -> (i, init_state rep.store))
Expand Down
6 changes: 1 addition & 5 deletions impl/lib/conspire_mp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ module Types = struct
Conspire_f.
{node_id; replica_ids; other_replica_ids; replica_count; quorum_size}
in
{ conspire
; other_replica_ids
; lower_replica_ids
; fd_timeout
; max_outstanding }
{conspire; other_replica_ids; lower_replica_ids; fd_timeout; max_outstanding}

type message = Conspire.message [@@deriving show, bin_io]

Expand Down
Loading

0 comments on commit df22912

Please sign in to comment.