Skip to content
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

Introduce configuration options in the cluster API #137

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bjosv
Copy link
Collaborator

@bjosv bjosv commented Dec 4, 2024

The standalone API uses the options struct valkeyOptions to allow users to configure how libvalkey set up the context.
This struct is used when calling valkeyConnectWithOptions(valkeyOptions *opt), which returns a connected context with prepared command timeout values and so on.

The current cluster API, which in inherited from the project hiredis-vip and hiredis-cluster, has some similarities to the standalone API, but it does not provide a options struct and does not have the same "look and feel" as the standalone API.

This PR introduces a valkeyClusterOption that allows a user to set all options before connecting to the cluster using:
valkeyClusterContext *cc = valkeyClusterConnectWithOptions(&options)
or
valkeyClusterAsyncContext *acc = valkeyClusterAsyncConnectWithOptions(&options) when using the async API.

This options struct enables users to set the initial nodes, callbacks, timeouts, options, TLS- and event-adapters,
instead of using a wide range of valkeyClusterSetOptionXxx functions on a valkeyClusterContext (even when they use async contexts valkeyClusterAsyncContext...).
There are still options that are allowed to be configured during runtime likevalkeyClusterSetOptionTimeout, but most other options requires a reconnect.

The async cluster API will no longer require that users calls the blocking cluster API using valkeyClusterConnect2(acc->cc).
We now provide a new option VALKEY_OPT_BLOCKING_INITIAL_UPDATE to enable a blocking slotmap update after an initial connect using the valkeyClusterAsyncConnectWithOptions API. This will allow us to avoid acc->cc usages and we should be able to hide the cc in the acc struct.

All testcases are updated to use the new API and this should give a feeling how it works,
alternatively look at changes in include/valkey/cluster.h.
The migration guide and docs are not yet updated since its a draft PR.

bjosv added 5 commits December 4, 2024 21:48
These flags will be replaced by options and can be set
using these new APIs instead:

- valkeyClusterConnectWithOptions
- valkeyClusterAsyncConnectWithOptions

Signed-off-by: Björn Svensson <[email protected]>
Signed-off-by: Björn Svensson <[email protected]>
@bjosv bjosv requested a review from zuiderkwast December 4, 2024 22:00
Copy link
Collaborator

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API looks good in general!

Comment on lines +196 to +202
/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEVENT(opts, event_base) \
do { \
(opts)->attach_fn = valkeyLibeventAttachAdapter; \
(opts)->attach_data = event_base; \
} while (0)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these not static functions, like valkeyClusterLibeventAttach and others?

Comment on lines +46 to +52
/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_SSL(opts, tls_) \
do { \
(opts)->tls = tls_; \
(opts)->tls_init_fn = &valkeyInitiateTLSWithContext; \
} while (0)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants