Skip to content

Commit

Permalink
Add time to commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Cjen1 committed Jan 10, 2024
1 parent 1f92ed4 commit a1dba25
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 308 deletions.
5 changes: 4 additions & 1 deletion bin/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ let pitcher ~sw nid mclock n rate cmgr (dispatch : (int, Mtime.t) Hashtbl.t) :
let id = i * prime in
let cmd =
Command.
{op= Write ("asdf", "asdf"); id; trace_start= Unix.gettimeofday ()}
{ op= Write ("asdf", "asdf")
; id
; submitted= Unix.gettimeofday ()
; trace_start= Unix.gettimeofday () }
in
let target = Mtime.add_span prev period |> Option.get in
if Mtime.is_later target ~than:(MT.now mclock) then
Expand Down
3 changes: 2 additions & 1 deletion fuzz/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(test
(name lib_line_prot)
(libraries ocons.core crowbar mtime))
(libraries ocons.core crowbar mtime)
(preprocess (pps ppx_jane)))
12 changes: 9 additions & 3 deletions fuzz/lib_line_prot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module Gen = struct
; const NoOp ]

let command =
map [op; int; float] (fun op id trace_start ->
Ocons_core.Types.Command.{op; id; trace_start} )
map [op; int; float; float] (fun op id submitted trace_start ->
Ocons_core.Types.Command.{op; id; submitted; trace_start} )

let log_entry = map [command; int] (fun command term -> {command; term})

Expand All @@ -39,7 +39,13 @@ let test_client_request r =
@@ fun bw ->
Line_prot.External_infra.serialise_request r bw ;
let r' = Line_prot.External_infra.parse_request br in
check_eq ~cmp:Command.compare ~pp:Command.pp_mach r r'
(* compare *)
check_eq ~cmp:Command.compare ~pp:Command.pp_mach r r';
(* hash *)
check_eq ~pp:Command.pp_mach r r' ~cmp:(fun a b ->
let ha, hb = Command.hash a, Command.hash b in
Int.compare ha hb
)

let test_client_response r =
let open Crowbar in
Expand Down
23 changes: 17 additions & 6 deletions impl/fuzz/test_msgs.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module C = Crowbar

let entries_equal (ea, la) (eb, lb) =
la = lb && List.equal ( = ) (Iter.to_list ea) (Iter.to_list eb)
la = lb
&& List.equal [%compare.equal: Ocons_core.Types.log_entry] (Iter.to_list ea)
(Iter.to_list eb)

module Gen = struct
open Ocons_core.Types
Expand All @@ -17,13 +19,22 @@ module Gen = struct
; const NoOp ]

let command =
map [op; int] (fun op id ->
Ocons_core.Types.Command.{op; id; trace_start= -1.} )
with_printer Command.pp
@@ map [op; int; float; float] (fun op id submitted trace_start ->
Ocons_core.Types.Command.{op; id; trace_start; submitted} )

let log_entry = map [command; int] (fun command term -> {command; term})
let log_entry =
with_printer log_entry_pp
@@ map [command; int] (fun command term -> {command; term})

let pp_entries ppf (v, _) =
Fmt.pf ppf "%a"
Fmt.(brackets @@ list ~sep:comma log_entry_pp_mach)
(Iter.to_list v)

let entries =
map [list log_entry] (fun les -> (Iter.of_list les, List.length les))
with_printer pp_entries
@@ map [list log_entry] (fun les -> (Iter.of_list les, List.length les))

let conspire_value : Impl_core.ConspireSS.value gen = list command
end
Expand All @@ -43,7 +54,7 @@ let test_entry_equality les =
@@ fun bw ->
LP.SerPrim.entries w_entries bw ;
let r_entries = LP.DeserPrim.entries br in
check_eq ~eq:entries_equal w_entries r_entries
check_eq ~pp:Gen.pp_entries ~eq:entries_equal w_entries r_entries

module Paxos = struct
open Impl_core.Paxos
Expand Down
250 changes: 125 additions & 125 deletions impl/test/test_conspire_dc.ml

Large diffs are not rendered by default.

336 changes: 173 additions & 163 deletions impl/test/test_conspire_leader.ml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ let send_request ?(random_id = false) t op =
if random_id then Random.int32 Int32.max_int |> Int32.to_int
else t.next_id ()
in
let command = Command.{op; id; trace_start= Unix.gettimeofday ()} in
let command = Command.{op; id; submitted= Unix.gettimeofday (); trace_start= Unix.gettimeofday ()} in
let send () = submit_request t.cmgr command in
let res_t, res_u = Promise.create () in
let request_state =
Expand Down
5 changes: 3 additions & 2 deletions lib/internal_infra.ml
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,12 @@ module Test = struct
Command.
{ op= Write (k, n)
; id= Core.Random.int Core.Int.max_value
; trace_start= -1. }
; trace_start= -1.
; submitted= -1.}

let r n =
Command.
{op= Read n; id= Core.Random.int Core.Int.max_value; trace_start= -1.}
{op= Read n; id= Core.Random.int Core.Int.max_value; trace_start= -1.; submitted = -1.}

module CT : Consensus_intf.S = struct
type message = Core.String.t [@@deriving sexp]
Expand Down
6 changes: 4 additions & 2 deletions lib/line_prot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ module SerPrim = struct
| NoOp ->
()

let command Command.{op; id; trace_start} w =
let command Command.{op; id; submitted; trace_start} w =
W.BE.uint64 w (Int64.of_int id) ;
W.BE.double w submitted ;
W.BE.double w trace_start ;
sm_op op w

Expand Down Expand Up @@ -85,9 +86,10 @@ module DeserPrim = struct

let command =
let* id = R.map Int64.to_int R.BE.uint64
and* submitted = R.BE.double
and* trace_start = R.BE.double
and* op = sm_op in
R.return Command.{op; id; trace_start}
R.return Command.{op; id; submitted; trace_start}

let log_entry =
let* term = R.map Int64.to_int R.BE.uint64 and* command = command in
Expand Down
10 changes: 6 additions & 4 deletions lib/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ let sm_op_pp ppf v =

module Command = struct
module T = struct
type t = {op: sm_op; id: command_id; mutable trace_start: float}
type t =
{op: sm_op; id: command_id; submitted: float; mutable trace_start: float}
[@@deriving sexp, bin_io]

let hash t = hash_command_id t.id

let hash_fold_t s t = hash_fold_command_id s t.id

let pp_mach ppf v =
Fmt.pf ppf "Command(%a, %d, %.4f)" sm_op_pp v.op v.id v.trace_start
Fmt.pf ppf "Command(%a, %d, %.4f, %.4f)" sm_op_pp v.op v.id v.submitted v.trace_start

let pp ppf v = Fmt.pf ppf "Command(%a, %d)" sm_op_pp v.op v.id

Expand All @@ -67,15 +68,16 @@ let update_command_time c = c.Command.trace_start <- Core_unix.gettimeofday ()

let get_command_trace_time c = c.Command.trace_start

let empty_command = Command.{op= NoOp; id= -1; trace_start= -1.}
let empty_command = Command.{op= NoOp; id= -1; submitted= -1.; trace_start= -1.}

let make_command_state = ref 0

let reset_make_command_state () = make_command_state := 0

(* Used for tests *)
let make_command c =
make_command_state := !make_command_state + 1 ;
Command.{op= c; id= !make_command_state; trace_start= -1.}
Command.{op= c; id= !make_command_state; trace_start= -1.; submitted= -1.}

type op_result = Success | Failure of string | ReadSuccess of key
[@@deriving bin_io]
Expand Down

0 comments on commit a1dba25

Please sign in to comment.