Skip to content

Commit 62adf0b

Browse files
committed
PYCBC-1752: Provide ClusterOption to enable C++ core lazy KV connections
Changes ------- * Add `enable_lazy_connections` option to `ClusterOptions` * Update bindings to pass `enable_lazy_connections` to C++ core * Update connection tests to confirm option is propagated to the C++ core Change-Id: I5a693982addd021fb33f02b917f68e3370245594 Reviewed-on: https://review.couchbase.org/c/couchbase-python-client/+/242352 Reviewed-by: Dimitris Christodoulou <dimitris.christodoulou@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent fbceef9 commit 62adf0b

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

couchbase/logic/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ class ClusterOptionsBase(dict):
683683
"app_telemetry_ping_interval": {"app_telemetry_ping_interval": timedelta_as_milliseconds},
684684
"app_telemetry_ping_timeout": {"app_telemetry_ping_timeout": timedelta_as_milliseconds},
685685
"allow_enterprise_analytics": {"allow_enterprise_analytics": validate_bool},
686+
"enable_lazy_connections": {"enable_lazy_connections": validate_bool}
686687
}
687688

688689
@overload
@@ -734,6 +735,7 @@ def __init__(
734735
app_telemetry_ping_interval=None, # type: Optional[timedelta]
735736
app_telemetry_ping_timeout=None, # type: Optional[timedelta]
736737
allow_enterprise_analytics=None, # type: Optional[bool]
738+
enable_lazy_connections=None # type: Optional[bool]
737739
):
738740
"""ClusterOptions instance."""
739741

couchbase/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ class ClusterOptions(ClusterOptionsBase):
405405
app_telemetry_backoff (timedelta, optional): Specifies the time to wait before attempting a websocket reconnection. Defaults to 5 seconds.
406406
app_telemetry_ping_interval (timedelta, optional): Specifies the time to wait between sending consecutive websocket PING commands to the server. Defaults to 30 seconds.
407407
app_telemetry_ping_timeout (timedelta, optional): Specifies the time allowed for the server to respond to websocket PING command. Defaults to 2 seconds.
408+
enable_lazy_connections (bool, optional): Set to True to enable the C++ core to lazily establish bucket connections. Defaults to False (disabled).
408409
""" # noqa: E501
409410

410411
def apply_profile(self,

couchbase/tests/connection_t.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def test_cluster_options(self, couchbase_config):
327327
'app_telemetry_backoff': timedelta(seconds=10),
328328
'app_telemetry_ping_interval': timedelta(seconds=60),
329329
'app_telemetry_ping_timeout': timedelta(seconds=5),
330+
'enable_lazy_connections': True,
330331
}
331332

332333
expected_opts = copy(opts)
@@ -1190,8 +1191,8 @@ def test_valid_connection_strings(self, conn_str):
11901191
pytest.fail(f'Unexpected exception occurred: {ex}')
11911192

11921193
@pytest.mark.parametrize('conn_str, expected_opts',
1193-
[('couchbase://10.0.0.1?num_io_threads=1&dump_configuration=true',
1194-
{'num_io_threads': 1, 'dump_configuration': True}),
1194+
[('couchbase://10.0.0.1?num_io_threads=1&dump_configuration=true&enable_lazy_connections=true', # noqa: E501
1195+
{'num_io_threads': 1, 'dump_configuration': True, 'enable_lazy_connections': True}),
11951196
('couchbase://10.0.0.1?max_http_connections=4&disable_mozilla_ca_certificates=False',
11961197
{'max_http_connections': 4, 'disable_mozilla_ca_certificates': False}),
11971198
('couchbase://localhost?enable_app_telemetry=true&app_telemetry_endpoint=ws://localhost:8091', # noqa: E501

src/utils.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ update_cluster_options_from_py(couchbase::core::cluster_options& options,
236236
extract_bool_field(pyObj_options, "enable_compression", options.enable_compression);
237237
extract_bool_field(
238238
pyObj_options, "disable_mozilla_ca_certificates", options.disable_mozilla_ca_certificates);
239+
extract_bool_field(pyObj_options, "enable_lazy_connections", options.enable_lazy_connections);
239240

240241
// Always disable metrics for now
241242
options.enable_metrics = false;
@@ -361,6 +362,7 @@ cluster_options_to_py(const couchbase::core::cluster_options& opts,
361362
add_bool_field(dict, "disable_mozilla_ca_certificates", opts.disable_mozilla_ca_certificates);
362363
add_bool_field(dict, "enable_metrics", opts.enable_metrics);
363364
add_bool_field(dict, "enable_tracing", opts.enable_tracing);
365+
add_bool_field(dict, "enable_lazy_connections", opts.enable_lazy_connections);
364366

365367
// Other
366368
add_field<std::chrono::milliseconds>(dict, "config_poll_interval", opts.config_poll_interval);

0 commit comments

Comments
 (0)