diff --git a/aerospike-stubs/aerospike.pyi b/aerospike-stubs/aerospike.pyi index b5f066213..dbc562c6f 100644 --- a/aerospike-stubs/aerospike.pyi +++ b/aerospike-stubs/aerospike.pyi @@ -93,7 +93,6 @@ LOG_LEVEL_INFO: Literal[2] LOG_LEVEL_OFF: Literal[-1] LOG_LEVEL_TRACE: Literal[4] LOG_LEVEL_WARN: Literal[1] -MAP_CREATE_ONLY: Literal[2] MAP_KEY_ORDERED: Literal[1] MAP_KEY_VALUE_ORDERED: Literal[3] MAP_RETURN_COUNT: Literal[5] @@ -109,8 +108,6 @@ MAP_RETURN_VALUE: Literal[7] MAP_RETURN_ORDERED_MAP: Literal[17] MAP_RETURN_UNORDERED_MAP: Literal[16] MAP_UNORDERED: Literal[0] -MAP_UPDATE: Literal[0] -MAP_UPDATE_ONLY: Literal[1] MAP_WRITE_FLAGS_CREATE_ONLY: Literal[1] MAP_WRITE_FLAGS_DEFAULT: Literal[0] MAP_WRITE_FLAGS_NO_FAIL: Literal[4] diff --git a/aerospike_helpers/operations/bitwise_operations.py b/aerospike_helpers/operations/bitwise_operations.py index f8d018378..320a8547b 100644 --- a/aerospike_helpers/operations/bitwise_operations.py +++ b/aerospike_helpers/operations/bitwise_operations.py @@ -96,7 +96,7 @@ client.remove(key) bit_policy = { - 'map_write_mode': aerospike.BIT_WRITE_DEFAULT, + 'bit_write_flags': aerospike.BIT_WRITE_DEFAULT, } client.put(key, {five_one_bin: five_one_blob}) diff --git a/doc/aerospike.rst b/doc/aerospike.rst index 4cf6a242b..37fb9b4b9 100644 --- a/doc/aerospike.rst +++ b/doc/aerospike.rst @@ -1085,27 +1085,6 @@ Flags used by map write flag. Allow other valid map items to be committed if a map item is denied due to write flag constraints. -.. _aerospike_map_write_mode: - -Map Write Mode -^^^^^^^^^^^^^^ - -Flags used by map *write mode*. - -.. note:: This should only be used for Server version < 4.3.0 - -.. data:: MAP_UPDATE - - Default. Allow create or update. - -.. data:: MAP_CREATE_ONLY - - If the key already exists, the item will be denied. If the key does not exist, a new item will be created. - -.. data:: MAP_UPDATE_ONLY - - If the key already exists, the item will be overwritten. If the key does not exist, the item will be denied. - .. _aerospike_map_order: Map Order diff --git a/doc/client.rst b/doc/client.rst index 197c2614a..4a15e6102 100755 --- a/doc/client.rst +++ b/doc/client.rst @@ -2264,21 +2264,11 @@ Map Policies .. object:: policy - A :class:`dict` of optional map policies, which are applicable to map operations. Only one of ``map_write_mode`` or ``map_write_flags`` should - be provided. ``map_write_mode`` should be used for Aerospike Server versions < `4.3.0` and ``map_write_flags`` should be used for Aerospike server versions - greater than or equal to `4.3.0` . + A :class:`dict` of optional map policies, which are applicable to map operations. .. hlist:: :columns: 1 - * **map_write_mode** - | Write mode for the map operation. - | One of the :ref:`aerospike_map_write_mode` values such as :data:`aerospike.MAP_UPDATE` - | - | Default: :data:`aerospike.MAP_UPDATE` - - .. note:: This should only be used for Server version < 4.3.0. - * **map_write_flags** | Write flags for the map operation. | One of the :ref:`aerospike_map_write_flag` values such as :data:`aerospike.MAP_WRITE_FLAGS_DEFAULT` @@ -2311,12 +2301,6 @@ Map Policies 'map_write_flags': aerospike.MAP_WRITE_FLAGS_CREATE_ONLY } - # Server < 4.3.0 - map_policy = { - 'map_order': aerospike.MAP_UNORDERED, - 'map_write_mode': aerospike.MAP_CREATE_ONLY - } - .. _aerospike_bit_policies: Bit Policies diff --git a/src/main/policy.c b/src/main/policy.c index 745eaa35b..07ff2b638 100644 --- a/src/main/policy.c +++ b/src/main/policy.c @@ -219,10 +219,6 @@ static AerospikeConstants aerospike_constants[] = { {AS_MAP_KEY_ORDERED, "MAP_KEY_ORDERED"}, {AS_MAP_KEY_VALUE_ORDERED, "MAP_KEY_VALUE_ORDERED"}, - {AS_MAP_UPDATE, "MAP_UPDATE"}, - {AS_MAP_UPDATE_ONLY, "MAP_UPDATE_ONLY"}, - {AS_MAP_CREATE_ONLY, "MAP_CREATE_ONLY"}, - {AS_MAP_RETURN_NONE, "MAP_RETURN_NONE"}, {AS_MAP_RETURN_INDEX, "MAP_RETURN_INDEX"}, {AS_MAP_RETURN_REVERSE_INDEX, "MAP_RETURN_REVERSE_INDEX"}, @@ -1122,48 +1118,28 @@ as_status pyobject_to_map_policy(as_error *err, PyObject *py_policy, // Initialize Policy POLICY_INIT(as_map_policy); + // Defaults long map_order = AS_MAP_UNORDERED; - long map_write_mode = AS_MAP_UPDATE; uint32_t map_write_flags = AS_MAP_WRITE_DEFAULT; + bool persist_index = false; MAP_POLICY_SET_FIELD(map_order); - PyObject *mode_or_flags = - PyDict_GetItemString(py_policy, MAP_WRITE_FLAGS_KEY); - - /* - This only works for client >= 3.5.0 and server >= 4.3.0 - If py_policy["map_write_flags"] is set, we use it - otherwise we use py_policy["map_write_mode"] - */ - if (mode_or_flags) { - if (PyLong_Check(mode_or_flags)) { - map_write_flags = (uint32_t)PyLong_AsLong(mode_or_flags); - as_map_policy_set_flags(policy, map_order, map_write_flags); - } - else { - as_error_update(err, AEROSPIKE_ERR_PARAM, - "map write flags must be an integer"); - } - return err->code; - } - - MAP_POLICY_SET_FIELD(map_write_mode); + MAP_POLICY_SET_FIELD(map_write_flags); PyObject *py_persist_index = PyDict_GetItemString(py_policy, "persist_index"); - bool persist_index; - if (!py_persist_index) { - // Default value if persist_index isn't set in policy - persist_index = false; - } - else if (!PyBool_Check(py_persist_index)) { - // persist_index value must be valid if it is set - return as_error_update(err, AEROSPIKE_ERR_PARAM, - "persist_index is not a boolean"); + if (py_persist_index) { + if (PyBool_Check(py_persist_index)) { + persist_index = (bool)PyObject_IsTrue(py_persist_index); + } + else { + // persist_index value must be valid if it is set + return as_error_update(err, AEROSPIKE_ERR_PARAM, + "persist_index is not a boolean"); + } } - persist_index = (bool)PyObject_IsTrue(py_persist_index); - as_map_policy_set_all(policy, map_order, map_write_mode, persist_index); + as_map_policy_set_all(policy, map_order, map_write_flags, persist_index); return err->code; } diff --git a/test/new_tests/test_batch_get_ops.py b/test/new_tests/test_batch_get_ops.py index 898103116..a8df01661 100644 --- a/test/new_tests/test_batch_get_ops.py +++ b/test/new_tests/test_batch_get_ops.py @@ -122,7 +122,7 @@ def test_batch_result_output_format(self): # pp = pprint.PrettyPrinter(2, 80) policy = {"key": aerospike.POLICY_KEY_SEND} map_policy = { - "map_write_mode": aerospike.MAP_UPDATE, + "map_write_flags": aerospike.MAP_WRITE_FLAGS_UPDATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED, } diff --git a/test/new_tests/test_inverted_map_operations.py b/test/new_tests/test_inverted_map_operations.py index 93aa95109..d6f6e189b 100644 --- a/test/new_tests/test_inverted_map_operations.py +++ b/test/new_tests/test_inverted_map_operations.py @@ -39,7 +39,7 @@ def maps_have_same_values(map1, map2): def sort_map(client, test_key, test_bin): - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} + map_policy = {"map_write_flags": aerospike.MAP_WRITE_FLAGS_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} operations = [map_ops.map_set_policy(test_bin, map_policy)] client.operate(test_key, operations) diff --git a/test/new_tests/test_map_operation_helpers.py b/test/new_tests/test_map_operation_helpers.py index d7a3dd3f8..15bc02ddc 100644 --- a/test/new_tests/test_map_operation_helpers.py +++ b/test/new_tests/test_map_operation_helpers.py @@ -39,7 +39,7 @@ def maps_have_same_values(map1, map2): def sort_map(client, test_key, test_bin): - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} + map_policy = {"map_write_flags": aerospike.MAP_WRITE_FLAGS_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} operations = [map_ops.map_set_policy(test_bin, map_policy)] client.operate(test_key, operations) @@ -80,7 +80,7 @@ def test_map_set_policy(self): Test setting map policy with an operation """ map_policy = { - "map_write_mode": aerospike.MAP_CREATE_ONLY, + "map_write_flags": aerospike.MAP_WRITE_FLAGS_CREATE_ONLY, "map_order": aerospike.MAP_KEY_VALUE_ORDERED, "persist_index": True } diff --git a/test/new_tests/test_map_write_flags.py b/test/new_tests/test_map_write_flags.py index 3a50793e7..08572197b 100644 --- a/test/new_tests/test_map_write_flags.py +++ b/test/new_tests/test_map_write_flags.py @@ -90,7 +90,7 @@ def test_update_only_does_not_allow_create(self): map_ops.map_put("map", "new", "new", map_policy=map_policy), ] - with pytest.raises(e.AerospikeError): + with pytest.raises(e.ElementNotFoundError): self.as_connection.operate(key, ops) _, _, bins = self.as_connection.get(key) diff --git a/test/new_tests/test_map_write_mode.py b/test/new_tests/test_map_write_mode.py deleted file mode 100644 index e501b7a86..000000000 --- a/test/new_tests/test_map_write_mode.py +++ /dev/null @@ -1,107 +0,0 @@ -# These fail if we don't have a new server -# -*- coding: utf-8 -*- -import pytest -import aerospike -from aerospike import exception as e -from aerospike_helpers.operations import map_operations as map_ops - - -class TestMapWriteMode(object): - @pytest.fixture(autouse=True) - def setup(self, request, as_connection): - """ - Setup Method - """ - self.keys = [] - - yield - - for key in self.keys: - self.as_connection.remove(key) - - def test_default_allows_update_and_create(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_UPDATE} - ops = [ - map_ops.map_put("map", "existing", "new", map_policy=map_policy), - map_ops.map_put("map", "new", "new", map_policy=map_policy), - ] - self.as_connection.operate(key, ops) - - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "new" - assert map_bin["new"] == "new" - - def test_create_only_does_not_allow_update(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY} - ops = [ - map_ops.map_put("map", "existing", "new", map_policy=map_policy), - ] - with pytest.raises(e.ElementExistsError): - self.as_connection.operate(key, ops) - - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "old" - - def test_create_only_allows_create(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY} - ops = [ - map_ops.map_put("map", "new", "new", map_policy=map_policy), - ] - self.as_connection.operate(key, ops) - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "old" - assert map_bin["new"] == "new" - - def test_update_only_does_not_allow_create(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_UPDATE_ONLY} - ops = [ - map_ops.map_put("map", "new", "new", map_policy=map_policy), - ] - - with pytest.raises(e.ElementNotFoundError): - self.as_connection.operate(key, ops) - - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "old" - assert "new" not in map_bin - - def test_update_only_allows_update(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_UPDATE_ONLY} - ops = [ - map_ops.map_put("map", "existing", "new", map_policy=map_policy), - ] - - self.as_connection.operate(key, ops) - - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "new" diff --git a/test/new_tests/test_relative_cdt_operations.py b/test/new_tests/test_relative_cdt_operations.py index 5f9a2cad4..7a242f5ca 100644 --- a/test/new_tests/test_relative_cdt_operations.py +++ b/test/new_tests/test_relative_cdt_operations.py @@ -261,7 +261,7 @@ def setup(self, request, as_connection): self.test_bin = "map" self.as_connection.put(self.test_key, {self.test_bin: self.test_map}) - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} + map_policy = {"map_write_flags": aerospike.MAP_WRITE_FLAGS_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} operations = [map_ops.map_set_policy(self.test_bin, map_policy)] self.as_connection.operate(self.test_key, operations) self.keys.append(self.test_key)