Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
Signed-off-by: Shoham Elias <[email protected]>
  • Loading branch information
shohamazon committed Dec 23, 2024
1 parent fb01f37 commit e924f99
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 25 deletions.
2 changes: 1 addition & 1 deletion glide-core/redis-rs/redis/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>,
}

Expand Down
2 changes: 2 additions & 0 deletions glide-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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.
*
* <p>If not explicitly set, a default value of 250 milliseconds will be used.
*/
private final Integer connectionTimeout;
}
Original file line number Diff line number Diff line change
@@ -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}.
*
* <p>Example Usage:
*
* <pre>{@code
* AdvancedGlideClientConfiguration config = AdvancedGlideClientConfiguration.builder()
* .connectionTimeout(500)
* .build();
* }</pre>
*/
@Getter
@SuperBuilder
@ToString
Expand Down
Original file line number Diff line number Diff line change
@@ -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}.
*
* <p>Example Usage:
*
* <pre>{@code
* AdvancedGlideClusterClientConfiguration config = AdvancedGlideClusterClientConfiguration.builder()
* .connectionTimeout(500)
* .build();
* }</pre>
*/
@Getter
@SuperBuilder
@ToString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* .clientName("GLIDE")
* .subscriptionConfiguration(subscriptionConfiguration)
* .inflightRequestsLimit(1000)
* .advancedConfiguration(AdvancedGlideClientConfiguration.builder().connectionTimeout(500).build())
* .build();
* }</pre>
*/
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* .clientName("GLIDE")
* .subscriptionConfiguration(subscriptionConfiguration)
* .inflightRequestsLimit(1000)
* .advancedConfiguration(AdvancedGlideClusterClientConfiguration.builder().connectionTimeout(500).build())
* .build();
* }</pre>
*/
Expand All @@ -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;
}
11 changes: 9 additions & 2 deletions java/client/src/main/java/glide/managers/ConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions node/rust-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand Down
40 changes: 36 additions & 4 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions node/src/GlideClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {};

Expand Down
16 changes: 14 additions & 2 deletions node/src/GlideClusterClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {};

Expand Down Expand Up @@ -564,7 +577,6 @@ export class GlideClusterClient extends BaseClient {
public static async createClient(
options: GlideClusterClientConfiguration,
): Promise<GlideClusterClient> {
console.log("options are: ", options);
return await super.createClientInternal(
options,
(socket: net.Socket, options?: GlideClusterClientConfiguration) =>
Expand Down
15 changes: 9 additions & 6 deletions python/python/glide/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -264,6 +266,7 @@ class AdvancedGlideClientConfiguration(AdvancedBaseClientConfiguration):
"""

def __init__(self, connection_timeout: Optional[int] = None):

super().__init__(connection_timeout)


Expand All @@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down

0 comments on commit e924f99

Please sign in to comment.