Skip to content

Commit

Permalink
[CLIENT-3106] Refactor aerospike module initialization code and check…
Browse files Browse the repository at this point in the history
… if error indicator is set after every C-API call (#667)

- Consolidate the code that adds the aerospike's module constants into the same file and array
- Remove aerospike_log_level enum because an enum already exists in C client's "common" submodule
- Remove aerospike module state since the module itself already has the same members as Python attributes. There is no reason to store them twice as Python attributes and in the module state
  • Loading branch information
juliannguyen4 authored Sep 25, 2024
1 parent c0c805a commit 8ff0327
Show file tree
Hide file tree
Showing 12 changed files with 554 additions and 627 deletions.
20 changes: 0 additions & 20 deletions src/include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,13 @@
#include <Python.h>
#include <aerospike/as_status.h>

/*
* Enum to declare log level constants
*/
typedef enum Aerospike_log_level_e {

LOG_LEVEL_OFF = -1,
LOG_LEVEL_ERROR,
LOG_LEVEL_WARN,
LOG_LEVEL_INFO,
LOG_LEVEL_DEBUG,
LOG_LEVEL_TRACE

} aerospike_log_level;

/*
* Structure to hold user's log_callback object
*/
typedef struct Aerospike_log_callback {
PyObject *callback;
} AerospikeLogCallback;

/**
* Add log level constants to aerospike module
* aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
*/
as_status declare_log_constants(PyObject *aerospike);

/**
* Set log level for C-SDK
* aerospike.set_log_level( aerospike.LOG_LEVEL_WARN )
Expand Down
24 changes: 0 additions & 24 deletions src/include/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@
#include <aerospike/as_partition_filter.h>
#include <aerospike/as_metrics.h>

#define MAX_CONSTANT_STR_SIZE 512

/*
*******************************************************************************************************
*Structure to map constant number to constant name string for Aerospike constants.
*******************************************************************************************************
*/

enum Aerospike_serializer_values {
SERIALIZER_NONE, /* default handler for serializer type */
SERIALIZER_PYTHON,
Expand Down Expand Up @@ -193,20 +185,6 @@ enum aerospike_cdt_ctx_identifiers {
CDT_CTX_MAP_KEY_CREATE = 0x24
};

typedef struct Aerospike_Constants {
long constantno;
char constant_str[MAX_CONSTANT_STR_SIZE];
} AerospikeConstants;

typedef struct Aerospike_JobConstants {
char job_str[MAX_CONSTANT_STR_SIZE];
char exposed_job_str[MAX_CONSTANT_STR_SIZE];
} AerospikeJobConstants;
#define AEROSPIKE_CONSTANTS_ARR_SIZE \
(sizeof(aerospike_constants) / sizeof(AerospikeConstants))
#define AEROSPIKE_JOB_CONSTANTS_ARR_SIZE \
(sizeof(aerospike_job_constants) / sizeof(AerospikeJobConstants))

as_status pyobject_to_policy_admin(AerospikeClient *self, as_error *err,
PyObject *py_policy, as_policy_admin *policy,
as_policy_admin **policy_p,
Expand Down Expand Up @@ -270,8 +248,6 @@ as_status pyobject_to_policy_batch(AerospikeClient *self, as_error *err,
as_status pyobject_to_map_policy(as_error *err, PyObject *py_policy,
as_map_policy *policy);

as_status declare_policy_constants(PyObject *aerospike);

void set_scan_options(as_error *err, as_scan *scan_p, PyObject *py_options);

as_status set_query_options(as_error *err, PyObject *query_options,
Expand Down
3 changes: 3 additions & 0 deletions src/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <aerospike/as_operations.h>
#include "pool.h"

#define AEROSPIKE_MODULE_NAME "aerospike"
#define FULLY_QUALIFIED_TYPE_NAME(name) AEROSPIKE_MODULE_NAME "." name

// Bin names can be of type Unicode in Python
// DB supports 32767 maximum number of bins
#define MAX_UNICODE_OBJECTS 32767
Expand Down
Loading

0 comments on commit 8ff0327

Please sign in to comment.