From 98766c693623e2196a2a6c2208d7cfce9c10350e Mon Sep 17 00:00:00 2001 From: Robert Marks Date: Wed, 3 Jul 2019 01:32:15 +0000 Subject: [PATCH 1/4] Add use_serices_alternate support --- VERSION | 2 +- doc/aerospike.rst | 4 ++++ src/main/aerospike.c | 2 +- src/main/client/type.c | 19 +++++++++++++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index a76ccff2a..0b2eb36f5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.7.1 +3.7.2 diff --git a/doc/aerospike.rst b/doc/aerospike.rst index b552f055a..9838f0e45 100644 --- a/doc/aerospike.rst +++ b/doc/aerospike.rst @@ -116,6 +116,10 @@ in an in-memory primary index. | This serves to lower cloud provider costs when nodes are distributed across different racks/data centers. | **rack_id** and **POLICY_REPLICA_PREFER_RACK** and server rack configuration must also be set to enable this functionality. | Default False + * **use_services_alternate** + | Boolean. Flag to signify if "services-alternate" should be used instead of "services" + | Default False + :return: an instance of the :py:class:`aerospike.Client` class. diff --git a/src/main/aerospike.c b/src/main/aerospike.c index b31bfd5ee..1f7d5087f 100644 --- a/src/main/aerospike.c +++ b/src/main/aerospike.c @@ -94,7 +94,7 @@ AerospikeConstants operator_constants[] = { MOD_INIT(aerospike) { - const char version[8] = "3.7.1"; + const char version[8] = "3.7.2"; // Makes things "thread-safe" PyEval_InitThreads(); int i = 0; diff --git a/src/main/client/type.c b/src/main/client/type.c index 85ff22b3b..4e61f0f14 100644 --- a/src/main/client/type.c +++ b/src/main/client/type.c @@ -34,6 +34,7 @@ static int set_rack_aware_config(as_config* conf, PyObject* config_dict); +static int set_use_services_alternate(as_config* conf, PyObject* config_dict); enum {INIT_SUCCESS, INIT_NO_CONFIG_ERR, INIT_CONFIG_TYPE_ERR, INIT_LUA_USER_ERR, INIT_LUA_SYS_ERR, INIT_HOST_TYPE_ERR, INIT_EMPTY_HOSTS_ERR, @@ -1270,10 +1271,11 @@ static int AerospikeClient_Type_Init(AerospikeClient * self, PyObject * args, Py } if (set_rack_aware_config(&config, py_config) != INIT_SUCCESS) { - return INIT_POLICY_PARAM_ERR; } - + if (set_use_services_alternate(&config, py_config) != INIT_SUCCESS) { + return INIT_POLICY_PARAM_ERR; + } PyObject* py_max_socket_idle = NULL; py_max_socket_idle = PyDict_GetItemString(py_config, "max_socket_idle"); @@ -1387,6 +1389,19 @@ static int set_rack_aware_config(as_config*conf, PyObject* config_dict) { return INIT_SUCCESS; } +static int set_use_services_alternate(as_config* conf, PyObject* config_dict) { + PyObject* py_config_value; + py_config_value = PyDict_GetItemString(config_dict, "use_services_alternate"); + if (py_config_value) { + if (PyBool_Check(py_config_value)) { + conf->use_services_alternate = PyObject_IsTrue(py_config_value); + } else { + return INIT_POLICY_PARAM_ERR; // A non boolean was passed in as the value of use_services_alternate + } + } + return INIT_SUCCESS; +} + static void AerospikeClient_Type_Dealloc(PyObject * self) { From 705d05548600338ab28a4b857a5fa2090c95b069 Mon Sep 17 00:00:00 2001 From: Robert Marks Date: Wed, 3 Jul 2019 14:24:03 +0000 Subject: [PATCH 2/4] Make constructor behavior more consistent, test using use_services_alternate --- src/main/client/type.c | 6 ++++-- test/new_tests/test_new_constructor.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/client/type.c b/src/main/client/type.c index 4e61f0f14..bb4618197 100644 --- a/src/main/client/type.c +++ b/src/main/client/type.c @@ -1271,10 +1271,12 @@ static int AerospikeClient_Type_Init(AerospikeClient * self, PyObject * args, Py } if (set_rack_aware_config(&config, py_config) != INIT_SUCCESS) { - return INIT_POLICY_PARAM_ERR; + error_code = INIT_POLICY_PARAM_ERR; + goto CONSTRUCTOR_ERROR; } if (set_use_services_alternate(&config, py_config) != INIT_SUCCESS) { - return INIT_POLICY_PARAM_ERR; + error_code = INIT_POLICY_PARAM_ERR; + goto CONSTRUCTOR_ERROR; } PyObject* py_max_socket_idle = NULL; diff --git a/test/new_tests/test_new_constructor.py b/test/new_tests/test_new_constructor.py index 070dcd102..ac166fbaf 100644 --- a/test/new_tests/test_new_constructor.py +++ b/test/new_tests/test_new_constructor.py @@ -84,6 +84,11 @@ def test_setting_rack_aware_and_rack_id(): client = aerospike.client(config) assert client is not None +def test_setting_use_services_alternate(): + config = {'hosts': host, 'use_services_alternate': True} + client = aerospike.client(config) + assert client is not None + def test_setting_rack_aware_non_bool(): config = {'hosts': host, 'rack_aware': "True"} with pytest.raises(e.ParamError): @@ -102,3 +107,11 @@ def test_setting_rack_id_wrong_type(rack_id): config = {'hosts': host, 'rack_id': rack_id} with pytest.raises(e.ParamError): client = aerospike.client(config) + +def test_setting_wrong_type_services_alternate(): + ''' + 'use_services_alternate' should be a boolean + ''' + config = {'hosts': host, 'use_services_alternate': "True"} + with pytest.raises(e.ParamError): + client = aerospike.client(config) \ No newline at end of file From 4811375f97623ff06a33d7a00f3cfde6f32652a2 Mon Sep 17 00:00:00 2001 From: Robert Marks Date: Wed, 3 Jul 2019 15:39:59 +0000 Subject: [PATCH 3/4] Mention explicit constructor use --- doc/aerospike.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/aerospike.rst b/doc/aerospike.rst index 9838f0e45..f91fef53a 100644 --- a/doc/aerospike.rst +++ b/doc/aerospike.rst @@ -40,6 +40,9 @@ in an in-memory primary index. against it, such as :meth:`~aerospike.Client.put` and :meth:`~aerospike.Client.get` records. + This is a wrapper function which calls the constructor for the :class:`~aerospike.Client` class. + The client may also be constructed by calling the constructor directly. + :param dict config: the client's configuration. .. hlist:: From e29f7e6ca7b939de1f3d0dab8ff90a35accae606 Mon Sep 17 00:00:00 2001 From: Robert Marks Date: Wed, 3 Jul 2019 21:13:20 +0000 Subject: [PATCH 4/4] Update travis build OS --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd81cf55e..7c5bc9bfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,14 +6,14 @@ python: sudo: false os: - linux -dist: trusty +dist: xenial addons: apt: packages: - libssl-dev - python-dev install: -- wget -O aerospike-server.tgz http://aerospike.com/download/server/latest/artifact/tgz +- wget -O aerospike-server.tgz https://aerospike.com/download/server/latest/artifact/tgz - tar xvzf aerospike-server.tgz - cp -f .travis/aerospike.conf ./aerospike-server/share/etc - cd aerospike-server