Current section

113 Versions

Jump to

Compare versions

4 files changed
+20 additions
-9 deletions
  @@ -1,6 +1,6 @@
1 1 PROJECT = brod
2 2 PROJECT_DESCRIPTION = Kafka client library in Erlang
3 - PROJECT_VERSION = 2.2.11
3 + PROJECT_VERSION = 2.2.12
4 4
5 5 DEPS = supervisor3 kafka_protocol
  @@ -1,5 +1,5 @@
1 1 {<<"name">>,<<"brod">>}.
2 - {<<"version">>,<<"2.2.11">>}.
2 + {<<"version">>,<<"2.2.12">>}.
3 3 {<<"requirements">>,
4 4 #{<<"kafka_protocol">> => #{<<"app">> => <<"kafka_protocol">>,
5 5 <<"optional">> => false,
  @@ -1,6 +1,6 @@
1 1 {application,brod,
2 2 [{description,"Apache Kafka Erlang client library"},
3 - {vsn,"2.2.11"},
3 + {vsn,"2.2.12"},
4 4 {registered,[]},
5 5 {applications,[kernel,stdlib,ssl,kafka_protocol,supervisor3]},
6 6 {env,[]},
  @@ -65,7 +65,7 @@
65 65 , max_bytes_orig :: bytes()
66 66 , sleep_timeout :: integer()
67 67 , prefetch_count :: integer()
68 - , last_corr_id :: corr_id()
68 + , last_corr_id :: ?undef | corr_id()
69 69 , subscriber :: ?undef | pid()
70 70 , subscriber_mref :: ?undef | reference()
71 71 , pending_acks = [] :: [offset()]
  @@ -293,16 +293,18 @@ do_debug(Pid, Debug) ->
293 293 ok.
294 294
295 295 handle_fetch_response(_Response, _CorrId,
296 - #state{subscriber = ?undef} = State) ->
296 + #state{subscriber = ?undef} = State0) ->
297 297 %% discard fetch response when there is no (dead?) subscriber
298 + State = State0#state{last_corr_id = ?undef},
298 299 {noreply, State};
299 300 handle_fetch_response(_Response, CorrId1,
300 301 #state{ last_corr_id = CorrId2
301 302 } = State) when CorrId1 =/= CorrId2 ->
302 303 {noreply, State};
303 304 handle_fetch_response(#kpro_FetchResponse{ fetchResponseTopic_L = [TopicData]
304 - }, CorrId, State) ->
305 - CorrId = State#state.last_corr_id, %% assert
305 + }, CorrId, State0) ->
306 + CorrId = State0#state.last_corr_id, %% assert
307 + State = State0#state{last_corr_id = ?undef},
306 308 #kpro_FetchResponseTopic{ topicName = Topic
307 309 , fetchResponsePartition_L = [PartitionResponse]
308 310 } = TopicData,
  @@ -478,6 +480,9 @@ maybe_send_fetch_request(#state{socket_pid = ?undef} = State) ->
478 480 maybe_send_fetch_request(#state{is_suspended = true} = State) ->
479 481 %% waiting for subscriber to re-subscribe
480 482 State;
483 + maybe_send_fetch_request(#state{last_corr_id = I} = State) when is_integer(I) ->
484 + %% Waiting for the last request
485 + State;
481 486 maybe_send_fetch_request(#state{ pending_acks = PendingAcks
482 487 , prefetch_count = PrefetchCount
483 488 } = State) ->
  @@ -575,13 +580,15 @@ fetch_valid_offset(SocketPid, BeginOffset, Topic, Partition) ->
575 580
576 581 %% @private Reset fetch buffer, use the last unacked offset as the next begin
577 582 %% offset to fetch data from.
583 + %% Discard onwire fetch responses by setting last_corr_id to undefined.
578 584 %% @end
579 585 -spec reset_buffer(#state{}) -> #state{}.
580 586 reset_buffer(#state{pending_acks = []} = State) ->
581 - State;
587 + State#state{last_corr_id = ?undef};
582 588 reset_buffer(#state{pending_acks = [Offset | _]} = State) ->
583 589 State#state{ begin_offset = Offset
584 590 , pending_acks = []
591 + , last_corr_id = ?undef
585 592 }.
586 593
587 594 %% @private Catch noproc exit exception when making gen_server:call.
  @@ -608,7 +615,11 @@ maybe_init_socket(#state{ client_pid = ClientPid
608 615 case brod_client:get_leader_connection(ClientPid, Topic, Partition) of
609 616 {ok, SocketPid} ->
610 617 _ = erlang:monitor(process, SocketPid),
611 - State = State0#state{socket_pid = SocketPid},
618 + %% Switching to a new socket
619 + %% the response for last_coor_id will be lost forever
620 + State = State0#state{ last_corr_id = ?undef
621 + , socket_pid = SocketPid
622 + },
612 623 {ok, State};
613 624 {error, Reason} ->
614 625 {{error, Reason}, State0}