Skip to content

Commit

Permalink
Remove map_write_mode since it is mutually exclusive with persist_index
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannguyen4 committed Oct 18, 2023
1 parent dad3b56 commit d37c0bf
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 192 deletions.
3 changes: 0 additions & 3 deletions aerospike-stubs/aerospike.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion aerospike_helpers/operations/bitwise_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
21 changes: 0 additions & 21 deletions doc/aerospike.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 1 addition & 17 deletions doc/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
50 changes: 13 additions & 37 deletions src/main/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/new_tests/test_batch_get_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion test/new_tests/test_inverted_map_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test/new_tests/test_map_operation_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion test/new_tests/test_map_write_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
107 changes: 0 additions & 107 deletions test/new_tests/test_map_write_mode.py

This file was deleted.

2 changes: 1 addition & 1 deletion test/new_tests/test_relative_cdt_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d37c0bf

Please sign in to comment.