Skip to content

[CLIENT-3246] Support "force_single_node" client config option for QE Jepsen testing #718

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

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from
8 changes: 8 additions & 0 deletions doc/aerospike.rst
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,14 @@ Only the `hosts` key is required; the rest of the keys are optional.
Flag to signify fail on cluster init if seed node and all peers are not reachable.

Default: ``True``
* **force_single_node** (:class:`bool`)
For testing purposes only. Do not modify.

Should the client communicate with the first seed node only
instead of using the data partition map to determine which node to send the
database command.

Default: ``False``

Constants
=========
Expand Down
24 changes: 19 additions & 5 deletions src/main/client/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,11 +1011,24 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args,
}
}

PyObject *py_fail_if_not_connected =
PyDict_GetItemString(py_config, "fail_if_not_connected");
if (py_fail_if_not_connected && PyBool_Check(py_fail_if_not_connected)) {
config.fail_if_not_connected =
PyObject_IsTrue(py_fail_if_not_connected);
bool *bool_config_refs[] = {&config.force_single_node,
&config.fail_if_not_connected};
const char *bool_config_name[] = {"force_single_node",
"fail_if_not_connected"};

// TODO: needs better input validation.
// i.e throw an exception if value is not a bool type
for (unsigned long i = 0;
i < sizeof(bool_config_name) / sizeof(bool_config_name[0]); i++) {
PyObject *py_bool_value =
PyDict_GetItemString(py_config, bool_config_name[i]);
if (py_bool_value && PyBool_Check(py_bool_value)) {
int retval = PyObject_IsTrue(py_bool_value);
if (retval == -1) {
goto RAISE_EXCEPTION_WITHOUT_AS_ERROR;
}
*bool_config_refs[i] = (bool)retval;
}
}

PyObject *py_user_name = PyDict_GetItemString(py_config, "user");
Expand Down Expand Up @@ -1110,6 +1123,7 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args,
}

raise_exception(&constructor_err);
RAISE_EXCEPTION_WITHOUT_AS_ERROR:
return -1;
}

Expand Down
12 changes: 10 additions & 2 deletions test/new_tests/test_new_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,17 @@ def test_neg_setting_rack_ids(rack_ids):
aerospike.client(config)


def test_setting_use_services_alternate():
@pytest.mark.parametrize(
"setting",
[
"use_services_alternate",
"force_single_node",
"fail_if_not_connected"
]
)
def test_bool_settings(setting):
config = copy.deepcopy(gconfig)
config["use_services_alternate"] = True
config[setting] = True
client = aerospike.client(config)
assert client is not None

Expand Down