Skip to content

Commit

Permalink
don't die, but call all handlers when inner loop fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Slootmaekers committed Mar 19, 2015
1 parent 829090e commit d0b9e2a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion META
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- conf -*-

description = "Kinetic client"
version = "0.0.3"
version = "0.0.4"
exists_if = "kinetic.cmx,kinetic.cmi,kinetic.mli"
requires = "threads lwt lwt.unix cryptokit"
archive(byte) = "kinetic.client.cma"
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ This is an OCaml client for [Seagate's Kinetic drives](https://developers.seagat
Currently, it uses protocol version 3.0.6.
This is corresponds with version 0.8.0.3 of the Java Simulator.

Todo:
- [X] support 3.X protocol
- [ ] use 4.0.2 Bytes iso strings for buffers (depends on piqi)
- [X] opam installable
- [ ] publish 0.0.3 on opam repo

Installation
============
Expand Down
20 changes: 17 additions & 3 deletions src/kinetic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ struct

let remove t h = Hashtbl.remove t h

let make session (ic,oc) batch_id =
let make session conn batch_id =
let ic,oc = conn in
let handlers = Hashtbl.create 5 in
let mvar = Lwt_mvar.create_empty () in
let rec loop (go:bool ref) (ic:Lwt_io.input_channel) =
Expand Down Expand Up @@ -379,9 +380,22 @@ struct
end
in
let go = ref true in
let t = loop go ic in
let t =
Lwt.catch
(fun () ->loop go ic )
(fun exn ->
Lwt_log.debug_f ~exn ~section "batch loop for %li failed" batch_id
>>= fun ()->
let rci = status_code2i `internal_error in
let rc_bad = Nok (rci, Printexc.to_string exn) in
Hashtbl.iter (fun k h ->
Lwt.ignore_result (h rc_bad);
) handlers;
Lwt.return ()
)
in
let () = Lwt.ignore_result t in
{ mvar ; handlers ; conn = (ic,oc) ; batch_id; go = go; session}
{ mvar ; handlers ; conn; batch_id; go = go; session}

let add_handler t typ h =
let typs = message_type2s typ in
Expand Down
4 changes: 3 additions & 1 deletion src/kinetic.mli
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ module Kinetic : sig

(**
Batches are atomic multi-updates.
(while you're doing a batch, you're not supposed to use the connection )
Remark:
- while you're doing a batch, you're not supposed to use the connection
- handlers should not raise exceptions as these have no where to go.
*)
val start_batch_operation :
?handler:handler ->
Expand Down

0 comments on commit d0b9e2a

Please sign in to comment.