diff options
| author | Matthew Sackman <matthew@lshift.net> | 2010-05-18 14:22:10 +0100 |
|---|---|---|
| committer | Matthew Sackman <matthew@lshift.net> | 2010-05-18 14:22:10 +0100 |
| commit | c06cebee9707c71769aa4b30f75792fd13c691f6 (patch) | |
| tree | c50401491e65ce0a8b809ac310d5b9bbe65f155a | |
| parent | 0f915894a406256d00f30f87f448143381ba3116 (diff) | |
| download | rabbitmq-server-git-c06cebee9707c71769aa4b30f75792fd13c691f6.tar.gz | |
Cosmetics and documentation
| -rw-r--r-- | src/rabbit_queue_index.erl | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/rabbit_queue_index.erl b/src/rabbit_queue_index.erl index 6d39d99081..9cd816b21d 100644 --- a/src/rabbit_queue_index.erl +++ b/src/rabbit_queue_index.erl @@ -80,18 +80,20 @@ %% contains a mapping from segment numbers to state-per-segment (this %% state is held for all segments which have been "seen": thus a %% segment which has been read but has no pending entries in the -%% journal is still held in this mapping). Actions are stored directly -%% in this state. Thus at the point of flushing the journal, firstly -%% no reading from disk is necessary, but secondly if the known number -%% of acks and publishes in a segment are equal, given the known state -%% of the segment file combined with the journal, no writing needs to -%% be done to the segment file either (in fact it is deleted if it -%% exists at all). This is safe given that the set of acks is a subset -%% of the set of publishes. When it's necessary to sync messages -%% because of transactions, it's only necessary to fsync on the -%% journal: when entries are distributed from the journal to segment -%% files, those segments appended to are fsync'd prior to the journal -%% being truncated. +%% journal is still held in this mapping. Also note that a dict is +%% used for this mapping, not an array because with an array, you will +%% always have entries from 0). Actions are stored directly in this +%% state. Thus at the point of flushing the journal, firstly no +%% reading from disk is necessary, but secondly if the known number of +%% acks and publishes in a segment are equal, given the known state of +%% the segment file combined with the journal, no writing needs to be +%% done to the segment file either (in fact it is deleted if it exists +%% at all). This is safe given that the set of acks is a subset of the +%% set of publishes. When it's necessary to sync messages because of +%% transactions, it's only necessary to fsync on the journal: when +%% entries are distributed from the journal to segment files, those +%% segments appended to are fsync'd prior to the journal being +%% truncated. %% %% This module is also responsible for scanning the queue index files %% and seeding the message store on start up. @@ -734,13 +736,6 @@ get_segment_handle(Segment = #segment { handle = undefined, path = Path }) -> get_segment_handle(Segment = #segment { handle = Hdl }) -> {Hdl, Segment}. -segment_find(Seg, {_Segments, [Segment = #segment { num = Seg } |_]}) -> - {ok, Segment}; %% 1 or (2, matches head) -segment_find(Seg, {_Segments, [_, Segment = #segment { num = Seg }]}) -> - {ok, Segment}; %% 2, matches tail -segment_find(Seg, {Segments, _}) -> %% no match - dict:find(Seg, Segments). - segment_new(Seg, Dir) -> #segment { pubs = 0, acks = 0, @@ -756,6 +751,13 @@ segment_find_or_new(Seg, Dir, Segments) -> {ok, Segment} -> Segment end. +segment_find(Seg, {_Segments, [Segment = #segment { num = Seg } |_]}) -> + {ok, Segment}; %% 1 or (2, matches head) +segment_find(Seg, {_Segments, [_, Segment = #segment { num = Seg }]}) -> + {ok, Segment}; %% 2, matches tail +segment_find(Seg, {Segments, _}) -> %% no match + dict:find(Seg, Segments). + segment_store(Segment = #segment { num = Seg }, %% 1 or (2, matches head) {Segments, [#segment { num = Seg } | Tail]}) -> {Segments, [Segment | Tail]}; |
