Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to Producer Busy error on reconnect #280

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,11 @@ impl<Exe: Executor> ConnectionSender<Exe> {
producer_id: u64,
producer_name: Option<String>,
options: ProducerOptions,
epoch: u64,
user_provided_producer_name: bool,
) -> Result<proto::CommandProducerSuccess, ConnectionError> {
let request_id = self.request_id.get();
let msg = messages::create_producer(topic, producer_name, producer_id, request_id, options);
let msg = messages::create_producer(topic, producer_name, producer_id, request_id, options, epoch, user_provided_producer_name);
self.send_message(msg, RequestKey::RequestId(request_id), |resp| {
resp.command.producer_success
})
Expand Down Expand Up @@ -1227,6 +1229,8 @@ pub(crate) mod messages {
producer_id: u64,
request_id: u64,
options: ProducerOptions,
epoch: u64,
user_provided_producer_name: bool,
) -> Message {
Message {
command: proto::BaseCommand {
Expand All @@ -1235,6 +1239,7 @@ pub(crate) mod messages {
topic,
producer_id,
request_id,
user_provided_producer_name: Some(user_provided_producer_name),
producer_name,
encrypted: options.encrypted,
metadata: options
Expand All @@ -1247,6 +1252,7 @@ pub(crate) mod messages {
.collect(),
schema: options.schema,
producer_access_mode: options.access_mode,
epoch: Some(epoch),
..Default::default()
}),
..Default::default()
Expand Down
10 changes: 10 additions & 0 deletions src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ struct TopicProducer<Exe: Executor> {
batch: Option<Mutex<Batch>>,
compression: Option<Compression>,
options: ProducerOptions,
epoch: std::sync::atomic::AtomicU64,
user_provided_producer_name: bool,
}

impl<Exe: Executor> TopicProducer<Exe> {
Expand All @@ -455,6 +457,8 @@ impl<Exe: Executor> TopicProducer<Exe> {
let batch_byte_size = options.batch_byte_size;
let compression = options.compression.clone();
let mut connection = client.manager.get_connection(&addr).await?;
let epoch = std::sync::atomic::AtomicU64::new(0);
let user_provided_producer_name = name.is_some();

let producer_name = retry_create_producer(
&client,
Expand All @@ -464,6 +468,8 @@ impl<Exe: Executor> TopicProducer<Exe> {
producer_id,
name,
&options,
&epoch,
user_provided_producer_name,
)
.await?;

Expand All @@ -481,6 +487,8 @@ impl<Exe: Executor> TopicProducer<Exe> {
batch,
compression,
options,
epoch,
user_provided_producer_name,
})
}

Expand Down Expand Up @@ -727,6 +735,8 @@ impl<Exe: Executor> TopicProducer<Exe> {
self.id,
Some(self.name.clone()),
&self.options,
&self.epoch,
self.user_provided_producer_name,
)
.await?;

Expand Down
4 changes: 4 additions & 0 deletions src/retry_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ pub async fn retry_create_producer<Exe: Executor>(
producer_id: u64,
producer_name: Option<String>,
options: &ProducerOptions,
epoch: &std::sync::atomic::AtomicU64,
user_provided_producer_name: bool,
) -> Result<String, Error> {
*connection = client.manager.get_connection(&addr).await?;
let mut current_retries = 0u32;
Expand All @@ -174,6 +176,8 @@ pub async fn retry_create_producer<Exe: Executor>(
producer_id,
producer_name.clone(),
options.clone(),
epoch.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
user_provided_producer_name
)
.await
{
Expand Down