Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
041749a
CLIENT-681 refactor (#621)
DomPeliniAerospike May 23, 2025
483f959
Refactor the dynamic_pool
DomPeliniAerospike May 27, 2025
952fe85
Fixed merge conflicts
DomPeliniAerospike May 27, 2025
7b08bbd
Fixed merge conflicts
DomPeliniAerospike May 27, 2025
d05c47c
Fixed merge conflicts
DomPeliniAerospike May 27, 2025
928943f
Fixed merge conflicts
DomPeliniAerospike May 27, 2025
97163b2
Fixed merge conflicts
DomPeliniAerospike May 27, 2025
f4261a8
Fixed merge conflicts
DomPeliniAerospike May 27, 2025
1c95766
Fixed merge conflicts
DomPeliniAerospike May 27, 2025
3eaef6c
Fixed merge conflicts
DomPeliniAerospike May 27, 2025
d9c4982
Fixed merge conflicts
DomPeliniAerospike May 27, 2025
cd76a0f
revert c client
juliannguyen4 May 27, 2025
3b7ee6b
Refactored Byte Pool Code
DomPeliniAerospike Jun 6, 2025
11532e2
Merge branch 'dev' into CLIENT-681-2025
DomPeliniAerospike Jun 6, 2025
ff66bb3
Fixed issue with config.conf.template
DomPeliniAerospike Jun 6, 2025
24f43ed
Merge branch 'dev' into CLIENT-681-2025
DomPeliniAerospike Jun 30, 2025
74d00c0
Added changes from review
DomPeliniAerospike Oct 23, 2025
912abd0
Merge branch 'dev' into CLIENT-681-2025
DomPeliniAerospike Oct 23, 2025
e591df9
Fix merge conflict issue
DomPeliniAerospike Oct 23, 2025
231e48a
Changes from pre-commit
DomPeliniAerospike Oct 23, 2025
36f2512
Merge branch 'dev' into CLIENT-681-2025
DomPeliniAerospike Nov 3, 2025
dc674cc
Update conversions.c
DomPeliniAerospike Nov 3, 2025
0ea62c9
Update conversions.c
DomPeliniAerospike Nov 3, 2025
e8cdd77
lint fix
DomPeliniAerospike Nov 3, 2025
2e73f6c
Merge branch 'dev' into CLIENT-681-2025
DomPeliniAerospike Nov 4, 2025
de830d9
Removed destroy_buffers variable
DomPeliniAerospike Nov 5, 2025
4697e71
Update bit_operate.c
DomPeliniAerospike Nov 5, 2025
988067e
Removed double instantiation of byte pools in policy functions
DomPeliniAerospike Nov 6, 2025
eba0c50
Update serializer.c
DomPeliniAerospike Nov 14, 2025
74f897b
Fixed test by closing client
DomPeliniAerospike Nov 14, 2025
0f3667c
Merge branch 'dev' into CLIENT-681-2025
DomPeliniAerospike Jan 23, 2026
aa86e64
Fixed merge issue
DomPeliniAerospike Jan 23, 2026
4b044b5
Added linting and fixed some test cases
DomPeliniAerospike Jan 23, 2026
221730f
Update test_cdt_index.py
DomPeliniAerospike Jan 23, 2026
3064009
Fixed tests
DomPeliniAerospike Jan 23, 2026
0c4b0a1
Commented out failing test cases
DomPeliniAerospike Jan 23, 2026
a52315e
Fixed issue with serializer failing in initiailze_bin_for_strictypes
DomPeliniAerospike Jan 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/include/bit_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
as_status add_new_bit_op(AerospikeClient *self, as_error *err,
PyObject *op_dict, as_vector *unicodeStrVector,
as_operations *ops, long operation_code,
long *ret_type, int serializer_type);
long *ret_type);
3 changes: 1 addition & 2 deletions src/include/cdt_list_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@
as_status add_new_list_op(AerospikeClient *self, as_error *err,
PyObject *op_dict, as_vector *unicodeStrVector,
as_dynamic_pool *dynamic_pool, as_operations *ops,
long operation_code, long *ret_type,
int serializer_type);
long operation_code, long *ret_type);
3 changes: 1 addition & 2 deletions src/include/cdt_map_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@
as_status add_new_map_op(AerospikeClient *self, as_error *err,
PyObject *op_dict, as_vector *unicodeStrVector,
as_dynamic_pool *dynamic_pool, as_operations *ops,
long operation_code, long *ret_type,
int serializer_type);
long operation_code, long *ret_type);
5 changes: 2 additions & 3 deletions src/include/cdt_operation_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ as_status get_bin(as_error *err, PyObject *op_dict, as_vector *unicodeStrVector,

as_status get_asval(AerospikeClient *self, as_error *err, char *key,
PyObject *op_dict, as_val **val,
as_dynamic_pool *dynamic_pool, int serializer_type,
bool required);
as_dynamic_pool *dynamic_pool, bool required);

as_status get_val_list(AerospikeClient *self, as_error *err,
const char *list_key, PyObject *op_dict, as_list **list,
as_dynamic_pool *dynamic_pool, int serializer_type);
as_dynamic_pool *dynamic_pool);

as_status get_int64_t(as_error *err, const char *key, PyObject *op_dict,
int64_t *i64_valptr);
Expand Down
9 changes: 4 additions & 5 deletions src/include/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ as_status pyobject_to_strArray(as_error *err, PyObject *py_list, char **arr,
as_status as_val_new_from_pyobject(AerospikeClient *self, as_error *err,
PyObject *py_obj, as_val **val,
as_dynamic_pool *dynamic_pool, int serializer_type,
bool allocate_buffer);
bool destroy_buffers);

as_status pyobject_to_map(AerospikeClient *self, as_error *err,
PyObject *py_dict, as_map **map,
as_dynamic_pool *dynamic_pool, int serializer_type, bool allocate_buffer);
as_dynamic_pool *dynamic_pool, int serializer_type, bool destroy_buffers);

as_status pyobject_to_list(AerospikeClient *self, as_error *err,
PyObject *py_list, as_list **list,
as_dynamic_pool *dynamic_pool, int serializer_type, bool allocate_buffer);
as_dynamic_pool *dynamic_pool, int serializer_type, bool destroy_buffers);

as_status pyobject_to_key(as_error *err, PyObject *py_key, as_key *key);

Expand Down Expand Up @@ -197,8 +197,7 @@ as_status string_and_pyuni_from_pystring(PyObject *py_string,

as_status get_cdt_ctx(AerospikeClient *self, as_error *err, as_cdt_ctx *cdt_ctx,
PyObject *op_dict, bool *ctx_in_use,
as_dynamic_pool *dynamic_pool, int serializer_type,
bool allocate_buffer);
as_dynamic_pool *dynamic_pool, bool destroy_buffers);

as_status convert_exp_list(AerospikeClient *self, PyObject *py_exp_list,
as_exp **exp_list, as_error *err);
Expand Down
62 changes: 36 additions & 26 deletions src/include/dynamic_pool.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/*
*******************************************************************************************************
* Dynamic pool maintained to avoid excessive runtime mallocs.
* It is comprised of a Pool of pointers to pools of
* as_bytes containing AS_DYNAMIC_POOL_BLOCK_SIZE as_bytes.
* Dynamic pool maintained to avoid excessive runtime mallocs and efficiently use memory.
*
* The dynamic pool maintains a table composed of several groups of as_bytes buffers.
* New groups are allocated dynamically after the current group is exhausted.
* As more as_bytes are used, group sizes will grow to reduce malloc calls.

* The dynamic pool does not allocate any memory unless bytes are used in a command.
*
*******************************************************************************************************
*/
#define AS_DYNAMIC_POOL_BYTES_PER_GROUP_MIN 128
Expand Down Expand Up @@ -41,8 +46,7 @@ static inline void dynamic_pool_malloc_group(as_dynamic_pool *dynamic_pool,
// bytes number to allocate in the next group.
uint16_t num_bytes_to_allocate = dynamic_pool->bytes_per_group;

// Allocate a group of bytes determined by bytes_per_group.
table[group_num_to_allocate] = (as_bytes *)cf_malloc(sizeof(as_bytes) * num_bytes_to_allocate);
table[group_num_to_allocate] = (as_bytes *)cf_malloc(num_bytes_to_allocate * sizeof(as_bytes));

// If allocation fails, throw an error.
if (table[group_num_to_allocate] == NULL) {
Expand Down Expand Up @@ -144,7 +148,7 @@ static inline void dynamic_pool_free_group(as_dynamic_pool *dynamic_pool, bool f
dynamic_pool_destroy_bytes_in_group(dynamic_pool, group_index, num_bytes);
}
as_bytes* group = dynamic_pool->byte_group_table[group_index];
cf_free((as_dynamic_pool *)group);
cf_free(group);
}

/**
Expand All @@ -166,7 +170,7 @@ static inline void dynamic_pool_free_table(as_dynamic_pool *dynamic_pool, bool f
// Free the current byte group.
dynamic_pool_free_group(dynamic_pool, free_buffer, dynamic_pool->group_iterator, dynamic_pool->byte_iterator);
// Free the table.
cf_free(((as_dynamic_pool *)dynamic_pool)->byte_group_table);
cf_free(dynamic_pool->byte_group_table);
}


Expand All @@ -176,7 +180,7 @@ static inline void dynamic_pool_free_table(as_dynamic_pool *dynamic_pool, bool f
* If the group table is full, the table is also expanded.
*
* @param dynamic_pool Pointer to a dynamic pool.
* @param error Pointer to an as_error
* @param err Pointer to an as_error
*
*/
static inline void dynamic_pool_init(as_dynamic_pool *dynamic_pool,
Expand All @@ -197,7 +201,7 @@ static inline void dynamic_pool_init(as_dynamic_pool *dynamic_pool,
* If the group table is full, the table is also expanded.
*
* @param dynamic_pool Pointer to a dynamic pool.
* @param error Pointer to an as_error
* @param err Pointer to an as_error
*
*/
static inline void dynamic_pool_add_group(as_dynamic_pool *dynamic_pool,
Expand All @@ -220,26 +224,30 @@ static inline void dynamic_pool_add_group(as_dynamic_pool *dynamic_pool,
*/
#define BYTE_POOL_INIT_NULL(dynamic_pool) \
(dynamic_pool)->byte_group_table = NULL;

/**
* Fetches the address of the next as_byte in the pool.
*
* @param map_bytes Pointer to an as_bytes.
* @param dynamic_pool Pointer to a dynamic pool.
* @param error Pointer to an as_error
* @param err Pointer to an as_error
*/
#define GET_BYTES_POOL(map_bytes, dynamic_pool, err) \
as_bytes **table = (dynamic_pool)->byte_group_table; \
if (table == NULL) { \
dynamic_pool_init(dynamic_pool, err); \
} \
else if ((dynamic_pool)->bytes_per_group <= (dynamic_pool)->byte_iterator) { \
dynamic_pool_add_group(dynamic_pool, err); \
} \
table = (dynamic_pool)->byte_group_table; \
uint16_t group_iterator = (dynamic_pool)->group_iterator; \
as_bytes *group = table[group_iterator]; \
uint16_t byte_iterator = (dynamic_pool)->byte_iterator++; \
map_bytes = &group[byte_iterator];
static inline as_bytes* GET_BYTES_POOL(as_dynamic_pool *dynamic_pool, as_error *err) {
as_bytes **table = dynamic_pool->byte_group_table;

if (table == NULL) {
dynamic_pool_init(dynamic_pool, err);
} else if (dynamic_pool->byte_iterator >= dynamic_pool->bytes_per_group) {
dynamic_pool_add_group(dynamic_pool, err);
}

table = dynamic_pool->byte_group_table;
uint16_t group_iterator = dynamic_pool->group_iterator;
as_bytes *group = table[group_iterator];
uint16_t byte_iterator = dynamic_pool->byte_iterator++;

return &group[byte_iterator];
}

/**
* Destroy the dynamic pool. Must be called before the dynamic_pool loses scope.
Expand All @@ -248,7 +256,9 @@ static inline void dynamic_pool_add_group(as_dynamic_pool *dynamic_pool,
* @param free_buffer boolean value determining if as_bytes_destroyed should be called.
* If the raw bytes array is heap allocated, free_buffer should be true.
*/
#define DESTROY_DYNAMIC_POOL(dynamic_pool, free_buffer) \
if ((dynamic_pool)->byte_group_table != NULL) { \
dynamic_pool_free_table(dynamic_pool, free_buffer); \
static inline void DESTROY_DYNAMIC_POOL(as_dynamic_pool *dynamic_pool, bool free_buffer) {
if (dynamic_pool->byte_group_table != NULL) {
dynamic_pool_free_table(dynamic_pool, free_buffer);
}
}

3 changes: 1 addition & 2 deletions src/include/expression_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@

as_status add_new_expr_op(AerospikeClient *self, as_error *err,
PyObject *op_dict, as_vector *unicodeStrVector,
as_operations *ops, long operation_code,
int serializer_type);
as_operations *ops, long operation_code);
3 changes: 1 addition & 2 deletions src/include/hll_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@
as_status add_new_hll_op(AerospikeClient *self, as_error *err,
PyObject *op_dict, as_vector *unicodeStrVector,
as_dynamic_pool *dynamic_pool, as_operations *ops,
long operation_code, long *ret_type,
int serializer_type);
long operation_code, long *ret_type);
2 changes: 1 addition & 1 deletion src/include/operate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
#include "exceptions.h"

as_status add_op(AerospikeClient *self, as_error *err, PyObject *py_val,
as_vector *unicodeStrVector, as_dynamic_pool *dynamic_pool,
as_vector *unicodeStrVector, as_dynamic_pool *dynamic_pool, bool destroy_buffers,
as_operations *ops, long *op, long *ret_type);
2 changes: 1 addition & 1 deletion src/include/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

enum Aerospike_serializer_values {
SERIALIZER_NONE, /* default handler for serializer type */
SERIALIZER_PYTHON,
SERIALIZER_PYTHON, /* Removed */
SERIALIZER_JSON,
SERIALIZER_USER,
};
Expand Down
8 changes: 5 additions & 3 deletions src/main/client/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "exceptions.h"
#include "policy.h"


/**
*******************************************************************************************************
* This function applies a registered udf module on a particular record.
Expand Down Expand Up @@ -70,6 +71,8 @@ PyObject *AerospikeClient_Apply_Invoke(AerospikeClient *self, PyObject *py_key,
// Initialisation flags
bool key_initialised = false;

bool destroy_buffers = false;

// Initialize error
as_error_init(&err);

Expand Down Expand Up @@ -102,10 +105,9 @@ PyObject *AerospikeClient_Apply_Invoke(AerospikeClient *self, PyObject *py_key,
// Key is initialiased successfully
key_initialised = true;

bool allocate_buffer = false;
// Convert python list to as_list
pyobject_to_list(self, &err, py_arglist, &arglist, &dynamic_pool,
SERIALIZER_PYTHON, allocate_buffer);
SERIALIZER_NONE, destroy_buffers);
if (err.code != AEROSPIKE_OK) {
goto CLEANUP;
}
Expand Down Expand Up @@ -169,7 +171,7 @@ PyObject *AerospikeClient_Apply_Invoke(AerospikeClient *self, PyObject *py_key,
}
as_list_destroy(arglist);
as_val_destroy(result);
DESTROY_DYNAMIC_POOL(&dynamic_pool, false);
DESTROY_DYNAMIC_POOL(&dynamic_pool, destroy_buffers);

if (err.code != AEROSPIKE_OK) {
raise_exception_base(&err, py_key, Py_None, py_module, py_function,
Expand Down
8 changes: 4 additions & 4 deletions src/main/client/batch_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ static PyObject *AerospikeClient_Batch_Apply_Invoke(
as_dynamic_pool dynamic_pool;
BYTE_POOL_INIT_NULL(&dynamic_pool);


bool destroy_buffers = false;

Py_ssize_t keys_size = PyList_Size(py_keys);

as_list *arglist = NULL;
Expand Down Expand Up @@ -200,10 +201,9 @@ static PyObject *AerospikeClient_Batch_Apply_Invoke(
const char *mod = PyUnicode_AsUTF8(py_mod);
const char *func = PyUnicode_AsUTF8(py_func);

bool allocate_buffer = false;

pyobject_to_list(self, err, py_args, &arglist, &dynamic_pool,
SERIALIZER_PYTHON, allocate_buffer);
SERIALIZER_NONE, destroy_buffers);
if (err->code != AEROSPIKE_OK) {
goto CLEANUP;
}
Expand Down Expand Up @@ -290,7 +290,7 @@ static PyObject *AerospikeClient_Batch_Apply_Invoke(
as_vector_destroy(tmp_keys_p);
}

DESTROY_DYNAMIC_POOL(&dynamic_pool, false);
DESTROY_DYNAMIC_POOL(&dynamic_pool, destroy_buffers);

if (err->code != AEROSPIKE_OK) {
raise_exception(err);
Expand Down
6 changes: 4 additions & 2 deletions src/main/client/batch_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ static PyObject *AerospikeClient_Batch_Operate_Invoke(
BYTE_POOL_INIT_NULL(&dynamic_pool);


bool destroy_buffers = false;

as_vector *tmp_keys_p = NULL;

as_operations ops;
Expand Down Expand Up @@ -170,7 +172,7 @@ static PyObject *AerospikeClient_Batch_Operate_Invoke(
goto CLEANUP;
}

if (add_op(self, err, py_val, unicodeStrVector, &dynamic_pool, &ops,
if (add_op(self, err, py_val, unicodeStrVector, &dynamic_pool, destroy_buffers, &ops,
&operation, &return_type) != AEROSPIKE_OK) {
goto CLEANUP;
}
Expand Down Expand Up @@ -312,7 +314,7 @@ static PyObject *AerospikeClient_Batch_Operate_Invoke(
as_vector_destroy(unicodeStrVector);
as_operations_destroy(&ops);
as_batch_destroy(&batch);
DESTROY_DYNAMIC_POOL(&dynamic_pool, false);
DESTROY_DYNAMIC_POOL(&dynamic_pool, destroy_buffers);

if (tmp_keys_p) {
as_vector_destroy(tmp_keys_p);
Expand Down
8 changes: 4 additions & 4 deletions src/main/client/batch_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ static PyObject *AerospikeClient_BatchWriteInvoke(AerospikeClient *self,
as_policy_batch *batch_policy_p = NULL;
as_exp exp_list;
as_exp *exp_list_p = NULL;
bool destroy_buffers = false;

PyObject *py_batch_type = NULL;
PyObject *py_key = NULL;
Expand Down Expand Up @@ -309,7 +310,7 @@ static PyObject *AerospikeClient_BatchWriteInvoke(AerospikeClient *self,
goto CLEANUP_ON_ERROR;
}

if (add_op(self, err, py_op, unicodeStrVector, &dynamic_pool,
if (add_op(self, err, py_op, unicodeStrVector, &dynamic_pool, destroy_buffers,
ops, &operation, &return_type) != AEROSPIKE_OK) {
goto CLEANUP_ON_ERROR;
}
Expand Down Expand Up @@ -402,9 +403,8 @@ static PyObject *AerospikeClient_BatchWriteInvoke(AerospikeClient *self,

as_list *arglist = NULL;

bool allocate_buffer = false;
pyobject_to_list(self, err, py_args, &arglist, &dynamic_pool,
SERIALIZER_PYTHON, allocate_buffer);
SERIALIZER_NONE, destroy_buffers);
if (err->code != AEROSPIKE_OK) {
Py_DECREF(py_args);
goto CLEANUP_ON_ERROR;
Expand Down Expand Up @@ -550,7 +550,7 @@ static PyObject *AerospikeClient_BatchWriteInvoke(AerospikeClient *self,

as_vector_destroy(unicodeStrVector);

DESTROY_DYNAMIC_POOL(&dynamic_pool, false);
DESTROY_DYNAMIC_POOL(&dynamic_pool, destroy_buffers);

if (exp_list_p != NULL) {
as_exp_destroy(exp_list_p);
Expand Down
Loading
Loading