Skip to content

Commit 3379959

Browse files
committed
refactor: also invalidate broker cache when erroring on "unknown topic/partition"
1 parent 14ae812 commit 3379959

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/client/partition.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -473,39 +473,46 @@ where
473473
Err(e) => e,
474474
};
475475

476-
match error {
476+
let retry = match error {
477477
Error::Request(RequestError::Poisoned(_) | RequestError::IO(_))
478-
| Error::Connection(_) => broker_cache.invalidate().await,
478+
| Error::Connection(_) => {
479+
broker_cache.invalidate().await;
480+
true
481+
}
479482
Error::ServerError {
480483
protocol_error:
481484
ProtocolError::InvalidReplicationFactor
482485
| ProtocolError::LeaderNotAvailable
483486
| ProtocolError::OffsetNotAvailable,
484487
..
485-
} => {}
488+
} => true,
486489
Error::ServerError {
487490
protocol_error: ProtocolError::NotLeaderOrFollower,
488491
..
489492
} => {
490493
broker_cache.invalidate().await;
494+
true
491495
}
492496
Error::ServerError {
493497
protocol_error: ProtocolError::UnknownTopicOrPartition,
494498
..
495-
} if unknown_topic_handling == UnknownTopicHandling::Retry => {
499+
} => {
496500
broker_cache.invalidate().await;
501+
unknown_topic_handling == UnknownTopicHandling::Retry
497502
}
498-
_ => {
499-
error!(
500-
e=%error,
501-
request_name,
502-
"request encountered fatal error",
503-
);
504-
return ControlFlow::Break(Err(error));
505-
}
506-
}
503+
_ => false,
504+
};
507505

508-
ControlFlow::Continue(error)
506+
if retry {
507+
ControlFlow::Continue(error)
508+
} else {
509+
error!(
510+
e=%error,
511+
request_name,
512+
"request encountered fatal error",
513+
);
514+
ControlFlow::Break(Err(error))
515+
}
509516
})
510517
.await
511518
.map_err(Error::RetryFailed)?

0 commit comments

Comments
 (0)