Skip to content

Commit

Permalink
* flog0: scanforward should start with time from metadata iso Time.zero
Browse files Browse the repository at this point in the history
* store: reading beyond the store should raise End_of_file
=> rewrite test succeeds
  • Loading branch information
Romain Slootmaekers committed Sep 4, 2012
1 parent 6eb87aa commit d0a40bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
23 changes: 13 additions & 10 deletions src/flog0.ml
Expand Up @@ -110,14 +110,15 @@ let _read_metadata fd =
let t0 = input_time input in
return {commit; td;t0}

type t = { spindles : S.t array;
start : Time.t;
mutable last: (spindle * offset);
mutable next_spindle: int;
mutable d: int;
mutable now: Time.t;
filename : string;
}
type t = {
spindles : S.t array;
start : Time.t;
mutable last: (spindle * offset);
mutable next_spindle: int;
mutable d: int;
mutable now: Time.t;
filename : string;
}

let get_d t = t.d

Expand Down Expand Up @@ -427,7 +428,8 @@ let lookup t =

let init ?(d=8) fn t0 =
S.init fn >>= fun s ->
if S.next s = 0 then
if S.next s = 0
then
let commit = (Spindle 0, Offset 0) in
_write_metadata s {commit;td = d; t0} >>= fun () ->
S.close s
Expand Down Expand Up @@ -470,7 +472,8 @@ let make filename =
in
let (_,Offset tbr) = m.commit in
let corrected_tbr = max _METADATA_SIZE tbr in
_scan_forward ((Spindle 0, Offset 0),Time.zero) corrected_tbr >>= fun (last, now) ->

_scan_forward ((Spindle 0, Offset 0),m.t0) corrected_tbr >>= fun (last, now) ->
let flog0 = { spindles=spindles;
last=last;
next_spindle=0;
Expand Down
4 changes: 2 additions & 2 deletions src/rewrite_test.ml
Expand Up @@ -35,9 +35,9 @@ let test_presence () =
let kvs =
let rec loop acc = function
| 26 -> acc
| i ->
| i ->
let c0 = Char.chr (65 + i) in
let c1 = Char.chr (96 + i) in
let c1 = Char.chr (97 + i) in
let kv = (Printf.sprintf "%c" c0, Printf.sprintf "%c" c1) in
loop (kv :: acc) (i+1)
in
Expand Down
25 changes: 17 additions & 8 deletions src/store.ml
Expand Up @@ -31,18 +31,27 @@ module Memory : STORE with type 'a m = 'a =
let return v = v

let init (n:string) =
if Hashtbl.mem memory_store n
then
return (Hashtbl.find memory_store n)
else
let v = T (ref (Buffer.create 128)) in
Hashtbl.replace memory_store n v;
return v
let v =
if Hashtbl.mem memory_store n
then Hashtbl.find memory_store n
else
let v = T (ref (Buffer.create 128)) in
let () = Hashtbl.replace memory_store n v in
v
in
return v

let close _ = return ()

let next (T b) = Buffer.length (!b)

let read (T b) o l = return (Buffer.sub !b o l)
let read (T b) o l =
if o < Buffer.length (!b)
then
return (Buffer.sub !b o l)
else
raise End_of_file

let write (T b) d p l o =
let s = Buffer.contents !b in
let sl = String.length s in
Expand Down

0 comments on commit d0a40bc

Please sign in to comment.