diff --git a/glide-core/redis-rs/redis/src/client.rs b/glide-core/redis-rs/redis/src/client.rs index bd32ad67fc..2b97671110 100644 --- a/glide-core/redis-rs/redis/src/client.rs +++ b/glide-core/redis-rs/redis/src/client.rs @@ -92,7 +92,7 @@ pub struct GlideConnectionOptions { /// Connection timeout duration. /// /// This optional field sets the maximum duration to wait when attempting to establish - /// a connection. If `None`, the connection will use a default timeout. + /// a connection. If `None`, the connection will use `DEFAULT_CONNECTION_TIMEOUT`. pub connection_timeout: Option, } diff --git a/glide-core/src/client/mod.rs b/glide-core/src/client/mod.rs index bab2110e39..6e329d2f9c 100644 --- a/glide-core/src/client/mod.rs +++ b/glide-core/src/client/mod.rs @@ -29,9 +29,11 @@ use tokio::sync::mpsc; pub const HEARTBEAT_SLEEP_DURATION: Duration = Duration::from_secs(1); pub const DEFAULT_RETRIES: u32 = 3; +/// Note: If you change the default value, make sure to change the documentation in *all* wrappers. pub const DEFAULT_RESPONSE_TIMEOUT: Duration = Duration::from_millis(250); pub const DEFAULT_CONNECTION_ATTEMPT_TIMEOUT: Duration = Duration::from_millis(250); pub const DEFAULT_PERIODIC_TOPOLOGY_CHECKS_INTERVAL: Duration = Duration::from_secs(60); +/// Note: If you change the default value, make sure to change the documentation in *all* wrappers. pub const DEFAULT_CONNECTION_TIMEOUT: Duration = Duration::from_millis(250); pub const FINISHED_SCAN_CURSOR: &str = "finished"; diff --git a/java/client/src/main/java/glide/api/models/configuration/AdvancedBaseClientConfiguration.java b/java/client/src/main/java/glide/api/models/configuration/AdvancedBaseClientConfiguration.java index ced294fdd4..3f0649115f 100644 --- a/java/client/src/main/java/glide/api/models/configuration/AdvancedBaseClientConfiguration.java +++ b/java/client/src/main/java/glide/api/models/configuration/AdvancedBaseClientConfiguration.java @@ -4,14 +4,23 @@ import lombok.Getter; import lombok.experimental.SuperBuilder; +/** + * Advanced configuration settings class for creating a client. Shared settings for standalone and + * cluster clients. + */ @Getter @SuperBuilder public abstract class AdvancedBaseClientConfiguration { /** - * The duration in milliseconds that the client will wait for a connection to be established. If - * the connection attempt does not complete within this time frame, a connection timeout error - * will occur. If not set, a default value will be used. + * The duration in milliseconds that the client will wait for a connection to be established. + * + *

This timeout applies both during initial client creation and any reconnections that may + * occur during request processing. A high connection timeout may lead to prolonged blocking of + * the entire command pipeline. If the client cannot establish a connection within the specified + * duration, a timeout error will occur. + * + *

If not explicitly set, a default value of 250 milliseconds will be used. */ private final Integer connectionTimeout; } diff --git a/java/client/src/main/java/glide/api/models/configuration/AdvancedGlideClientConfiguration.java b/java/client/src/main/java/glide/api/models/configuration/AdvancedGlideClientConfiguration.java index 1281fa692a..b561aa0118 100644 --- a/java/client/src/main/java/glide/api/models/configuration/AdvancedGlideClientConfiguration.java +++ b/java/client/src/main/java/glide/api/models/configuration/AdvancedGlideClientConfiguration.java @@ -1,10 +1,23 @@ /** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api.models.configuration; +import glide.api.GlideClient; import lombok.Getter; import lombok.ToString; import lombok.experimental.SuperBuilder; +/** + * Represents advanced configuration settings for a Standalone {@link GlideClient} used in {@link + * GlideClientConfiguration}. + * + *

Example Usage: + * + *

{@code
+ * AdvancedGlideClientConfiguration config = AdvancedGlideClientConfiguration.builder()
+ *     .connectionTimeout(500)
+ *     .build();
+ * }
+ */ @Getter @SuperBuilder @ToString diff --git a/java/client/src/main/java/glide/api/models/configuration/AdvancedGlideClusterClientConfiguration.java b/java/client/src/main/java/glide/api/models/configuration/AdvancedGlideClusterClientConfiguration.java index 9d7748b271..8fa7a4b1f0 100644 --- a/java/client/src/main/java/glide/api/models/configuration/AdvancedGlideClusterClientConfiguration.java +++ b/java/client/src/main/java/glide/api/models/configuration/AdvancedGlideClusterClientConfiguration.java @@ -1,10 +1,23 @@ /** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api.models.configuration; +import glide.api.GlideClusterClient; import lombok.Getter; import lombok.ToString; import lombok.experimental.SuperBuilder; +/** + * Represents advanced configuration settings for a Standalone {@link GlideClusterClient} used in + * {@link GlideClusterClientConfiguration}. + * + *

Example Usage: + * + *

{@code
+ * AdvancedGlideClusterClientConfiguration config = AdvancedGlideClusterClientConfiguration.builder()
+ *     .connectionTimeout(500)
+ *     .build();
+ * }
+ */ @Getter @SuperBuilder @ToString diff --git a/java/client/src/main/java/glide/api/models/configuration/BaseClientConfiguration.java b/java/client/src/main/java/glide/api/models/configuration/BaseClientConfiguration.java index 7d9d5d5b68..7cd29a7cb8 100644 --- a/java/client/src/main/java/glide/api/models/configuration/BaseClientConfiguration.java +++ b/java/client/src/main/java/glide/api/models/configuration/BaseClientConfiguration.java @@ -49,7 +49,8 @@ public abstract class BaseClientConfiguration { * The duration in milliseconds that the client should wait for a request to complete. This * duration encompasses sending the request, awaiting for a response from the server, and any * required reconnections or retries. If the specified timeout is exceeded for a pending request, - * it will result in a timeout error. If not set, a default value will be used. + * it will result in a timeout error. If not explicitly set, a default value of 250 milliseconds + * will be used. */ private final Integer requestTimeout; diff --git a/java/client/src/main/java/glide/api/models/configuration/GlideClientConfiguration.java b/java/client/src/main/java/glide/api/models/configuration/GlideClientConfiguration.java index 8f04c6b680..4321f1dd39 100644 --- a/java/client/src/main/java/glide/api/models/configuration/GlideClientConfiguration.java +++ b/java/client/src/main/java/glide/api/models/configuration/GlideClientConfiguration.java @@ -24,6 +24,7 @@ * .clientName("GLIDE") * .subscriptionConfiguration(subscriptionConfiguration) * .inflightRequestsLimit(1000) + * .advancedConfiguration(AdvancedGlideClientConfiguration.builder().connectionTimeout(500).build()) * .build(); * } */ @@ -40,6 +41,6 @@ public class GlideClientConfiguration extends BaseClientConfiguration { /** Subscription configuration for the current client. */ private final StandaloneSubscriptionConfiguration subscriptionConfiguration; - /** */ + /** Advanced configuration settings for the client. */ private final AdvancedGlideClientConfiguration advancedConfiguration; } diff --git a/java/client/src/main/java/glide/api/models/configuration/GlideClusterClientConfiguration.java b/java/client/src/main/java/glide/api/models/configuration/GlideClusterClientConfiguration.java index 937a8a4ea3..f0b6d7789d 100644 --- a/java/client/src/main/java/glide/api/models/configuration/GlideClusterClientConfiguration.java +++ b/java/client/src/main/java/glide/api/models/configuration/GlideClusterClientConfiguration.java @@ -23,6 +23,7 @@ * .clientName("GLIDE") * .subscriptionConfiguration(subscriptionConfiguration) * .inflightRequestsLimit(1000) + * .advancedConfiguration(AdvancedGlideClusterClientConfiguration.builder().connectionTimeout(500).build()) * .build(); * } */ @@ -33,6 +34,6 @@ public class GlideClusterClientConfiguration extends BaseClientConfiguration { /** Subscription configuration for the current client. */ private final ClusterSubscriptionConfiguration subscriptionConfiguration; - /** */ + /** Advanced configuration settings for the client. */ private final AdvancedGlideClusterClientConfiguration advancedConfiguration; } diff --git a/java/client/src/main/java/glide/managers/ConnectionManager.java b/java/client/src/main/java/glide/managers/ConnectionManager.java index f520a86f86..443384d5a6 100644 --- a/java/client/src/main/java/glide/managers/ConnectionManager.java +++ b/java/client/src/main/java/glide/managers/ConnectionManager.java @@ -70,8 +70,7 @@ private Response exceptionHandler(Throwable e) { * @param configuration Connection Request Configuration * @return ConnectionRequest protobuf message */ - private ConnectionRequest createConnectionRequest( - BaseClientConfiguration configuration) { // shoham + private ConnectionRequest createConnectionRequest(BaseClientConfiguration configuration) { if (configuration instanceof GlideClusterClientConfiguration) { return setupConnectionRequestBuilderGlideClusterClient( (GlideClusterClientConfiguration) configuration) @@ -182,6 +181,14 @@ private ConnectionRequest.Builder setupConnectionRequestBuilderGlideClient( return connectionRequestBuilder; } + /** + * Configures the {@link ConnectionRequest.Builder} with settings from the provided {@link + * AdvancedBaseClientConfiguration}. + * + * @param connectionRequestBuilder The builder for the {@link ConnectionRequest}. + * @param configuration The advanced configuration settings. + * @return The updated {@link ConnectionRequest.Builder}. + */ private ConnectionRequest.Builder setupConnectionRequestBuilderAdvancedBaseConfiguration( ConnectionRequest.Builder connectionRequestBuilder, AdvancedBaseClientConfiguration configuration) { diff --git a/node/rust-client/src/lib.rs b/node/rust-client/src/lib.rs index b15b18f521..ffa5b5c47f 100644 --- a/node/rust-client/src/lib.rs +++ b/node/rust-client/src/lib.rs @@ -1,8 +1,7 @@ +// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 + use glide_core::Telemetry; use redis::GlideConnectionOptions; -/** - * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 - */ #[cfg(not(target_env = "msvc"))] use tikv_jemallocator::Jemalloc; @@ -41,9 +40,13 @@ pub enum Level { pub const MAX_REQUEST_ARGS_LEN: u32 = MAX_REQUEST_ARGS_LENGTH as u32; #[napi] -pub const DEFAULT_TIMEOUT_IN_MILLISECONDS: u32 = +pub const DEFAULT_REQUEST_TIMEOUT_IN_MILLISECONDS: u32 = glide_core::client::DEFAULT_RESPONSE_TIMEOUT.as_millis() as u32; +#[napi] +pub const DEFAULT_CONNECTION_TIMEOUT_IN_MILLISECONDS: u32 = + glide_core::client::DEFAULT_CONNECTION_TIMEOUT.as_millis() as u32; + #[napi] pub const DEFAULT_INFLIGHT_REQUESTS_LIMIT: u32 = glide_core::client::DEFAULT_MAX_INFLIGHT_REQUESTS; diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 46048a8e48..f84ccf7f69 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -3,8 +3,9 @@ */ import { ClusterScanCursor, + DEFAULT_CONNECTION_TIMEOUT_IN_MILLISECONDS, DEFAULT_INFLIGHT_REQUESTS_LIMIT, - DEFAULT_TIMEOUT_IN_MILLISECONDS, + DEFAULT_REQUEST_TIMEOUT_IN_MILLISECONDS, Script, StartSocketConnection, getStatistics, @@ -606,7 +607,7 @@ export interface BaseClientConfiguration { * The duration in milliseconds that the client should wait for a request to complete. * This duration encompasses sending the request, awaiting for a response from the server, and any required reconnections or retries. * If the specified timeout is exceeded for a pending request, it will result in a timeout error. - * If not set, a default value will be used. + * If not explicitly set, a default value of 250 milliseconds will be used. * Value must be an integer. */ requestTimeout?: number; @@ -650,7 +651,33 @@ export interface BaseClientConfiguration { clientAz?: string; } +/** + * Represents advanced configuration settings for a client, including connection-related options. + * + * @remarks + * The `AdvancedBaseClientConfiguration` interface defines advanced configuration settings for managing the client's connection behavior. + * + * ### Connection Timeout + * + * - **Connection Timeout**: The `connectionTimeout` property specifies the duration (in milliseconds) the client should wait for a connection to be established. If the connection is not successful within the specified time, a timeout error will occur. + * + * @example + * ```typescript + * const config: AdvancedBaseClientConfiguration = { + * connectionTimeout: 5000, // 5 seconds + * }; + * ``` + */ export interface AdvancedBaseClientConfiguration { + /** + * The duration in milliseconds that the client will wait for a connection to be established. + * + * This timeout applies both during initial client creation and any reconnections that + * may occur during request processing. A high connection timeout may lead to prolonged + * blocking of the entire command pipeline. If the client cannot establish a connection + * within the specified duration, a timeout error will occur. + * If not explicitly set, a default value of 250 milliseconds will be used. + */ connectionTimeout?: number; } @@ -955,7 +982,7 @@ export class BaseClient { Logger.log("info", "Client lifetime", `construct client`); this.config = options; this.requestTimeout = - options?.requestTimeout ?? DEFAULT_TIMEOUT_IN_MILLISECONDS; + options?.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_IN_MILLISECONDS; this.socket = socket; this.socket .on("data", (data) => this.handleReadData(data)) @@ -7661,11 +7688,16 @@ export class BaseClient { }; } + /** + * @internal + */ protected configureAdvancedConfigurationBase( request: connection_request.IConnectionRequest, options?: AdvancedBaseClientConfiguration, ) { - request.connectionTimeout = options?.connectionTimeout; + request.connectionTimeout = + options?.connectionTimeout ?? + DEFAULT_CONNECTION_TIMEOUT_IN_MILLISECONDS; } /** diff --git a/node/src/GlideClient.ts b/node/src/GlideClient.ts index c333a8a0c4..58b9e122a1 100644 --- a/node/src/GlideClient.ts +++ b/node/src/GlideClient.ts @@ -172,9 +172,23 @@ export type GlideClientConfiguration = BaseClientConfiguration & { * Will be applied via SUBSCRIBE/PSUBSCRIBE commands during connection establishment. */ pubsubSubscriptions?: GlideClientConfiguration.PubSubSubscriptions; + /** + * Advanced configuration settings for the client. + */ advancedConfiguration?: AdvancedGlideClientConfiguration; }; +/** + * Represents advanced configuration settings for creating a {@link GlideClient | GlideClient} used in {@link GlideClientConfiguration | GlideClientConfiguration}. + * + * + * @example + * ```typescript + * const config: AdvancedGlideClientConfiguration = { + * connectionTimeout: 500, // Set the connection timeout to 500ms + * }; + * ``` + */ export type AdvancedGlideClientConfiguration = AdvancedBaseClientConfiguration & {}; diff --git a/node/src/GlideClusterClient.ts b/node/src/GlideClusterClient.ts index 807361a3e4..5b76e99901 100644 --- a/node/src/GlideClusterClient.ts +++ b/node/src/GlideClusterClient.ts @@ -191,10 +191,23 @@ export type GlideClusterClientConfiguration = BaseClientConfiguration & { * Will be applied via SUBSCRIBE/PSUBSCRIBE/SSUBSCRIBE commands during connection establishment. */ pubsubSubscriptions?: GlideClusterClientConfiguration.PubSubSubscriptions; - + /** + * Advanced configuration settings for the client. + */ advancedConfiguration?: AdvancedGlideClusterClientConfiguration; }; +/** + * Represents advanced configuration settings for creating a {@link GlideClusterClient | GlideClusterClient} used in {@link GlideClusterClientConfiguration | GlideClusterClientConfiguration}. + * + * + * @example + * ```typescript + * const config: AdvancedGlideClusterClientConfiguration = { + * connectionTimeout: 500, // Set the connection timeout to 500ms + * }; + * ``` + */ export type AdvancedGlideClusterClientConfiguration = AdvancedBaseClientConfiguration & {}; @@ -564,7 +577,6 @@ export class GlideClusterClient extends BaseClient { public static async createClient( options: GlideClusterClientConfiguration, ): Promise { - console.log("options are: ", options); return await super.createClientInternal( options, (socket: net.Socket, options?: GlideClusterClientConfiguration) => diff --git a/python/python/glide/config.py b/python/python/glide/config.py index d519bbcd52..384e4dc464 100644 --- a/python/python/glide/config.py +++ b/python/python/glide/config.py @@ -138,10 +138,11 @@ class AdvancedBaseClientConfiguration: This applies both during initial client creation and any reconnections that may occur during request processing. **Note**: A high connection timeout may lead to prolonged blocking of the entire command pipeline. If the client cannot establish a connection within the specified duration, a timeout error will occur. - If not set, a default value will be used. + If not explicitly set, a default value of 250 milliseconds will be used. """ def __init__(self, connection_timeout: Optional[int] = None): + self.connection_timeout = connection_timeout def _create_a_protobuf_conn_request( @@ -187,13 +188,14 @@ def __init__( read_from (ReadFrom): If not set, `PRIMARY` will be used. request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to complete. This duration encompasses sending the request, awaiting for a response from the server, and any required reconnections or retries. - If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not set, a default value will be used. + If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not explicitly set, a default value of 250 milliseconds will be used. client_name (Optional[str]): Client name to be used for the client. Will be used with CLIENT SETNAME command during connection establishment. inflight_requests_limit (Optional[int]): The maximum number of concurrent requests allowed to be in-flight (sent but not yet completed). This limit is used to control the memory usage and prevent the client from overwhelming the server or getting stuck in case of a queue backlog. If not set, a default value will be used. client_az (Optional[str]): Availability Zone of the client. If ReadFrom strategy is AZAffinity, this setting ensures that readonly commands are directed to replicas within the specified AZ if exits. + advanced_config (Optional[AdvancedBaseClientConfiguration]): Advanced configuration settings for the client. """ self.addresses = addresses self.use_tls = use_tls @@ -264,6 +266,7 @@ class AdvancedGlideClientConfiguration(AdvancedBaseClientConfiguration): """ def __init__(self, connection_timeout: Optional[int] = None): + super().__init__(connection_timeout) @@ -286,7 +289,7 @@ class GlideClientConfiguration(BaseClientConfiguration): request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to complete. This duration encompasses sending the request, awaiting for a response from the server, and any required reconnections or retries. If the specified timeout is exceeded for a pending request, it will result in a timeout error. - If not set, a default value will be used. + If not explicitly set, a default value of 250 milliseconds will be used. reconnect_strategy (Optional[BackoffStrategy]): Strategy used to determine how and when to reconnect, in case of connection failures. If not set, a default backoff strategy will be used. @@ -300,7 +303,7 @@ class GlideClientConfiguration(BaseClientConfiguration): If not set, a default value will be used. client_az (Optional[str]): Availability Zone of the client. If ReadFrom strategy is AZAffinity, this setting ensures that readonly commands are directed to replicas within the specified AZ if exits. - advanced_config (Optional[AdvancedGlideClientConfiguration]) : Advanced configuration, see `AdvancedGlideClientConfiguration`. + advanced_config (Optional[AdvancedGlideClientConfiguration]): Advanced configuration settings for the client, see `AdvancedGlideClientConfiguration`. """ class PubSubChannelModes(IntEnum): @@ -442,7 +445,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration): read_from (ReadFrom): If not set, `PRIMARY` will be used. request_timeout (Optional[int]): The duration in milliseconds that the client should wait for a request to complete. This duration encompasses sending the request, awaiting for a response from the server, and any required reconnections or retries. - If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not set, a default value will be used. + If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not explicitly set, a default value of 250 milliseconds will be used. client_name (Optional[str]): Client name to be used for the client. Will be used with CLIENT SETNAME command during connection establishment. protocol (ProtocolVersion): The version of the RESP protocol to communicate with the server. periodic_checks (Union[PeriodicChecksStatus, PeriodicChecksManualInterval]): Configure the periodic topology checks. @@ -456,7 +459,7 @@ class GlideClusterClientConfiguration(BaseClientConfiguration): If not set, a default value will be used. client_az (Optional[str]): Availability Zone of the client. If ReadFrom strategy is AZAffinity, this setting ensures that readonly commands are directed to replicas within the specified AZ if exits. - advanced_config (Optional[AdvancedGlideClusterClientConfiguration]) : Advanced configuration, see `AdvancedGlideClusterClientConfiguration`. + advanced_config (Optional[AdvancedGlideClusterClientConfiguration]) : Advanced configuration settings for the client, see `AdvancedGlideClusterClientConfiguration`. Notes: