summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2009-08-29 07:15:29 +0100
committerMatthias Radestock <matthias@lshift.net>2009-08-29 07:15:29 +0100
commitea9bfffbead3196dabe20e418a9718f8ffb1eb3b (patch)
tree7a321f87a5bea2e3afabbc66fa6b2160474c2c0a
parent6940bbae66d15d7d1844dbbfbb32dfdcefb619a0 (diff)
downloadrabbitmq-server-git-ea9bfffbead3196dabe20e418a9718f8ffb1eb3b.tar.gz
refactoring: extract reading of stop byte
-rw-r--r--src/rabbit_disk_queue.erl31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/rabbit_disk_queue.erl b/src/rabbit_disk_queue.erl
index d88eea1b07..900692a48d 100644
--- a/src/rabbit_disk_queue.erl
+++ b/src/rabbit_disk_queue.erl
@@ -1995,26 +1995,21 @@ read_next_file_entry(FileHdl, Offset) ->
end;
{_, _} -> %% all good, let's continue
case file:read(FileHdl, MsgIdBinSize) of
- {ok, <<MsgId:MsgIdBinSize/binary>>} ->
+ {ok, <<MsgIdBin:MsgIdBinSize/binary>>} ->
ExpectedAbsPos = Offset + ?FILE_PACKING_ADJUSTMENT +
TotalSize - 1,
case file:position(
FileHdl, {cur, TotalSize - MsgIdBinSize}) of
{ok, ExpectedAbsPos} ->
- NextOffset = Offset + TotalSize +
- ?FILE_PACKING_ADJUSTMENT,
- case file:read(FileHdl, 1) of
- {ok,
- <<?WRITE_OK_TRANSIENT:?WRITE_OK_SIZE_BITS>>} ->
- {ok, {binary_to_term(MsgId),
- false, TotalSize, NextOffset}};
- {ok,
- <<?WRITE_OK_PERSISTENT:?WRITE_OK_SIZE_BITS>>} ->
- {ok, {binary_to_term(MsgId),
- true, TotalSize, NextOffset}};
- {ok, _SomeOtherData} ->
+ NextOffset = ExpectedAbsPos + 1,
+ case read_stop_byte(FileHdl) of
+ {ok, Persistent} ->
+ MsgId = binary_to_term(MsgIdBin),
+ {ok, {MsgId, Persistent,
+ TotalSize, NextOffset}};
+ corrupted ->
{corrupted, NextOffset};
- KO -> KO
+ Other -> Other
end;
{ok, _SomeOtherPos} ->
%% seek failed, so give up
@@ -2026,3 +2021,11 @@ read_next_file_entry(FileHdl, Offset) ->
end;
Other -> Other
end.
+
+read_stop_byte(FileHdl) ->
+ case file:read(FileHdl, 1) of
+ {ok, <<?WRITE_OK_TRANSIENT:?WRITE_OK_SIZE_BITS>>} -> {ok, false};
+ {ok, <<?WRITE_OK_PERSISTENT:?WRITE_OK_SIZE_BITS>>} -> {ok, true};
+ {ok, _SomeOtherData} -> corrupted;
+ KO -> KO
+ end.