Add sync test option

This commit is contained in:
Pierre Chambart 2018-10-02 15:44:22 +02:00 committed by Grégoire Henry
parent 2baa6c830c
commit 56936c7a1e
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2
2 changed files with 26 additions and 2 deletions

View File

@ -66,7 +66,19 @@ let (>>=?) v f =
let init ?mapsize path = let init ?mapsize path =
if not (Sys.file_exists path) then Unix.mkdir path 0o755 ; if not (Sys.file_exists path) then Unix.mkdir path 0o755 ;
match Lmdb.opendir ?mapsize ~flags:[NoTLS; NoMetaSync] path 0o644 with let sync_flag =
match Sys.getenv_opt "TEZOS_STORE_SYNC" with
| None -> []
| Some s ->
match String.lowercase_ascii s with
| "nosync" -> [ Lmdb.NoSync ]
| "nometasync" -> [ Lmdb.NoMetaSync ]
| _ ->
Printf.eprintf "Unrecognized TEZOS_SYNC option : %s\n\
allowed: nosync nometasync" s;
[]
in
match Lmdb.opendir ?mapsize ~flags:(sync_flag @ [NoTLS; NoMetaSync]) path 0o644 with
| Ok dir -> return { dir ; parent = Lwt.new_key () } | Ok dir -> return { dir ; parent = Lwt.new_key () }
| Error err -> failwith "%a" Lmdb.pp_error err | Error err -> failwith "%a" Lmdb.pp_error err

View File

@ -677,7 +677,19 @@ module Make
let root = match root with None -> "irmin.ldb" | Some root -> root in let root = match root with None -> "irmin.ldb" | Some root -> root in
if not (Sys.file_exists root) then Unix.mkdir root 0o755 ; if not (Sys.file_exists root) then Unix.mkdir root 0o755 ;
let flags = if readonly then [ Lmdb.RdOnly ] else [] in let flags = if readonly then [ Lmdb.RdOnly ] else [] in
let flags = Lmdb.NoRdAhead :: Lmdb.NoTLS :: flags in let sync_flag =
match Sys.getenv_opt "TEZOS_CONTEXT_SYNC" with
| None -> []
| Some s ->
match String.lowercase_ascii s with
| "nosync" -> [ Lmdb.NoSync ]
| "nometasync" -> [ Lmdb.NoMetaSync ]
| _ ->
Printf.eprintf "Unrecognized TEZOS_SYNC option : %s\n\
allowed: nosync nometasync" s;
[]
in
let flags = sync_flag @ Lmdb.NoRdAhead :: Lmdb.NoTLS :: flags in
let file_flags = if readonly then 0o444 else 0o644 in let file_flags = if readonly then 0o444 else 0o644 in
match Lmdb.opendir ~mapsize ~flags root file_flags with match Lmdb.opendir ~mapsize ~flags root file_flags with
| Error err -> Lwt.fail_with (Lmdb.string_of_error err) | Error err -> Lwt.fail_with (Lmdb.string_of_error err)