Skip to content

Commit ed88e38

Browse files
Merge pull request #9418 from rabbitmq/osiris-1.6.6
Osiris 1.6.7
2 parents 9ba3e3d + 739214b commit ed88e38

File tree

4 files changed

+56
-64
lines changed

4 files changed

+56
-64
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bazel_dep(
4343

4444
bazel_dep(
4545
name = "rabbitmq_osiris",
46-
version = "1.6.4",
46+
version = "1.6.7",
4747
repo_name = "osiris",
4848
)
4949

deps/rabbit/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers amqp_client meck prop
149149
PLT_APPS += mnesia
150150

151151
dep_syslog = git https://github.com/schlagert/syslog 4.0.0
152-
dep_osiris = git https://github.com/rabbitmq/osiris v1.6.4
152+
dep_osiris = git https://github.com/rabbitmq/osiris v1.6.7
153153
dep_systemd = hex 0.6.1
154154
dep_seshat = git https://github.com/rabbitmq/seshat v0.6.1
155155

deps/rabbit/src/rabbit_stream_coordinator.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ writer_pid(StreamId) when is_list(StreamId) ->
239239
MFA = {?MODULE, query_writer_pid, [StreamId]},
240240
query_pid(StreamId, MFA).
241241

242+
-spec local_pid(string()) ->
243+
{ok, pid()} | {error, not_found | term()}.
242244
local_pid(StreamId) when is_list(StreamId) ->
243245
MFA = {?MODULE, query_local_pid, [StreamId, node()]},
244246
query_pid(StreamId, MFA).

deps/rabbit/src/rabbit_stream_queue.erl

Lines changed: 52 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,11 @@ consume(Q, #{limiter_active := true}, _State)
238238
when ?amqqueue_is_stream(Q) ->
239239
{error, global_qos_not_supported_for_queue_type};
240240
consume(Q, Spec,
241-
#stream_client{filtering_supported = FilteringSupported} = QState0) when ?amqqueue_is_stream(Q) ->
241+
#stream_client{filtering_supported = FilteringSupported} = QState0)
242+
when ?amqqueue_is_stream(Q) ->
242243
%% Messages should include the offset as a custom header.
243-
case check_queue_exists_in_local_node(Q) of
244-
ok ->
244+
case get_local_pid(QState0) of
245+
{LocalPid, QState} when is_pid(LocalPid) ->
245246
#{no_ack := NoAck,
246247
channel_pid := ChPid,
247248
prefetch_count := ConsumerPrefetchCount,
@@ -250,30 +251,34 @@ consume(Q, Spec,
250251
args := Args,
251252
ok_msg := OkMsg} = Spec,
252253
QName = amqqueue:get_name(Q),
253-
case parse_offset_arg(rabbit_misc:table_lookup(Args, <<"x-stream-offset">>)) of
254+
case parse_offset_arg(
255+
rabbit_misc:table_lookup(Args, <<"x-stream-offset">>)) of
254256
{error, _} = Err ->
255257
Err;
256258
{ok, OffsetSpec} ->
257-
_ = rabbit_stream_coordinator:register_local_member_listener(Q),
258-
rabbit_core_metrics:consumer_created(ChPid, ConsumerTag, ExclusiveConsume,
259-
not NoAck, QName,
260-
ConsumerPrefetchCount, false,
261-
up, Args),
262-
%% FIXME: reply needs to be sent before the stream begins sending
263-
%% really it should be sent by the stream queue process like classic queues
264-
%% do
265-
maybe_send_reply(ChPid, OkMsg),
266259
FilterSpec = filter_spec(Args),
267260
case {FilterSpec, FilteringSupported} of
268261
{#{filter_spec := _}, false} ->
269-
{protocol_error, precondition_failed, "Filtering is not supported", []};
262+
{protocol_error, precondition_failed,
263+
"Filtering is not supported", []};
270264
_ ->
271-
begin_stream(QState0, ConsumerTag, OffsetSpec,
265+
rabbit_core_metrics:consumer_created(ChPid, ConsumerTag,
266+
ExclusiveConsume,
267+
not NoAck, QName,
268+
ConsumerPrefetchCount,
269+
false, up, Args),
270+
%% reply needs to be sent before the stream
271+
%% begins sending
272+
maybe_send_reply(ChPid, OkMsg),
273+
_ = rabbit_stream_coordinator:register_local_member_listener(Q),
274+
begin_stream(QState, ConsumerTag, OffsetSpec,
272275
ConsumerPrefetchCount, FilterSpec)
273276
end
274277
end;
275-
Err ->
276-
Err
278+
{undefined, _} ->
279+
{protocol_error, precondition_failed,
280+
"queue '~ts' does not have a running replica on the local node",
281+
[rabbit_misc:rs(amqqueue:get_name(Q))]}
277282
end.
278283

279284
-spec parse_offset_arg(undefined |
@@ -339,8 +344,7 @@ get_local_pid(#stream_client{local_pid = Pid} = State)
339344
get_local_pid(#stream_client{leader = Pid} = State)
340345
when is_pid(Pid) andalso node(Pid) == node() ->
341346
{Pid, State#stream_client{local_pid = Pid}};
342-
get_local_pid(#stream_client{stream_id = StreamId,
343-
local_pid = undefined} = State) ->
347+
get_local_pid(#stream_client{stream_id = StreamId} = State) ->
344348
%% query local coordinator to get pid
345349
case rabbit_stream_coordinator:local_pid(StreamId) of
346350
{ok, Pid} ->
@@ -349,34 +353,30 @@ get_local_pid(#stream_client{stream_id = StreamId,
349353
{undefined, State}
350354
end.
351355

352-
begin_stream(#stream_client{name = QName, readers = Readers0} = State0,
353-
Tag, Offset, Max, Options) ->
354-
{LocalPid, State} = get_local_pid(State0),
355-
case LocalPid of
356-
undefined ->
357-
{error, no_local_stream_replica_available};
358-
_ ->
359-
CounterSpec = {{?MODULE, QName, Tag, self()}, []},
360-
{ok, Seg0} = osiris:init_reader(LocalPid, Offset, CounterSpec, Options),
361-
NextOffset = osiris_log:next_offset(Seg0) - 1,
362-
osiris:register_offset_listener(LocalPid, NextOffset),
363-
%% TODO: avoid double calls to the same process
364-
StartOffset = case Offset of
365-
first -> NextOffset;
366-
last -> NextOffset;
367-
next -> NextOffset;
368-
{timestamp, _} -> NextOffset;
369-
_ -> Offset
370-
end,
371-
Str0 = #stream{credit = Max,
372-
start_offset = StartOffset,
373-
listening_offset = NextOffset,
374-
log = Seg0,
375-
max = Max,
376-
reader_options = Options},
377-
{ok, State#stream_client{local_pid = LocalPid,
378-
readers = Readers0#{Tag => Str0}}}
379-
end.
356+
begin_stream(#stream_client{name = QName,
357+
readers = Readers0,
358+
local_pid = LocalPid} = State,
359+
Tag, Offset, Max, Options)
360+
when is_pid(LocalPid) ->
361+
CounterSpec = {{?MODULE, QName, Tag, self()}, []},
362+
{ok, Seg0} = osiris:init_reader(LocalPid, Offset, CounterSpec, Options),
363+
NextOffset = osiris_log:next_offset(Seg0) - 1,
364+
osiris:register_offset_listener(LocalPid, NextOffset),
365+
StartOffset = case Offset of
366+
first -> NextOffset;
367+
last -> NextOffset;
368+
next -> NextOffset;
369+
{timestamp, _} -> NextOffset;
370+
_ -> Offset
371+
end,
372+
Str0 = #stream{credit = Max,
373+
start_offset = StartOffset,
374+
listening_offset = NextOffset,
375+
log = Seg0,
376+
max = Max,
377+
reader_options = Options},
378+
{ok, State#stream_client{local_pid = LocalPid,
379+
readers = Readers0#{Tag => Str0}}}.
380380

381381
cancel(_Q, ConsumerTag, OkMsg, ActingUser, #stream_client{readers = Readers0,
382382
name = QName} = State) ->
@@ -396,8 +396,8 @@ cancel(_Q, ConsumerTag, OkMsg, ActingUser, #stream_client{readers = Readers0,
396396
end.
397397

398398
credit(QName, CTag, Credit, Drain, #stream_client{readers = Readers0,
399-
name = Name,
400-
local_pid = LocalPid} = State) ->
399+
name = Name,
400+
local_pid = LocalPid} = State) ->
401401
{Readers1, Msgs} = case Readers0 of
402402
#{CTag := #stream{credit = Credit0} = Str0} ->
403403
Str1 = Str0#stream{credit = Credit0 + Credit},
@@ -411,7 +411,8 @@ credit(QName, CTag, Credit, Drain, #stream_client{readers = Readers0,
411411
true ->
412412
case Readers1 of
413413
#{CTag := #stream{credit = Credit1} = Str2} ->
414-
{Readers0#{CTag => Str2#stream{credit = 0}}, [{send_drained, {CTag, Credit1}}]};
414+
{Readers0#{CTag => Str2#stream{credit = 0}},
415+
[{send_drained, {CTag, Credit1}}]};
415416
_ ->
416417
{Readers1, []}
417418
end;
@@ -444,7 +445,7 @@ deliver0(MsgId, Msg,
444445
soft_limit = SftLmt,
445446
slow = Slow0,
446447
filtering_supported = FilteringSupported} = State,
447-
Actions0) ->
448+
Actions0) ->
448449
ok = osiris:write(LeaderPid, WriterId, Seq,
449450
stream_message(Msg, FilteringSupported)),
450451
Correlation = case MsgId of
@@ -1020,17 +1021,6 @@ stream_name(#resource{virtual_host = VHost, name = Name}) ->
10201021
recover(Q) ->
10211022
{ok, Q}.
10221023

1023-
check_queue_exists_in_local_node(Q) ->
1024-
#{name := StreamId} = amqqueue:get_type_state(Q),
1025-
case rabbit_stream_coordinator:local_pid(StreamId) of
1026-
{ok, Pid} when is_pid(Pid) ->
1027-
ok;
1028-
_ ->
1029-
{protocol_error, precondition_failed,
1030-
"queue '~ts' does not have a replica on the local node",
1031-
[rabbit_misc:rs(amqqueue:get_name(Q))]}
1032-
end.
1033-
10341024
maybe_send_reply(_ChPid, undefined) -> ok;
10351025
maybe_send_reply(ChPid, Msg) -> ok = rabbit_channel:send_command(ChPid, Msg).
10361026

0 commit comments

Comments
 (0)