Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Cjen1 committed Oct 31, 2023
1 parent 2761a84 commit fb45494
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 77 deletions.
46 changes: 18 additions & 28 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
name: Build and runtest
name: "CI"

on:
push:
branches:
- main
pull_request:
push:

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
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
4 changes: 1 addition & 3 deletions impl/test/test_command_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ let%expect_test "make_update" =
let ct, _ = CTree.addv ct ~node:0 ~parent:ct.root (Iter.of_list [1; 2]) in
let hd1 = Md5.of_hex_exn "5278a244879fc58054713fb2f920f455" in
let partial_tree = ct in
Fmt.pr "%a@."
(Impl_core__Utils.pp_set CTree.Key.pp)
(Map.key_set ct.ctree) ;
Fmt.pr "%a@." (Impl_core__Utils.pp_set CTree.Key.pp) (Map.key_set ct.ctree) ;
[%expect
{|
[5278a244879fc58054713fb2f920f455, 9b72f276548d04f7e1b6c1f1419a523b,
Expand Down
3 changes: 1 addition & 2 deletions lib/external_infra.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ let accept_handler t sock addr =
traceln "Client handler failed with %a" Fmt.exn_backtrace
(e, Printexc.get_raw_backtrace ())

let run (env) port
cmd_str res_str =
let run env port cmd_str res_str =
TRACE.run_cli_ex := true ;
TRACE.run_in_ex := true ;
Switch.run
Expand Down
5 changes: 2 additions & 3 deletions lib/infra.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Make (C : Consensus_intf.S) = struct
module Internal = Internal_infra.Make (C)
module ExInfra = External_infra

let run (env) config =
let run env config =
Switch.run
@@ fun sw ->
let command_stream = Eio.Stream.create config.stream_length in
Expand Down Expand Up @@ -45,8 +45,7 @@ module Make (C : Consensus_intf.S) = struct
(fun () ->
try
Eio.Domain_manager.run (Eio.Stdenv.domain_mgr env) (fun () ->
ExInfra.run env config.external_port command_stream
result_stream )
ExInfra.run env config.external_port command_stream result_stream )
with e when Utils.is_not_cancel e ->
traceln "External infra failed" ;
traceln "%a" Fmt.exn_backtrace (e, Printexc.get_raw_backtrace ()) ;
Expand Down
9 changes: 7 additions & 2 deletions ocons_conn_mgr/persistent_conn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ let is_open t = not t.should_close
let switch_run ~on_error f =
try Switch.run f with e when is_not_cancel e -> on_error e

let create ?connected ~sw (f : Switch.t -> Eio.Flow.two_way_ty Flow.two_way) delayer =
let create ?connected ~sw (f : Switch.t -> Eio.Flow.two_way_ty Flow.two_way)
delayer =
let t =
{ conn_state= Closed
; should_close= false
Expand Down Expand Up @@ -135,7 +136,11 @@ let%expect_test "PersistantConn" =
; `Return "3\n"
; `Return "4\n"
; `Raise End_of_file ] ;
let c = create ~sw (fun _ -> (!f :> Eio.Flow.two_way_ty Eio.Flow.two_way)) (fun () -> ()) in
let c =
create ~sw
(fun _ -> (!f :> Eio.Flow.two_way_ty Eio.Flow.two_way))
(fun () -> ())
in
let p_line = Buf_read.line in
print_endline (recv c p_line) ;
[%expect {|
Expand Down
4 changes: 3 additions & 1 deletion ocons_conn_mgr/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ let set_debug_flag () = debug_flag := true

let dtraceln fmt =
let ignore_format = Format.ikfprintf ignore Fmt.stderr in
let traceln fmt = Eio.traceln ("%a" ^^ fmt) Time_float_unix.pp (Time_float_unix.now ()) in
let traceln fmt =
Eio.traceln ("%a" ^^ fmt) Time_float_unix.pp (Time_float_unix.now ())
in
if !debug_flag then traceln fmt else ignore_format fmt

let is_not_cancel = function Eio.Cancel.Cancelled _ -> false | _ -> true
Expand Down

0 comments on commit fb45494

Please sign in to comment.