From 80ea2ac6af8f993888444a4f75bbcc976ddd3973 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Mon, 27 Oct 2014 01:24:09 +0100 Subject: Parallel fsync --- src/fsyncport.erl | 22 +++++++++++++++++++++- src/util.erl | 16 +++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/fsyncport.erl b/src/fsyncport.erl index 5084fdd..c9be44d 100644 --- a/src/fsyncport.erl +++ b/src/fsyncport.erl @@ -3,7 +3,7 @@ -module(fsyncport). -export([start_link/0, stop/0, init/1]). --export([fsync/1]). +-export([fsync/1, fsyncall/1]). start_link() -> Pid = spawn(?MODULE, init, [code:priv_dir(plop) ++ "/fsynchelper"]), @@ -14,6 +14,9 @@ stop() -> fsync(Path) -> call_port({fsync, Path}). +fsyncall(Paths) -> + call_port_multi([{fsync, Path} || Path <- Paths]). + call_port(Msg) -> fsyncport ! {call, self(), Msg}, receive @@ -21,6 +24,23 @@ call_port(Msg) -> Result end. +call_port_multi(Msgs) -> + lists:foreach(fun (Msg) -> + fsyncport ! {call, self(), Msg} + end, Msgs), + lists:foldl(fun (_Msg, Acc) -> + R = receive + {fsyncport, Result} -> + Result + end, + case R of + ok -> + Acc; + Error -> + Error + end + end, ok, Msgs). + init(ExtPrg) -> lager:debug("starting fsync service"), register(fsyncport, self()), diff --git a/src/util.erl b/src/util.erl index dd42752..435dbc8 100644 --- a/src/util.erl +++ b/src/util.erl @@ -13,15 +13,13 @@ tempfilename(Base) -> Filename. -spec fsync([string()]) -> ok. -fsync([]) -> - ok; -fsync([Name | Rest]) -> - case fsyncport:fsync(Name) of - ok -> - fsync(Rest); - {error, Error} -> - exit_with_error(fsync, Error, "Error in fsync") - end. +fsync(Paths) -> + case fsyncport:fsyncall(Paths) of + ok -> + ok; + {error, Error} -> + exit_with_error(fsync, Error, "Error in fsync") + end. -spec exit_with_error(atom(), atom(), string()) -> no_return(). exit_with_error(Operation, Error, ErrorMessage) -> -- cgit v1.1