diff options
author | Matthew Sackman <matthew@lshift.net> | 2009-06-17 13:09:57 +0100 |
---|---|---|
committer | Matthew Sackman <matthew@lshift.net> | 2009-06-17 13:09:57 +0100 |
commit | cd3312a50493218168fa26349023c9935d52292e (patch) | |
tree | 358c1c898eea5ab7210f2fed969920e702d87355 | |
parent | cabc5ab67fc2bc5925a0eec1b10d6fac409b2b7b (diff) | |
download | rabbitmq-server-cd3312a50493218168fa26349023c9935d52292e.tar.gz |
mainly if ==> case in suitable places, but also some formatting
-rw-r--r-- | src/rabbit_amqqueue_process.erl | 44 | ||||
-rw-r--r-- | src/rabbit_disk_queue.erl | 84 | ||||
-rw-r--r-- | src/rabbit_limiter.erl | 6 | ||||
-rw-r--r-- | src/rabbit_mnesia.erl | 5 | ||||
-rw-r--r-- | src/rabbit_queue_mode_manager.erl | 18 |
5 files changed, 88 insertions, 69 deletions
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl index 6fc31664..e2a99d19 100644 --- a/src/rabbit_amqqueue_process.erl +++ b/src/rabbit_amqqueue_process.erl @@ -217,8 +217,9 @@ deliver_queue(Fun, FunAcc0, blocked_consumers = NewBlockedConsumers, next_msg_id = NextId + 1 }, - if Remaining == 0 -> {FunAcc1, State3}; - true -> deliver_queue(Fun, FunAcc1, State3) + case Remaining of + 0 -> {FunAcc1, State3}; + _ -> deliver_queue(Fun, FunAcc1, State3) end; %% if IsMsgReady then we've hit the limiter false when IsMsgReady -> @@ -264,12 +265,13 @@ attempt_immediate_delivery(none, _ChPid, Msg, State) -> true; (AckRequired, false, State2) -> {AckTag, State3} = - if AckRequired -> + case AckRequired of + true -> {ok, AckTag2, MS} = rabbit_mixed_queue:publish_delivered( Msg, State2 #q.mixed_state), {AckTag2, State2 #q { mixed_state = MS }}; - true -> + false -> {noack, State2} end, {{Msg, false, AckTag, 0}, true, State3} @@ -579,12 +581,13 @@ handle_call({basic_get, ChPid, NoAck}, _From, {{Msg, IsDelivered, AckTag, Remaining}, MS2} -> AckRequired = not(NoAck), {ok, MS3} = - if AckRequired -> + case AckRequired of + true -> C = #cr{unacked_messages = UAM} = ch_record(ChPid), NewUAM = dict:store(NextId, {Msg, AckTag}, UAM), store_ch_record(C#cr{unacked_messages = NewUAM}), {ok, MS2}; - true -> + false -> rabbit_mixed_queue:ack([AckTag], MS2) end, Message = {QName, self(), NextId, IsDelivered, Msg}, @@ -612,15 +615,14 @@ handle_call({basic_consume, NoAck, ReaderPid, ChPid, LimiterPid, ack_required = not(NoAck)}, store_ch_record(C#cr{consumer_count = ConsumerCount +1, limiter_pid = LimiterPid}), - if ConsumerCount == 0 -> - ok = rabbit_limiter:register(LimiterPid, self()); - true -> - ok + case ConsumerCount of + 0 -> ok = rabbit_limiter:register(LimiterPid, self()); + _ -> ok end, - ExclusiveConsumer = - if ExclusiveConsume -> {ChPid, ConsumerTag}; - true -> ExistingHolder - end, + ExclusiveConsumer = case ExclusiveConsume of + true -> {ChPid, ConsumerTag}; + false -> ExistingHolder + end, State1 = State#q{has_had_consumers = true, exclusive_consumer = ExclusiveConsumer}, ok = maybe_send_reply(ChPid, OkMsg), @@ -650,11 +652,10 @@ handle_call({basic_cancel, ChPid, ConsumerTag, OkMsg}, _From, reply(ok, State); C = #cr{consumer_count = ConsumerCount, limiter_pid = LimiterPid} -> store_ch_record(C#cr{consumer_count = ConsumerCount - 1}), - if ConsumerCount == 1 -> - ok = rabbit_limiter:unregister(LimiterPid, self()); - true -> - ok - end, + ok = case ConsumerCount of + 1 -> rabbit_limiter:unregister(LimiterPid, self()); + _ -> ok + end, ok = maybe_send_reply(ChPid, OkMsg), NewState = State#q{exclusive_consumer = cancel_holder(ChPid, @@ -791,8 +792,9 @@ handle_cast({limit, ChPid, LimiterPid}, State) -> end)); handle_cast({constrain, Constrain}, State = #q { mixed_state = MS }) -> - {ok, MS2} = if Constrain -> rabbit_mixed_queue:to_disk_only_mode(MS); - true -> rabbit_mixed_queue:to_mixed_mode(MS) + {ok, MS2} = case Constrain of + true -> rabbit_mixed_queue:to_disk_only_mode(MS); + false -> rabbit_mixed_queue:to_mixed_mode(MS) end, noreply(State #q { mixed_state = MS2 }). diff --git a/src/rabbit_disk_queue.erl b/src/rabbit_disk_queue.erl index f6090634..87c7abc9 100644 --- a/src/rabbit_disk_queue.erl +++ b/src/rabbit_disk_queue.erl @@ -419,8 +419,9 @@ init([FileSizeLimit, ReadFileHandlesLimit]) -> end, %% read is only needed so that we can seek {ok, FileHdl} = file:open(Path, [read, write, raw, binary, delayed_write]), - if Exists -> {ok, Offset} = file:position(FileHdl, {bof, Offset}); - true -> %% new file, so preallocate + case Exists of + true -> {ok, Offset} = file:position(FileHdl, {bof, Offset}); + false -> %% new file, so preallocate ok = preallocate(FileHdl, FileSizeLimit, Offset) end, {ok, State1 #dqstate { current_file_handle = FileHdl }}. @@ -552,9 +553,10 @@ shutdown(State = #dqstate { msg_location_dets = MsgLocationDets, file:delete(form_filename(atom_to_list(?MSG_LOC_NAME) ++ ?FILE_EXTENSION_DETS)), true = ets:delete_all_objects(MsgLocationEts), - if FileHdl =:= undefined -> ok; - true -> file:sync(FileHdl), - file:close(FileHdl) + case FileHdl of + undefined -> ok; + _ -> file:sync(FileHdl), + file:close(FileHdl) end, dict:fold(fun (_File, Hdl, _Acc) -> file:close(Hdl) @@ -652,10 +654,11 @@ get_read_handle(File, State = current_file_handle = CurHdl, current_dirty = IsDirty }) -> - IsDirty2 = if CurName == File andalso IsDirty -> + IsDirty2 = case CurName of + File when IsDirty -> file:sync(CurHdl), false; - true -> IsDirty + _ -> IsDirty end, Now = now(), {FileHdl, ReadHdls1, ReadHdlsAge1} = @@ -749,13 +752,14 @@ internal_read_message(Q, ReadSeqId, FakeDeliver, ReadMsg, State) -> mnesia:dirty_write(rabbit_disk_queue, Obj #dq_msg_loc {is_delivered = true}) end, - if ReadMsg -> + case ReadMsg of + true -> {FileHdl, State1} = get_read_handle(File, State), {ok, {MsgBody, BodySize}} = read_message_at_offset(FileHdl, Offset, TotalSize), {ok, {MsgId, MsgBody, BodySize, Delivered, {MsgId, ReadSeqId}}, NextReadSeqId, State1}; - true -> + false -> {ok, {MsgId, Delivered, {MsgId, ReadSeqId}}, NextReadSeqId, State} end. @@ -785,7 +789,8 @@ remove_messages(Q, MsgSeqIds, MnesiaDelete, [{MsgId, RefCount, File, Offset, TotalSize}] = dets_ets_lookup(State, MsgId), Files3 = - if 1 =:= RefCount -> + case RefCount of + 1 -> ok = dets_ets_delete(State, MsgId), [{File, ValidTotalSize, ContiguousTop, Left, Right}] = ets:lookup(FileSummary, File), @@ -799,19 +804,20 @@ remove_messages(Q, MsgSeqIds, MnesiaDelete, if CurName =:= File -> Files2; true -> sets:add_element(File, Files2) end; - 1 < RefCount -> + _ when 1 < RefCount -> ok = dets_ets_insert( State, {MsgId, RefCount - 1, File, Offset, TotalSize}), Files2 end, - ok = if MnesiaDelete -> + ok = case MnesiaDelete of + true -> mnesia:dirty_delete(rabbit_disk_queue, {Q, SeqId}); - MnesiaDelete =:= txn -> + txn -> mnesia:delete(rabbit_disk_queue, {Q, SeqId}, write); - true -> ok + _ -> ok end, Files3 end, sets:new(), MsgSeqIds), @@ -834,10 +840,11 @@ internal_tx_publish(MsgId, MsgBody, ets:lookup(FileSummary, CurName), ValidTotalSize1 = ValidTotalSize + TotalSize + ?FILE_PACKING_ADJUSTMENT, - ContiguousTop1 = if CurOffset =:= ContiguousTop -> + ContiguousTop1 = case CurOffset of + ContiguousTop -> %% can't be any holes in this file ValidTotalSize1; - true -> ContiguousTop + _ -> ContiguousTop end, true = ets:insert(FileSummary, {CurName, ValidTotalSize1, ContiguousTop1, Left, undefined}), @@ -904,9 +911,10 @@ internal_tx_commit(Q, PubMsgSeqIds, AckSeqIds, {ok, State3} = remove_messages(Q, AckSeqIds, txn, State), {Sync2, WriteSeqId3, State3} end), - true = if PubList =:= [] -> true; - true -> ets:insert(Sequences, {Q, ReadSeqId, WriteSeqId, - Length + erlang:length(PubList)}) + true = case PubList of + [] -> true; + _ -> ets:insert(Sequences, {Q, ReadSeqId, WriteSeqId, + Length + erlang:length(PubList)}) end, IsDirty2 = if IsDirty andalso Sync -> ok = file:sync(CurHdl), @@ -1089,8 +1097,9 @@ maybe_roll_to_new_file(Offset, file_summary = FileSummary } ) when Offset >= FileSizeLimit -> - ok = if IsDirty -> file:sync(CurHdl); - true -> ok + ok = case IsDirty of + true -> file:sync(CurHdl); + false -> ok end, ok = file:close(CurHdl), NextNum = CurNum + 1, @@ -1181,8 +1190,9 @@ adjust_meta_and_combine( end. sort_msg_locations_by_offset(Asc, List) -> - Comp = if Asc -> fun erlang:'<'/2; - true -> fun erlang:'>'/2 + Comp = case Asc of + true -> fun erlang:'<'/2; + false -> fun erlang:'>'/2 end, lists:sort(fun ({_, _, _, OffA, _}, {_, _, _, OffB, _}) -> Comp(OffA, OffB) @@ -1212,10 +1222,11 @@ combine_files({Source, SourceValid, _SourceContiguousTop, %% the DestinationContiguousTop to a tmp file then truncate, %% copy back in, and then copy over from Source %% otherwise we just truncate straight away and copy over from Source - if DestinationContiguousTop =:= DestinationValid -> + case DestinationContiguousTop of + DestinationValid -> ok = truncate_and_extend_file(DestinationHdl, DestinationValid, ExpectedSize); - true -> + _ -> Tmp = filename:rootname(Destination) ++ ?FILE_EXTENSION_TMP, {ok, TmpHdl} = file:open(form_filename(Tmp), @@ -1413,9 +1424,9 @@ extract_sequence_numbers(State = #dqstate { sequences = Sequences }) -> %% subtraction to get the %% right length lists:max([Write, NextWrite]), Length}, - if Orig /= Repl -> - true = ets:insert(Sequences, Repl); - true -> true + case Orig of + Repl -> true; + _ -> true = ets:insert(Sequences, Repl) end end end, true, rabbit_disk_queue) @@ -1455,14 +1466,15 @@ shuffle_up(Q, BaseSeqId, SeqId, Gap) -> case mnesia:read(rabbit_disk_queue, {Q, SeqId}, write) of [] -> 1; [Obj] -> - if Gap =:= 0 -> ok; - true -> mnesia:write(rabbit_disk_queue, - Obj #dq_msg_loc { - queue_and_seq_id = {Q, SeqId + Gap }, - next_seq_id = SeqId + Gap + 1 - }, - write), - mnesia:delete(rabbit_disk_queue, {Q, SeqId}, write) + case Gap of + 0 -> ok; + _ -> mnesia:write(rabbit_disk_queue, + Obj #dq_msg_loc { + queue_and_seq_id = {Q, SeqId + Gap }, + next_seq_id = SeqId + Gap + 1 + }, + write), + mnesia:delete(rabbit_disk_queue, {Q, SeqId}, write) end, 0 end, diff --git a/src/rabbit_limiter.erl b/src/rabbit_limiter.erl index 92078acd..9f3dcbd0 100644 --- a/src/rabbit_limiter.erl +++ b/src/rabbit_limiter.erl @@ -101,10 +101,8 @@ ack(LimiterPid, Count) -> gen_server2:cast(LimiterPid, {ack, Count}). register(undefined, _QPid) -> ok; register(LimiterPid, QPid) -> gen_server2:cast(LimiterPid, {register, QPid}). -unregister(undefined, _QPid) -> - ok; -unregister(LimiterPid, QPid) -> - gen_server2:cast(LimiterPid, {unregister, QPid}). +unregister(undefined, _QPid) -> ok; +unregister(LimiterPid, QPid) -> gen_server2:cast(LimiterPid, {unregister, QPid}). %%---------------------------------------------------------------------------- %% gen_server callbacks diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 9e341584..6c583cb4 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -272,7 +272,8 @@ init_db(ClusterNodes) -> ExtraNodes = ClusterNodes -- [node()], case mnesia:change_config(extra_db_nodes, ExtraNodes) of {ok, []} -> - if WasDiskNode -> + case WasDiskNode of + true -> case check_schema_integrity() of ok -> ok; @@ -287,7 +288,7 @@ init_db(ClusterNodes) -> ok = move_db(), ok = create_schema() end; - true -> + false -> ok = create_schema() end; {ok, [_|_]} -> diff --git a/src/rabbit_queue_mode_manager.erl b/src/rabbit_queue_mode_manager.erl index c37cb842..c905d99b 100644 --- a/src/rabbit_queue_mode_manager.erl +++ b/src/rabbit_queue_mode_manager.erl @@ -77,21 +77,27 @@ handle_call({register, Pid}, _From, end, {reply, {ok, Result}, State #state { queues = [Pid | Qs] }}. -handle_cast({change_memory_usage, true}, State = #state { mode=disk_only }) -> +handle_cast({change_memory_usage, true}, + State = #state { mode = disk_only }) -> {noreply, State}; -handle_cast({change_memory_usage, true}, State = #state { mode=ram_disk }) -> +handle_cast({change_memory_usage, true}, + State = #state { mode = ram_disk }) -> constrain_queues(true, State #state.queues), {noreply, State #state { mode = disk_only }}; -handle_cast({change_memory_usage, true}, State = #state { mode=unlimited }) -> +handle_cast({change_memory_usage, true}, + State = #state { mode = unlimited }) -> ok = rabbit_disk_queue:to_disk_only_mode(), {noreply, State #state { mode = ram_disk }}; -handle_cast({change_memory_usage, false}, State = #state { mode=unlimited }) -> +handle_cast({change_memory_usage, false}, + State = #state { mode = unlimited }) -> {noreply, State}; -handle_cast({change_memory_usage, false}, State = #state { mode=ram_disk }) -> +handle_cast({change_memory_usage, false}, + State = #state { mode = ram_disk }) -> ok = rabbit_disk_queue:to_ram_disk_mode(), {noreply, State #state { mode = unlimited }}; -handle_cast({change_memory_usage, false}, State = #state { mode=disk_only }) -> +handle_cast({change_memory_usage, false}, + State = #state { mode = disk_only }) -> constrain_queues(false, State #state.queues), {noreply, State #state { mode = ram_disk }}. |