summaryrefslogtreecommitdiff
path: root/src/rabbit_msg_store_gc.erl
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@lshift.net>2010-04-01 19:08:04 +0100
committerMatthew Sackman <matthew@lshift.net>2010-04-01 19:08:04 +0100
commit2d3682168b298eba45b8b816c9f880337880a3ae (patch)
treec1eb0a97ece1edc59ce5d5388d66530fc3c93cba /src/rabbit_msg_store_gc.erl
parentb851a84c3ea9535ab9a317ade3deeaeeaca7608e (diff)
downloadrabbitmq-server-2d3682168b298eba45b8b816c9f880337880a3ae.tar.gz
Split msg_store into two msg stores, one for persistent and one for transient. This is the first step in trying to make startup and recovery of data on disk much faster.
Diffstat (limited to 'src/rabbit_msg_store_gc.erl')
-rw-r--r--src/rabbit_msg_store_gc.erl45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/rabbit_msg_store_gc.erl b/src/rabbit_msg_store_gc.erl
index a64733df..9cf11af2 100644
--- a/src/rabbit_msg_store_gc.erl
+++ b/src/rabbit_msg_store_gc.erl
@@ -33,7 +33,7 @@
-behaviour(gen_server2).
--export([start_link/3, gc/2, stop/0]).
+-export([start_link/4, gc/3, stop/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
@@ -41,40 +41,42 @@
-record(gcstate,
{dir,
index_state,
- index_module
+ index_module,
+ parent,
+ file_summary_ets
}).
-include("rabbit_msg_store.hrl").
--define(SERVER, ?MODULE).
-
%%----------------------------------------------------------------------------
-start_link(Dir, IndexState, IndexModule) ->
- gen_server2:start_link({local, ?SERVER}, ?MODULE,
- [Dir, IndexState, IndexModule],
- [{timeout, infinity}]).
+start_link(Dir, IndexState, IndexModule, FileSummaryEts) ->
+ gen_server2:start_link(
+ ?MODULE, [self(), Dir, IndexState, IndexModule, FileSummaryEts],
+ [{timeout, infinity}]).
-gc(Source, Destination) ->
- gen_server2:cast(?SERVER, {gc, Source, Destination}).
+gc(Server, Source, Destination) ->
+ gen_server2:cast(Server, {gc, Source, Destination}).
-stop() ->
- gen_server2:call(?SERVER, stop).
+stop(Server) ->
+ gen_server2:call(Server, stop).
%%----------------------------------------------------------------------------
-init([Dir, IndexState, IndexModule]) ->
+init([Parent, Dir, IndexState, IndexModule, FileSummaryEts]) ->
{ok, #gcstate { dir = Dir, index_state = IndexState,
- index_module = IndexModule },
+ index_module = IndexModule, parent = Parent,
+ file_summary_ets = FileSummaryEts},
hibernate,
{backoff, ?HIBERNATE_AFTER_MIN, ?HIBERNATE_AFTER_MIN, ?DESIRED_HIBERNATE}}.
handle_call(stop, _From, State) ->
{stop, normal, ok, State}.
-handle_cast({gc, Source, Destination}, State) ->
- Reclaimed = adjust_meta_and_combine(Source, Destination, State),
- ok = rabbit_msg_store:gc_done(Reclaimed, Source, Destination),
+handle_cast({gc, Source, Destination}, State = #gcstate { parent = Parent }) ->
+ Reclaimed = adjust_meta_and_combine(Source, Destination,
+ State),
+ ok = rabbit_msg_store:gc_done(Parent, Reclaimed, Source, Destination),
{noreply, State, hibernate}.
handle_info({file_handle_cache, maximum_eldest_since_use, Age}, State) ->
@@ -92,18 +94,19 @@ code_change(_OldVsn, State, _Extra) ->
%%----------------------------------------------------------------------------
-adjust_meta_and_combine(SourceFile, DestFile, State) ->
+adjust_meta_and_combine(SourceFile, DestFile, State =
+ #gcstate { file_summary_ets = FileSummaryEts }) ->
[SourceObj = #file_summary {
readers = SourceReaders,
valid_total_size = SourceValidData, left = DestFile,
file_size = SourceFileSize, locked = true }] =
- ets:lookup(?FILE_SUMMARY_ETS_NAME, SourceFile),
+ ets:lookup(FileSummaryEts, SourceFile),
[DestObj = #file_summary {
readers = DestReaders,
valid_total_size = DestValidData, right = SourceFile,
file_size = DestFileSize, locked = true }] =
- ets:lookup(?FILE_SUMMARY_ETS_NAME, DestFile),
+ ets:lookup(FileSummaryEts, DestFile),
case SourceReaders =:= 0 andalso DestReaders =:= 0 of
true ->
@@ -112,7 +115,7 @@ adjust_meta_and_combine(SourceFile, DestFile, State) ->
%% don't update dest.right, because it could be changing
%% at the same time
true = ets:update_element(
- ?FILE_SUMMARY_ETS_NAME, DestFile,
+ FileSummaryEts, DestFile,
[{#file_summary.valid_total_size, TotalValidData},
{#file_summary.contiguous_top, TotalValidData},
{#file_summary.file_size, TotalValidData}]),