Skip to content

Commit 29d9030

Browse files
authored
chore: produce config builder as mutable (#4375)
* chore: produce config cloneable * chore: remove linger 10 when interactive mode
1 parent 8f6a1cf commit 29d9030

File tree

7 files changed

+61
-96
lines changed

7 files changed

+61
-96
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ k8-diff = { version = "0.1.2" }
173173
trybuild = { branch = "check_option", git = "https://github.com/infinyon/trybuild" }
174174

175175
# Internal fluvio dependencies
176-
fluvio = { version = "0.24.0", path = "crates/fluvio" }
176+
fluvio = { version = "0.25.0", path = "crates/fluvio" }
177177
fluvio-auth = { path = "crates/fluvio-auth" }
178178
fluvio-benchmark = { path = "crates/fluvio-benchmark" }
179179
fluvio-channel = { path = "crates/fluvio-channel" }

crates/fluvio-cli/src/client/produce/mod.rs

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -199,47 +199,27 @@ mod cmd {
199199
fluvio: &Fluvio,
200200
) -> Result<()> {
201201
init_monitoring(fluvio.metrics());
202-
let config_builder = if self.interactive_mode() {
203-
TopicProducerConfigBuilder::default().linger(std::time::Duration::from_millis(10))
204-
} else {
205-
Default::default()
206-
};
207-
202+
let mut config_builder = TopicProducerConfigBuilder::default();
208203
// Compression
209-
let config_builder = if let Some(compression) = self.compression {
210-
config_builder.compression(compression)
211-
} else {
212-
config_builder
213-
};
214-
204+
if let Some(compression) = self.compression {
205+
config_builder.compression(compression);
206+
}
215207
// Linger
216-
let config_builder = if let Some(linger) = self.linger {
217-
config_builder.linger(linger)
218-
} else {
219-
config_builder
220-
};
221-
208+
if let Some(linger) = self.linger {
209+
config_builder.linger(linger);
210+
}
222211
// Batch size
223-
let config_builder = if let Some(batch_size) = self.batch_size {
224-
config_builder.batch_size(batch_size)
225-
} else {
226-
config_builder
227-
};
228-
212+
if let Some(batch_size) = self.batch_size {
213+
config_builder.batch_size(batch_size);
214+
}
229215
// Max request size
230-
let config_builder = if let Some(max_request_size) = self.max_request_size {
231-
config_builder.max_request_size(max_request_size)
232-
} else {
233-
config_builder
234-
};
235-
216+
if let Some(max_request_size) = self.max_request_size {
217+
config_builder.max_request_size(max_request_size);
218+
}
236219
// Isolation
237-
let config_builder = if let Some(isolation) = self.isolation {
238-
config_builder.isolation(isolation)
239-
} else {
240-
config_builder
241-
};
242-
220+
if let Some(isolation) = self.isolation {
221+
config_builder.isolation(isolation);
222+
}
243223
// Delivery Semantic
244224
if self.delivery_semantic == DeliverySemantic::AtMostOnce && self.isolation.is_some() {
245225
warn!("Isolation is ignored for AtMostOnce delivery semantic");

crates/fluvio-connector-common/src/producer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub async fn producer_from_config(config: &ConnectorConfig) -> Result<(Fluvio, T
99

1010
let fluvio = Fluvio::connect_with_config(&cluster_config).await?;
1111
ensure_topic_exists(config).await?;
12-
let mut config_builder = TopicProducerConfigBuilder::default();
12+
let mut config_builder = &mut TopicProducerConfigBuilder::default();
1313

1414
if let Some(producer_params) = &config.meta().producer() {
1515
// Linger

crates/fluvio-test/src/tests/data_generator/producer.rs

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,6 @@ pub async fn producer(
3333
let mut producers = Vec::new();
3434

3535
for topic_id in 0..option.environment.topic {
36-
let maybe_builder = match (
37-
option.environment.producer_linger,
38-
option.environment.producer_batch_size,
39-
option.environment.producer_compression,
40-
) {
41-
(Some(linger), Some(batch), Some(compression)) => Some(
42-
TopicProducerConfigBuilder::default()
43-
.linger(Duration::from_millis(linger))
44-
.batch_size(batch)
45-
.compression(compression),
46-
),
47-
(Some(linger), Some(batch), None) => Some(
48-
TopicProducerConfigBuilder::default()
49-
.linger(Duration::from_millis(linger))
50-
.batch_size(batch),
51-
),
52-
(Some(linger), None, None) => {
53-
Some(TopicProducerConfigBuilder::default().linger(Duration::from_millis(linger)))
54-
}
55-
(Some(linger), None, Some(compression)) => Some(
56-
TopicProducerConfigBuilder::default()
57-
.linger(Duration::from_millis(linger))
58-
.compression(compression),
59-
),
60-
(None, Some(batch), Some(compression)) => Some(
61-
TopicProducerConfigBuilder::default()
62-
.batch_size(batch)
63-
.compression(compression),
64-
),
65-
66-
(None, Some(batch), None) => {
67-
Some(TopicProducerConfigBuilder::default().batch_size(batch))
68-
}
69-
(None, None, Some(compression)) => {
70-
Some(TopicProducerConfigBuilder::default().compression(compression))
71-
}
72-
73-
(None, None, None) => None,
74-
};
75-
7636
let env_opts = option.environment.clone();
7737

7838
let test_topic_name = if env_opts.topic > 1 {
@@ -81,16 +41,41 @@ pub async fn producer(
8141
env_opts.base_topic_name()
8242
};
8343

84-
if let Some(producer_config) = maybe_builder {
85-
let config = producer_config.build().expect("producer builder");
86-
producers.push(
87-
test_driver
88-
.create_producer_with_config(&test_topic_name, config)
89-
.await,
90-
)
91-
} else {
92-
producers.push(test_driver.create_producer(&test_topic_name).await)
44+
let mut builder = TopicProducerConfigBuilder::default();
45+
match (
46+
option.environment.producer_linger,
47+
option.environment.producer_batch_size,
48+
option.environment.producer_compression,
49+
) {
50+
(Some(linger), Some(batch), Some(compression)) => builder
51+
.linger(Duration::from_millis(linger))
52+
.batch_size(batch)
53+
.compression(compression),
54+
(Some(linger), Some(batch), None) => builder
55+
.linger(Duration::from_millis(linger))
56+
.batch_size(batch),
57+
(Some(linger), None, None) => builder.linger(Duration::from_millis(linger)),
58+
(Some(linger), None, Some(compression)) => builder
59+
.linger(Duration::from_millis(linger))
60+
.compression(compression),
61+
(None, Some(batch), Some(compression)) => {
62+
builder.batch_size(batch).compression(compression)
63+
}
64+
65+
(None, Some(batch), None) => builder.batch_size(batch),
66+
(None, None, Some(compression)) => builder.compression(compression),
67+
(None, None, None) => {
68+
producers.push(test_driver.create_producer(&test_topic_name).await);
69+
continue;
70+
}
9371
};
72+
73+
let config = builder.build().expect("producer builder");
74+
producers.push(
75+
test_driver
76+
.create_producer_with_config(&test_topic_name, config)
77+
.await,
78+
)
9479
}
9580

9681
// Create the syncing producer/consumer

crates/fluvio/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fluvio"
3-
version = "0.24.5"
3+
version = "0.25.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
authors = ["Fluvio Contributors <team@fluvio.io>"]

crates/fluvio/src/producer/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fmt::{self, Debug, Display, Formatter};
22
use std::str::FromStr;
3+
use std::sync::Arc;
34
use std::time::Duration;
45

56
use derive_builder::Builder;
@@ -44,8 +45,8 @@ fn default_linger_duration() -> Duration {
4445
Duration::from_millis(DEFAULT_LINGER_MS)
4546
}
4647

47-
fn default_partitioner() -> Box<dyn Partitioner + Send + Sync> {
48-
Box::new(SiphashRoundRobinPartitioner::new())
48+
fn default_partitioner() -> Arc<dyn Partitioner + Send + Sync> {
49+
Arc::new(SiphashRoundRobinPartitioner::new())
4950
}
5051

5152
fn default_timeout() -> Duration {
@@ -71,8 +72,7 @@ impl fmt::Debug for Box<dyn Partitioner + Send + Sync> {
7172
/// Create this struct with [`TopicProducerConfigBuilder`].
7273
///
7374
/// Create a producer with a custom config with [`crate::Fluvio::topic_producer_with_config()`].
74-
#[derive(Builder)]
75-
#[builder(pattern = "owned")]
75+
#[derive(Builder, Clone)]
7676
pub struct TopicProducerConfig {
7777
/// Maximum amount of bytes accumulated by the records before sending the batch.
7878
#[builder(default = "default_batch_size()")]
@@ -88,7 +88,7 @@ pub struct TopicProducerConfig {
8888
pub(crate) linger: Duration,
8989
/// Partitioner assigns the partition to each record that needs to be send
9090
#[builder(default = "default_partitioner()")]
91-
pub(crate) partitioner: Box<dyn Partitioner + Send + Sync>,
91+
pub(crate) partitioner: Arc<dyn Partitioner + Send + Sync>,
9292

9393
/// Compression algorithm used by Fluvio producer to compress data.
9494
/// If there is a topic level compression and it is not compatible with this setting, the producer
@@ -125,8 +125,8 @@ pub struct TopicProducerConfig {
125125
}
126126

127127
impl TopicProducerConfigBuilder {
128-
pub fn set_specific_partitioner(self, partition_id: PartitionId) -> Self {
129-
self.partitioner(Box::new(SpecificPartitioner::new(partition_id)))
128+
pub fn set_specific_partitioner(&mut self, partition_id: PartitionId) -> &mut Self {
129+
self.partitioner(Arc::new(SpecificPartitioner::new(partition_id)))
130130
}
131131
}
132132

0 commit comments

Comments
 (0)