Skip to content

re: improve ChannelProviderSettings #47

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

Merged
merged 3 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/hstreamdb/src/channel_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Channels {
}

pub struct ChannelProviderSettings {
pub concurrency_limit: usize,
pub concurrency_limit: Option<usize>,
}

impl ChannelProvider {
Expand All @@ -86,13 +86,12 @@ impl ChannelProvider {
log::warn!("create endpoint error: url = {url}, {err}");
continue;
}
Ok(endpoint) => {
Ok(mut endpoint) => {
let uri = endpoint.uri().clone();
match endpoint
.concurrency_limit(settings.concurrency_limit)
.connect()
.await
{
if let Some(concurrency_limit) = settings.concurrency_limit {
endpoint = endpoint.concurrency_limit(concurrency_limit)
}
match endpoint.connect().await {
Err(err) => {
log::warn!("connect to endpoint error: uri = {uri}, {err}");
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/hstreamdb/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mod tests {
let mut client = Client::new(
addr,
ChannelProviderSettings {
concurrency_limit: 8,
concurrency_limit: None,
},
)
.await
Expand Down Expand Up @@ -273,7 +273,7 @@ mod tests {
let mut client = Client::new(
addr,
ChannelProviderSettings {
concurrency_limit: 8,
concurrency_limit: None,
},
)
.await
Expand Down
6 changes: 3 additions & 3 deletions src/hstreamdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! let mut client = Client::new(
//! env::var("TEST_SERVER_ADDR")?,
//! ChannelProviderSettings {
//! concurrency_limit: 8,
//! concurrency_limit: Some(8),
//! },
//! )
//! .await?;
Expand All @@ -42,7 +42,7 @@
//! size: 4000 * 20,
//! },
//! ChannelProviderSettings {
//! concurrency_limit: 8,
//! concurrency_limit: Some(8),
//! },
//! )
//! .await?;
Expand Down Expand Up @@ -91,7 +91,7 @@
//! let mut client = Client::new(
//! env::var("TEST_SERVER_ADDR")?,
//! ChannelProviderSettings {
//! concurrency_limit: 8,
//! concurrency_limit: Some(8),
//! },
//! )
//! .await?;
Expand Down
4 changes: 2 additions & 2 deletions src/hstreamdb/tests/consumer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn test_consumer() {
let mut client = Client::new(
addr,
ChannelProviderSettings {
concurrency_limit: 8,
concurrency_limit: Some(8),
},
)
.await
Expand Down Expand Up @@ -54,7 +54,7 @@ async fn test_consumer() {
size: usize::MAX,
},
ChannelProviderSettings {
concurrency_limit: 8,
concurrency_limit: Some(8),
},
)
.await
Expand Down
4 changes: 2 additions & 2 deletions src/hstreamdb/tests/producer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn test_producer() {
let mut client = Client::new(
addr,
ChannelProviderSettings {
concurrency_limit: 8,
concurrency_limit: Some(8),
},
)
.await
Expand All @@ -40,7 +40,7 @@ async fn test_producer() {
size: usize::MAX,
},
ChannelProviderSettings {
concurrency_limit: 8,
concurrency_limit: Some(8),
},
)
.await
Expand Down
13 changes: 8 additions & 5 deletions src/x/hstreamdb-erl-nifs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn try_create_stream(
let mut client = Client::new(
url,
ChannelProviderSettings {
concurrency_limit: 1,
concurrency_limit: None,
},
)
.await?;
Expand Down Expand Up @@ -117,7 +117,7 @@ pub fn try_start_producer(
let mut client = Client::new(
url,
ChannelProviderSettings {
concurrency_limit: 1,
concurrency_limit: None,
},
)
.await?;
Expand Down Expand Up @@ -234,7 +234,7 @@ fn atom_to_compression_type(compression_type: Atom) -> Option<CompressionType> {

fn new_producer_settings(
proplists: Term,
) -> hstreamdb::Result<(CompressionType, usize, FlushSettings)> {
) -> hstreamdb::Result<(CompressionType, Option<usize>, FlushSettings)> {
let proplists = proplists
.into_list_iterator()
.map_err(|err| hstreamdb::Error::BadArgument(format!("{err:?}")))?;
Expand All @@ -249,7 +249,10 @@ fn new_producer_settings(
.decode()
.map_err(|err| hstreamdb::Error::BadArgument(format!("{err:?}")))?;
if k == concurrency_limit() {
concurrency_limit_v = v.decode().ok()
concurrency_limit_v = Some(
v.decode()
.map_err(|err| hstreamdb::Error::BadArgument(format!("{err:?}")))?,
);
} else if k == len() {
len_v = v
.decode()
Expand Down Expand Up @@ -278,7 +281,7 @@ fn new_producer_settings(

Ok((
compression_type_v,
concurrency_limit_v.unwrap_or(16),
concurrency_limit_v,
FlushSettings {
len: len_v,
size: size_v,
Expand Down