Skip to content
This repository has been archived by the owner on Nov 28, 2017. It is now read-only.

Commit

Permalink
Merge pull request #85 from jonludlam/circ-buffer
Browse files Browse the repository at this point in the history
Circular buffer
  • Loading branch information
Jon Ludlam committed Nov 9, 2015
2 parents 11edef4 + abc5260 commit 2ffe5a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
7 changes: 6 additions & 1 deletion lib/metadata.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,12 @@ let write device mdah md =
let absnewpos = Int64.add mrl_offset mdah.mdah_start in
let open IO in
B.write device absnewpos firstbitbuf >>= fun () ->
B.write device (Int64.add mdah.mdah_start 512L) secondbitbuf >>= fun () ->
begin
if secondbit>0
then B.write device (Int64.add mdah.mdah_start 512L) secondbitbuf
else Lwt.return (`Ok ())
end
>>= fun () ->

(* Now we have to update the crc and pointer to the metadata *)

Expand Down
10 changes: 5 additions & 5 deletions lib/vg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ let id_to_devices devices : 'a result Lwt.t =
Lwt.return (`Ok (label.Label.pv_header.Label.Pv_header.id, device))
) devices)

let write metadata devices : unit result Lwt.t =
let write metadata devices =
let devices = List.map snd devices in
id_to_devices devices
>>= fun id_to_devices ->
Expand Down Expand Up @@ -491,7 +491,7 @@ let write metadata devices : unit result Lwt.t =
end in
let open IO in
write_vg [] metadata.pvs >>= fun _pvs ->
return ()
return { metadata with pvs = _pvs }

let run metadata ops : metadata result Lwt.t =
let open Result in
Expand Down Expand Up @@ -546,7 +546,7 @@ let format name ?(creation_host="unknown") ?(creation_time=0L) ?(magic = `Lvm) d
| `Error x -> Lwt.return (`Error x)
)
) >>= fun metadata ->
write metadata devices >>= fun () ->
write metadata devices >>= fun _ ->
return ()

let read flush_interval devices flag : vg result Lwt.t =
Expand Down Expand Up @@ -641,7 +641,7 @@ let read flush_interval devices flag : vg result Lwt.t =
run !on_disk_metadata ops
>>|= fun metadata ->
write metadata name_to_devices
>>|= fun () ->
>>|= fun metadata ->
on_disk_metadata := metadata;
return (`Ok ()) in

Expand Down Expand Up @@ -718,7 +718,7 @@ let update vg ops : unit result Lwt.t =
vg.wait_for_flush_t <- last.Redo_log.sync;
vg.trigger_flush_now <- last.Redo_log.flush
| [] -> () );
return (`Ok ()) ) >>= fun () ->
return (`Ok metadata) ) >>= fun metadata ->
(* Update our cache of the metadata *)
vg.metadata <- metadata;
return ()
Expand Down
11 changes: 6 additions & 5 deletions lib_test/vg_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ let lv_create magic () =
Vg_IO.sync vg >>|= fun () ->
let md' = Vg_IO.metadata_of vg in
let md' = Vg.metadata_of_sexp (Vg.sexp_of_metadata md') in
(* Ignore the location of the metadata *)
let md = {md with Vg.pvs = List.map (fun pv -> {pv with Pv.headers = []}) md.pvs } in
let md' = {md' with Vg.pvs = List.map (fun pv -> {pv with Pv.headers = []}) md'.pvs } in
assert_equal (Vg.to_string md) (Vg.to_string md');
let id = expect_some (Vg_IO.find vg "name") in
let v_md = Vg_IO.Volume.metadata_of id in
Expand Down Expand Up @@ -555,12 +558,10 @@ let lv_lots_of_ops () =
Vg.create (Vg_IO.metadata_of vg) ~tags:[tag] name ~status:Lv.Status.([Read; Write; Visible]) small >>*= fun (_,op) ->
Vg_IO.update vg [ op ] >>|= fun () ->
Vg_IO.sync vg >>|= fun () ->
let (_: Vg_IO.Volume.id) = expect_some (Vg_IO.find vg name) in
Vg.remove (Vg_IO.metadata_of vg) name >>*= fun (_, op) ->
Vg_IO.update vg [ op ] >>|= fun () ->
Vg_IO.sync vg >>|= fun () ->
Vg_IO.connect [ block ] `RO >>|= fun vg' ->
let (_: Vg_IO.Volume.id) = expect_some (Vg_IO.find vg' name) in
loop (n - 1) in
loop 1000 (* hopefully this fills up the 10M metadata area *)
loop 400 (* this fills up the 10M metadata area twice *)
)
in
Lwt_main.run t)
Expand Down

0 comments on commit 2ffe5a1

Please sign in to comment.