summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2012-02-06 23:45:34 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2012-02-06 23:45:34 +0000
commitace78be9bd1f1ee0c00d7cc637edaf27695f69ca (patch)
tree6e95c837d0be5ec1de2d7d692ef4484f93652c7e
parent4f22b33092c2346578c1e7f73b2c859e37c217ef (diff)
downloadrabbitmq-server-git-ace78be9bd1f1ee0c00d7cc637edaf27695f69ca.tar.gz
Don't sync the mnesia disk log when nothing got written to it
This is imperfect but safe.
-rw-r--r--src/rabbit_misc.erl25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index f224b0436d..9a6879b13d 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -414,16 +414,25 @@ execute_mnesia_transaction(TxFun) ->
%% Making this a sync_transaction allows us to use dirty_read
%% elsewhere and get a consistent result even when that read
%% executes on a different node.
- case worker_pool:submit({mnesia, sync_transaction, [TxFun]}) of
- {atomic, Result} -> case mnesia:is_transaction() of
- true -> ok;
- false -> mnesia_sync:sync()
- end,
- Result;
- {aborted, Reason} -> throw({error, Reason})
+ case worker_pool:submit(
+ fun () ->
+ case mnesia:is_transaction() of
+ false -> DiskLogBefore = mnesia_dumper:get_log_writes(),
+ Res = mnesia:sync_transaction(TxFun),
+ DiskLogAfter = mnesia_dumper:get_log_writes(),
+ case DiskLogAfter == DiskLogBefore of
+ true -> Res;
+ false -> {sync, Res}
+ end;
+ true -> mnesia:sync_transaction(TxFun)
+ end
+ end) of
+ {sync, {atomic, Result}} -> mnesia_sync:sync(), Result;
+ {sync, {aborted, Reason}} -> throw({error, Reason});
+ {atomic, Result} -> Result;
+ {aborted, Reason} -> throw({error, Reason})
end.
-
%% Like execute_mnesia_transaction/1 with additional Pre- and Post-
%% commit function
execute_mnesia_transaction(TxFun, PrePostCommitFun) ->