Skip to content

Commit

Permalink
Refactor metadata locking
Browse files Browse the repository at this point in the history
  • Loading branch information
astrada committed Nov 19, 2016
1 parent b218efe commit 9aa6639
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type t = {
mountpoint_stats : Unix.LargeFile.stats;
(* Current metadata *)
metadata : Cache.Metadata.t option;
(* Metadata lock *)
metadata_lock : Mutex.t;
(* Whether permanently delete files *)
skip_trash : bool;
(* Memory buffers *)
Expand Down Expand Up @@ -62,6 +64,10 @@ let metadata = {
GapiLens.get = (fun x -> x.metadata);
GapiLens.set = (fun v x -> { x with metadata = v })
}
let metadata_lock = {
GapiLens.get = (fun x -> x.metadata_lock);
GapiLens.set = (fun v x -> { x with metadata_lock = v })
}
let skip_trash = {
GapiLens.get = (fun x -> x.skip_trash);
GapiLens.set = (fun v x -> { x with skip_trash = v })
Expand Down
11 changes: 4 additions & 7 deletions src/drive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@ let get_root_resource trashed =
inserted
| Some resource -> resource

let metadata_mutex = Mutex.create ()
let with_metadata_lock f = Utils.with_lock metadata_mutex f

let update_cache_size delta metadata cache =
Utils.log_with_header "BEGIN: Updating cache size (delta=%Ld) in db\n%!"
delta;
Expand All @@ -415,7 +412,7 @@ let shrink_cache ?(file_size = 0L) () =
let config = context |. Context.config_lens in
let max_cache_size_mb = config.Config.max_cache_size_mb in
let cache = context.Context.cache in
with_metadata_lock
Utils.with_lock context.Context.metadata_lock
(fun () ->
let max_cache_size =
Int64.mul (Int64.of_int max_cache_size_mb) Utils.mb in
Expand Down Expand Up @@ -486,14 +483,14 @@ let delete_cached_resources metadata cache resources =
resources

let update_cache_size_for_documents cache resource content_path op =
with_metadata_lock
let context = Context.get_ctx () in
Utils.with_lock context.Context.metadata_lock
(fun () ->
if resource.Cache.Resource.size = Some 0L &&
Sys.file_exists content_path then begin
try
let stats = Unix.LargeFile.stat content_path in
let size = stats.Unix.LargeFile.st_size in
let context = Context.get_ctx () in
let metadata = context |. Context.metadata_lens in
let delta = op size in
update_cache_size delta metadata cache
Expand Down Expand Up @@ -740,7 +737,7 @@ let get_metadata () =
db_metadata |> Cache.Metadata.cache_size ^= cache_size
in

with_metadata_lock
Utils.with_lock context.Context.metadata_lock
(fun () ->
let metadata =
let context = Context.get_ctx () in
Expand Down
1 change: 1 addition & 0 deletions src/gdfuse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ let setup_application params =
curl_state;
mountpoint_stats = Unix.LargeFile.stat mountpoint;
metadata = None;
metadata_lock = Mutex.create ();
skip_trash = params.skip_trash;
memory_buffers =
Buffering.MemoryBuffers.create config.Config.memory_buffer_size;
Expand Down

0 comments on commit 9aa6639

Please sign in to comment.