From fb45494105d34471328095a641117d5fe7103fa8 Mon Sep 17 00:00:00 2001 From: cjen1 Date: Tue, 31 Oct 2023 12:57:48 +0000 Subject: [PATCH] fmt --- .github/workflows/workflow.yml | 46 ++++++++++++------------------- bin/cli.ml | 4 ++- bin/dune | 27 ++++++++++-------- bin/test_alloc.ml | 3 +- impl/bench/dune | 10 +++---- impl/lib/conspire_command_tree.ml | 16 ++++++----- impl/lib/conspire_f.ml | 16 +++++++---- impl/lib/conspire_mp.ml | 6 +--- impl/test/test_command_tree.ml | 4 +-- lib/external_infra.ml | 3 +- lib/infra.ml | 5 ++-- ocons_conn_mgr/persistent_conn.ml | 9 ++++-- ocons_conn_mgr/util.ml | 4 ++- 13 files changed, 76 insertions(+), 77 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index d2d5c38..ced0c80 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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 + diff --git a/bin/cli.ml b/bin/cli.ml index 060fd16..229d55e 100644 --- a/bin/cli.ml +++ b/bin/cli.ml @@ -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) diff --git a/bin/dune b/bin/dune index 37358ce..f5e71b1 100644 --- a/bin/dune +++ b/bin/dune @@ -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)) diff --git a/bin/test_alloc.ml b/bin/test_alloc.ml index c8a0775..cbd66af 100644 --- a/bin/test_alloc.ml +++ b/bin/test_alloc.ml @@ -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 diff --git a/impl/bench/dune b/impl/bench/dune index 9c1ee80..36bc523 100644 --- a/impl/bench/dune +++ b/impl/bench/dune @@ -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))) diff --git a/impl/lib/conspire_command_tree.ml b/impl/lib/conspire_command_tree.ml index 35342f0..70e1cfd 100644 --- a/impl/lib/conspire_command_tree.ml +++ b/impl/lib/conspire_command_tree.ml @@ -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 @@ -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 @@ -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 diff --git a/impl/lib/conspire_f.ml b/impl/lib/conspire_f.ml index c55167b..05b07c2 100644 --- a/impl/lib/conspire_f.ml +++ b/impl/lib/conspire_f.ml @@ -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 @@ -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" @@ -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 @@ -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) : @@ -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)) diff --git a/impl/lib/conspire_mp.ml b/impl/lib/conspire_mp.ml index 527f98c..eb37952 100644 --- a/impl/lib/conspire_mp.ml +++ b/impl/lib/conspire_mp.ml @@ -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] diff --git a/impl/test/test_command_tree.ml b/impl/test/test_command_tree.ml index 2fcb9d0..d7ca6ef 100644 --- a/impl/test/test_command_tree.ml +++ b/impl/test/test_command_tree.ml @@ -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, diff --git a/lib/external_infra.ml b/lib/external_infra.ml index 1f85c36..f90dd0f 100644 --- a/lib/external_infra.ml +++ b/lib/external_infra.ml @@ -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 diff --git a/lib/infra.ml b/lib/infra.ml index c0ae46a..8d8e975 100644 --- a/lib/infra.ml +++ b/lib/infra.ml @@ -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 @@ -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 ()) ; diff --git a/ocons_conn_mgr/persistent_conn.ml b/ocons_conn_mgr/persistent_conn.ml index 2b7fa18..5931782 100644 --- a/ocons_conn_mgr/persistent_conn.ml +++ b/ocons_conn_mgr/persistent_conn.ml @@ -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 @@ -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 {| diff --git a/ocons_conn_mgr/util.ml b/ocons_conn_mgr/util.ml index 25bbdaf..9593731 100644 --- a/ocons_conn_mgr/util.ml +++ b/ocons_conn_mgr/util.ml @@ -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