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
commitec049687cafbf03bb60a8d60552e7265e6865cea (patch)
tree6e95c837d0be5ec1de2d7d692ef4484f93652c7e
parent2fdee97e0f1cad03faf1827eb6f43ec78c1d3e1f (diff)
downloadrabbitmq-server-bug24730.tar.gz
Don't sync the mnesia disk log when nothing got written to itbug24730
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 f224b043..9a6879b1 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) ->