diff options
| author | Michael Klishin <michael@novemberain.com> | 2015-08-06 17:19:08 +0300 |
|---|---|---|
| committer | Michael Klishin <michael@novemberain.com> | 2015-08-06 17:19:08 +0300 |
| commit | 559f7e237ddc31eb2bf42cffc30b1c52e142965f (patch) | |
| tree | 6c4b6248c861857b45e0095aac9649967377c85e | |
| parent | 06ce1d512c96ee0b2be6c387123570f03798e133 (diff) | |
| parent | 41b40e3d080e2b1f4ef5cba9426c71e1b59d4e52 (diff) | |
| download | rabbitmq-server-git-559f7e237ddc31eb2bf42cffc30b1c52e142965f.tar.gz | |
Merge pull request #256 from rabbitmq/rabbitmq-server-245
Priority queue: Fix a crash when querying 'head_message_timestamp'
| -rw-r--r-- | src/rabbit_priority_queue.erl | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/rabbit_priority_queue.erl b/src/rabbit_priority_queue.erl index 206d674abc..a839badfc4 100644 --- a/src/rabbit_priority_queue.erl +++ b/src/rabbit_priority_queue.erl @@ -376,6 +376,8 @@ info(backing_queue_status, #state{bq = BQ, bqss = BQSs}) -> fold0(fun (P, BQSN, Acc) -> combine_status(P, BQ:info(backing_queue_status, BQSN), Acc) end, nothing, BQSs); +info(head_message_timestamp, #state{bq = BQ, bqss = BQSs}) -> + find_head_message_timestamp(BQ, BQSs, ''); info(Item, #state{bq = BQ, bqss = BQSs}) -> fold0(fun (_P, BQSN, Acc) -> Acc + BQ:info(Item, BQSN) @@ -582,3 +584,17 @@ cse(_, infinity) -> infinity; cse(A, B) when is_number(A) -> A + B; cse({delta, _, _, _}, _) -> {delta, todo, todo, todo}; cse(A, B) -> exit({A, B}). + +%% When asked about 'head_message_timestamp' fro this priority queue, we +%% walk all the backing queues, starting by the highest priority. Once a +%% backing queue having messages (ready or unacknowledged) is found, its +%% 'head_message_timestamp' is returned even if it is null. + +find_head_message_timestamp(BQ, [{_, BQSN} | Rest], Timestamp) -> + MsgCount = BQ:len(BQSN) + BQ:info(messages_unacknowledged_ram, BQSN), + if + MsgCount =/= 0 -> BQ:info(head_message_timestamp, BQSN); + true -> find_head_message_timestamp(BQ, Rest, Timestamp) + end; +find_head_message_timestamp(_, [], Timestamp) -> + Timestamp. |
