Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub use utils::expiry::IggyExpiry;
pub use utils::hash::*;
pub use utils::net::validate_api_url;
pub use utils::net::validate_server_address;
pub use utils::non_zero_duration::{NonZeroDurationError, NonZeroIggyDuration};
pub use utils::personal_access_token_expiry::PersonalAccessTokenExpiry;
pub use utils::random_id;
pub use utils::serde_secret;
Expand Down
6 changes: 3 additions & 3 deletions core/common/src/traits/binary_impls/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use crate::traits::binary_auth::fail_if_not_authenticated;
use crate::wire_conversions::clients_from_wire;
use crate::{
BinaryClient, ClientInfo, ClientInfoDetails, IggyDuration, IggyError, OptionSpec, OptionsScope,
Snapshot, SnapshotCompression, Stats, SystemClient, SystemSnapshotType,
BinaryClient, ClientInfo, ClientInfoDetails, IggyError, NonZeroIggyDuration, OptionSpec,
OptionsScope, Snapshot, SnapshotCompression, Stats, SystemClient, SystemSnapshotType,
};
use iggy_binary_protocol::codec::WireEncode;
use iggy_binary_protocol::codes::{
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<B: BinaryClient> SystemClient for B {
Ok(())
}

async fn heartbeat_interval(&self) -> IggyDuration {
async fn heartbeat_interval(&self) -> NonZeroIggyDuration {
self.get_heartbeat_interval()
}

Expand Down
4 changes: 2 additions & 2 deletions core/common/src/traits/binary_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use crate::{ClientState, DiagnosticEvent, IggyDuration, IggyError};
use crate::{ClientState, DiagnosticEvent, IggyError, NonZeroIggyDuration};
use async_trait::async_trait;
use bytes::Bytes;
use std::sync::Arc;
Expand All @@ -28,7 +28,7 @@ pub trait BinaryTransport {
async fn set_state(&self, state: ClientState);
async fn publish_event(&self, event: DiagnosticEvent);
async fn send_raw_with_response(&self, code: u32, payload: Bytes) -> Result<Bytes, IggyError>;
fn get_heartbeat_interval(&self) -> IggyDuration;
fn get_heartbeat_interval(&self) -> NonZeroIggyDuration;

/// Per-transport consumer-group + partitioning cache used to resolve
/// partitioning client-side under VSR (the broker never picks a
Expand Down
6 changes: 3 additions & 3 deletions core/common/src/traits/system_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// under the License.

use crate::{
ClientInfo, ClientInfoDetails, IggyDuration, IggyError, OptionSpec, OptionsScope, Snapshot,
SnapshotCompression, Stats, SystemSnapshotType,
ClientInfo, ClientInfoDetails, IggyError, NonZeroIggyDuration, OptionSpec, OptionsScope,
Snapshot, SnapshotCompression, Stats, SystemSnapshotType,
};
use async_trait::async_trait;

Expand Down Expand Up @@ -49,7 +49,7 @@ pub trait SystemClient {
async fn describe_options(&self, scope: OptionsScope) -> Result<Vec<OptionSpec>, IggyError>;
/// Ping the server to check if it's alive.
async fn ping(&self) -> Result<(), IggyError>;
async fn heartbeat_interval(&self) -> IggyDuration;
async fn heartbeat_interval(&self) -> NonZeroIggyDuration;
/// Re-sync the cached consumer-group assignments from the coordinator.
///
/// Driven off the heartbeat so a member picks up a new generation (e.g. a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl ConnectionStringUtils {
#[cfg(test)]
mod tests {
use super::*;
use crate::IggyDuration;
use crate::NonZeroIggyDuration;
use crate::TcpConnectionStringOptions;
use secrecy::ExposeSecret;

Expand Down Expand Up @@ -255,7 +255,7 @@ mod tests {
assert!(connection_string.options.retries().is_none());
assert_eq!(
connection_string.options.heartbeat_interval(),
IggyDuration::from_str("5s").unwrap()
NonZeroIggyDuration::from_str("5s").unwrap()
);
}

Expand Down Expand Up @@ -289,7 +289,7 @@ mod tests {
assert_eq!(connection_string.options.retries().unwrap(), 3);
assert_eq!(
connection_string.options.heartbeat_interval(),
IggyDuration::from_str("10s").unwrap()
NonZeroIggyDuration::from_str("10s").unwrap()
);
}

Expand Down Expand Up @@ -317,7 +317,7 @@ mod tests {
assert!(connection_string.options.retries().is_none());
assert_eq!(
connection_string.options.heartbeat_interval(),
IggyDuration::from_str("5s").unwrap()
NonZeroIggyDuration::from_str("5s").unwrap()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// specific language governing permissions and limitations
// under the License.

use crate::{IggyDuration, IggyError};
use crate::{IggyError, NonZeroIggyDuration};

pub trait ConnectionStringOptions {
fn retries(&self) -> Option<u32>;

fn heartbeat_interval(&self) -> IggyDuration;
fn heartbeat_interval(&self) -> NonZeroIggyDuration;

fn parse_options(options: &str) -> Result<Self, IggyError>
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// specific language governing permissions and limitations
// under the License.

use crate::{ConnectionStringOptions, IggyDuration, IggyError};
use crate::{ConnectionStringOptions, IggyError, NonZeroIggyDuration};
use std::str::FromStr;

#[derive(Debug)]
pub struct HttpConnectionStringOptions {
heartbeat_interval: IggyDuration,
heartbeat_interval: NonZeroIggyDuration,
retries: u32,
}

Expand All @@ -29,7 +29,7 @@ impl ConnectionStringOptions for HttpConnectionStringOptions {
Some(self.retries)
}

fn heartbeat_interval(&self) -> IggyDuration {
fn heartbeat_interval(&self) -> NonZeroIggyDuration {
self.heartbeat_interval
}

Expand Down Expand Up @@ -58,7 +58,7 @@ impl ConnectionStringOptions for HttpConnectionStringOptions {
}
}

let heartbeat_interval = IggyDuration::from_str(heartbeat_interval.as_str())
let heartbeat_interval = NonZeroIggyDuration::from_str(heartbeat_interval.as_str())
.map_err(|_| IggyError::InvalidConnectionString)?;

let connection_string_options =
Expand All @@ -68,7 +68,7 @@ impl ConnectionStringOptions for HttpConnectionStringOptions {
}

impl HttpConnectionStringOptions {
pub fn new(heartbeat_interval: IggyDuration, retries: u32) -> Self {
pub fn new(heartbeat_interval: NonZeroIggyDuration, retries: u32) -> Self {
Self {
heartbeat_interval,
retries,
Expand All @@ -79,8 +79,30 @@ impl HttpConnectionStringOptions {
impl Default for HttpConnectionStringOptions {
fn default() -> Self {
Self {
heartbeat_interval: IggyDuration::from_str("5s").unwrap(),
heartbeat_interval: NonZeroIggyDuration::from_str("5s").unwrap(),
retries: 3,
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn should_parse_a_heartbeat_interval() {
let options = HttpConnectionStringOptions::parse_options("heartbeat_interval=10s").unwrap();

assert_eq!(
NonZeroIggyDuration::from_str("10s").unwrap(),
options.heartbeat_interval()
);
}

#[test]
fn should_fail_with_a_zero_heartbeat_interval() {
let error = HttpConnectionStringOptions::parse_options("heartbeat_interval=none").err();

assert!(matches!(error, Some(IggyError::InvalidConnectionString)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// under the License.

use crate::{
AutoLogin, ConnectionString, ConnectionStringOptions, IggyDuration,
AutoLogin, ConnectionString, ConnectionStringOptions, NonZeroIggyDuration,
QuicClientReconnectionConfig, QuicConnectionStringOptions,
};
use std::str::FromStr;
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct QuicClientConfig {
/// Whether to validate the server certificate.
pub validate_certificate: bool,
/// Interval of heartbeats sent by the client
pub heartbeat_interval: IggyDuration,
pub heartbeat_interval: NonZeroIggyDuration,
}

impl Default for QuicClientConfig {
Expand All @@ -63,7 +63,7 @@ impl Default for QuicClientConfig {
server_address: "127.0.0.1:8080".to_string(),
server_name: "localhost".to_string(),
auto_login: AutoLogin::Disabled,
heartbeat_interval: IggyDuration::from_str("5s").unwrap(),
heartbeat_interval: NonZeroIggyDuration::from_str("5s").unwrap(),
reconnection: QuicClientReconnectionConfig::default(),
response_buffer_size: 1000 * 1000 * 10,
max_concurrent_bidi_streams: 10000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// specific language governing permissions and limitations
// under the License.

use crate::{AutoLogin, IggyDuration, IggyError, QuicClientConfig, validate_server_address};
use crate::{
AutoLogin, IggyDuration, IggyError, NonZeroIggyDuration, QuicClientConfig,
validate_server_address,
};

/// Builder for the QUIC client configuration.
///
Expand Down Expand Up @@ -81,7 +84,7 @@ impl QuicClientConfigBuilder {
}

/// Sets the interval between retries when connecting to the server.
pub fn with_reconnection_interval(mut self, interval: IggyDuration) -> Self {
pub fn with_reconnection_interval(mut self, interval: NonZeroIggyDuration) -> Self {
self.config.reconnection.interval = interval;
self
}
Expand Down Expand Up @@ -147,7 +150,7 @@ impl QuicClientConfigBuilder {
}

/// Sets the heartbeat interval. Defaults to 5000ms.
pub fn with_heartbeat_interval(mut self, interval: IggyDuration) -> Self {
pub fn with_heartbeat_interval(mut self, interval: NonZeroIggyDuration) -> Self {
self.config.heartbeat_interval = interval;
self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@
// specific language governing permissions and limitations
// under the License.

use crate::IggyDuration;
use crate::{IggyDuration, NonZeroIggyDuration};
use std::str::FromStr;

#[derive(Debug, Clone)]
pub struct QuicClientReconnectionConfig {
pub enabled: bool,
pub max_retries: Option<u32>,
pub interval: IggyDuration,
/// Delay between connection attempts.
pub interval: NonZeroIggyDuration,
pub reestablish_after: IggyDuration,
}

impl QuicClientReconnectionConfig {
pub fn new(
enabled: bool,
max_retries: Option<u32>,
interval: IggyDuration,
interval: NonZeroIggyDuration,
reestablish_after: IggyDuration,
) -> Self {
Self {
Expand All @@ -47,7 +48,7 @@ impl Default for QuicClientReconnectionConfig {
QuicClientReconnectionConfig {
enabled: true,
max_retries: None,
interval: IggyDuration::from_str("1s").unwrap(),
interval: NonZeroIggyDuration::from_str("1s").unwrap(),
reestablish_after: IggyDuration::from_str("5s").unwrap(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// specific language governing permissions and limitations
// under the License.

use crate::{ConnectionStringOptions, IggyDuration, IggyError, QuicClientReconnectionConfig};
use crate::{
ConnectionStringOptions, IggyDuration, IggyError, NonZeroIggyDuration,
QuicClientReconnectionConfig,
};
use std::str::FromStr;

#[derive(Debug)]
Expand All @@ -30,7 +33,7 @@ pub struct QuicConnectionStringOptions {
keep_alive_interval: u64,
max_idle_timeout: u64,
validate_certificate: bool,
heartbeat_interval: IggyDuration,
heartbeat_interval: NonZeroIggyDuration,
}

impl QuicConnectionStringOptions {
Expand Down Expand Up @@ -80,7 +83,7 @@ impl ConnectionStringOptions for QuicConnectionStringOptions {
self.reconnection.max_retries
}

fn heartbeat_interval(&self) -> IggyDuration {
fn heartbeat_interval(&self) -> NonZeroIggyDuration {
self.heartbeat_interval
}

Expand Down Expand Up @@ -203,13 +206,13 @@ impl ConnectionStringOptions for QuicConnectionStringOptions {
.map_err(|_| IggyError::InvalidNumberValue)?,
),
},
interval: IggyDuration::from_str(reconnection_interval.as_str())
interval: NonZeroIggyDuration::from_str(reconnection_interval.as_str())
.map_err(|_| IggyError::InvalidConnectionString)?,
reestablish_after: IggyDuration::from_str(reconnection_reestablish_after.as_str())
.map_err(|_| IggyError::InvalidConnectionString)?,
};

let heartbeat_interval = IggyDuration::from_str(heartbeat_interval.as_str())
let heartbeat_interval = NonZeroIggyDuration::from_str(heartbeat_interval.as_str())
.map_err(|_| IggyError::InvalidConnectionString)?;

let connection_string_options = QuicConnectionStringOptions::new(
Expand Down Expand Up @@ -243,7 +246,7 @@ impl QuicConnectionStringOptions {
keep_alive_interval: u64,
max_idle_timeout: u64,
validate_certificate: bool,
heartbeat_interval: IggyDuration,
heartbeat_interval: NonZeroIggyDuration,
) -> Self {
Self {
reconnection,
Expand Down Expand Up @@ -274,7 +277,7 @@ impl Default for QuicConnectionStringOptions {
keep_alive_interval: 5000,
max_idle_timeout: 10000,
validate_certificate: false,
heartbeat_interval: IggyDuration::from_str("5s").unwrap(),
heartbeat_interval: NonZeroIggyDuration::from_str("5s").unwrap(),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::types::configuration::auth_config::connection_string::ConnectionString;
use crate::types::configuration::auth_config::connection_string_options::ConnectionStringOptions;
use crate::types::configuration::tcp_config::tcp_connection_string_options::TcpConnectionStringOptions;
use crate::{AutoLogin, IggyDuration, TcpClientReconnectionConfig};
use crate::{AutoLogin, NonZeroIggyDuration, TcpClientReconnectionConfig};
use std::str::FromStr;

/// Configuration for the TCP client.
Expand All @@ -40,7 +40,7 @@ pub struct TcpClientConfig {
/// Whether to automatically reconnect when disconnected.
pub reconnection: TcpClientReconnectionConfig,
/// Interval of heartbeats sent by the client
pub heartbeat_interval: IggyDuration,
pub heartbeat_interval: NonZeroIggyDuration,
/// Disable Nagle algorithm for the TCP socket.
pub nodelay: bool,
}
Expand All @@ -53,7 +53,7 @@ impl Default for TcpClientConfig {
tls_domain: "".to_string(),
tls_ca_file: None,
tls_validate_certificate: true,
heartbeat_interval: IggyDuration::from_str("5s").unwrap(),
heartbeat_interval: NonZeroIggyDuration::from_str("5s").unwrap(),
auto_login: AutoLogin::Disabled,
reconnection: TcpClientReconnectionConfig::default(),
nodelay: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// specific language governing permissions and limitations
// under the License.

use crate::{AutoLogin, IggyDuration, IggyError, TcpClientConfig, validate_server_address};
use crate::{
AutoLogin, IggyDuration, IggyError, NonZeroIggyDuration, TcpClientConfig,
validate_server_address,
};

/// Builder for the TCP client configuration.
/// Allows configuring the TCP client with custom settings or using defaults:
Expand Down Expand Up @@ -59,7 +62,7 @@ impl TcpClientConfigBuilder {
}

/// Sets the interval between retries when connecting to the server.
pub fn with_reconnection_interval(mut self, interval: IggyDuration) -> Self {
pub fn with_reconnection_interval(mut self, interval: NonZeroIggyDuration) -> Self {
self.config.reconnection.interval = interval;
self
}
Expand Down
Loading
Loading