Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLIENT-3106] aerospike.exception: create a Python dict that maps as_status error codes to Aerospike exception classes to speed up raising exceptions #663

Draft
wants to merge 29 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d10c6bc
rebase
juliannguyen4 Sep 9, 2024
f86e28e
wip not done
juliannguyen4 Sep 10, 2024
b20c519
rm unused header file
juliannguyen4 Sep 11, 2024
294a6ef
wip
juliannguyen4 Sep 11, 2024
74c216b
wip
juliannguyen4 Sep 11, 2024
b2e48df
finish
juliannguyen4 Sep 12, 2024
e21ff59
fix
juliannguyen4 Sep 12, 2024
c7b52d0
fix
juliannguyen4 Sep 12, 2024
ec6dc22
Fix
juliannguyen4 Sep 12, 2024
3a55e3b
temp
juliannguyen4 Sep 12, 2024
54c0f05
fix
juliannguyen4 Sep 12, 2024
9019d3c
fix
juliannguyen4 Sep 12, 2024
f7f3bd7
fix for now
juliannguyen4 Sep 12, 2024
b7a31b1
remove error_to_pyobject
juliannguyen4 Sep 12, 2024
67d4ecc
fix
juliannguyen4 Sep 12, 2024
0ea5bf1
add err checking
juliannguyen4 Sep 12, 2024
42b4886
Fix ref count error
juliannguyen4 Sep 12, 2024
71b92a0
set exc class attrs
juliannguyen4 Sep 12, 2024
de7e870
Clear exception that was found when checking for error code
juliannguyen4 Sep 13, 2024
b1925bf
slight refactoring
juliannguyen4 Sep 13, 2024
d1ecbb8
Merge remote-tracking branch 'origin/dev' into CLIENT-3106-map-err-co…
juliannguyen4 Sep 16, 2024
957cf69
Merge remote-tracking branch 'origin/dev' into CLIENT-3106-map-err-co…
juliannguyen4 Sep 16, 2024
8705e5a
Merge remote-tracking branch 'origin/dev' into CLIENT-3106-map-err-co…
juliannguyen4 Sep 17, 2024
669bd2e
wip
juliannguyen4 Sep 17, 2024
293bfd9
revert
juliannguyen4 Sep 17, 2024
01f59f3
rm todos and warn when codepath shouldnt execute
juliannguyen4 Sep 17, 2024
499a524
fix
juliannguyen4 Sep 17, 2024
10e7532
rm bad comment
juliannguyen4 Sep 17, 2024
cbe2967
refactor
juliannguyen4 Sep 18, 2024
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: 0 additions & 2 deletions src/include/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ as_status bins_to_pyobject(AerospikeClient *self, as_error *err,
const as_record *rec, PyObject **obj,
bool cnvt_list_to_map);

void error_to_pyobject(const as_error *err, PyObject **obj);

as_status pyobject_to_astype_write(AerospikeClient *self, as_error *err,
PyObject *py_value, as_val **val,
as_static_pool *static_pool,
Expand Down
152 changes: 0 additions & 152 deletions src/include/exception_types.h

This file was deleted.

10 changes: 8 additions & 2 deletions src/include/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@

#include <Python.h>

typedef struct {
const char *attr_name;
PyObject *py_value;
} as_exc_extra_info;

PyObject *AerospikeException_New(void);
void raise_exception(as_error *err);
PyObject *raise_exception_old(as_error *err);
int raise_exception(as_error *err);
int raise_exception_with_api_call_extra_info(as_error *err,
as_exc_extra_info *extra_info);
void remove_exception(as_error *err);
23 changes: 6 additions & 17 deletions src/main/client/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,12 @@ PyObject *AerospikeClient_Apply_Invoke(AerospikeClient *self, PyObject *py_key,
as_val_destroy(result);

if (err.code != AEROSPIKE_OK) {
PyObject *py_err = NULL;
error_to_pyobject(&err, &py_err);
PyObject *exception_type = raise_exception_old(&err);
if (PyObject_HasAttrString(exception_type, "key")) {
PyObject_SetAttrString(exception_type, "key", py_key);
}
if (PyObject_HasAttrString(exception_type, "bin")) {
PyObject_SetAttrString(exception_type, "bin", Py_None);
}
if (PyObject_HasAttrString(exception_type, "module")) {
PyObject_SetAttrString(exception_type, "module", py_module);
}
if (PyObject_HasAttrString(exception_type, "func")) {
PyObject_SetAttrString(exception_type, "func", py_function);
}
PyErr_SetObject(exception_type, py_err);
Py_DECREF(py_err);
as_exc_extra_info extra_info[] = {{"key", py_key},
{"bin", Py_None},
{"module", py_module},
{"func", py_function},
{0}};
raise_exception_with_api_call_extra_info(&err, extra_info);
return NULL;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/client/batch_get_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ static bool batch_read_operate_cb(const as_batch_read *results, uint32_t n,
bins_to_pyobject(data->client, &err, rec, &py_rec_bins, false);
}
else {
py_rec_meta = raise_exception_old(&err);
// TODO: for now just ignore error code
raise_exception(&err);
Py_INCREF(Py_None);
py_rec_bins = Py_None;
}
Expand Down
14 changes: 3 additions & 11 deletions src/main/client/exists.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,9 @@ extern PyObject *AerospikeClient_Exists_Invoke(AerospikeClient *self,
}

if (err.code != AEROSPIKE_OK) {
PyObject *py_err = NULL;
error_to_pyobject(&err, &py_err);
PyObject *exception_type = raise_exception_old(&err);
if (PyObject_HasAttrString(exception_type, "key")) {
PyObject_SetAttrString(exception_type, "key", py_key);
}
if (PyObject_HasAttrString(exception_type, "bin")) {
PyObject_SetAttrString(exception_type, "bin", Py_None);
}
PyErr_SetObject(exception_type, py_err);
Py_DECREF(py_err);
as_exc_extra_info extra_info[] = {
{"key", py_key}, {"bin", Py_None}, {0}};
raise_exception_with_api_call_extra_info(&err, extra_info);
}

return py_result;
Expand Down
14 changes: 3 additions & 11 deletions src/main/client/exists_many.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,9 @@ static PyObject *AerospikeClient_Exists_Many_Invoke(AerospikeClient *self,
}

if (err.code != AEROSPIKE_OK) {
PyObject *py_err = NULL;
error_to_pyobject(&err, &py_err);
PyObject *exception_type = raise_exception_old(&err);
if (PyObject_HasAttrString(exception_type, "key")) {
PyObject_SetAttrString(exception_type, "key", py_keys);
}
if (PyObject_HasAttrString(exception_type, "bin")) {
PyObject_SetAttrString(exception_type, "bin", Py_None);
}
PyErr_SetObject(exception_type, py_err);
Py_DECREF(py_err);
as_exc_extra_info extra_info[] = {
{"key", py_keys}, {"bin", Py_None}, {0}};
raise_exception_with_api_call_extra_info(&err, extra_info);
return NULL;
}

Expand Down
14 changes: 3 additions & 11 deletions src/main/client/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,9 @@ PyObject *AerospikeClient_Get_Invoke(AerospikeClient *self, PyObject *py_key,
}

if (err.code != AEROSPIKE_OK) {
PyObject *py_err = NULL;
error_to_pyobject(&err, &py_err);
PyObject *exception_type = raise_exception_old(&err);
if (PyObject_HasAttrString(exception_type, "key")) {
PyObject_SetAttrString(exception_type, "key", py_key);
}
if (PyObject_HasAttrString(exception_type, "bin")) {
PyObject_SetAttrString(exception_type, "bin", Py_None);
}
PyErr_SetObject(exception_type, py_err);
Py_DECREF(py_err);
as_exc_extra_info extra_info[] = {
{"key", py_key}, {"bin", Py_None}, {0}};
raise_exception_with_api_call_extra_info(&err, extra_info);
return NULL;
}

Expand Down
14 changes: 3 additions & 11 deletions src/main/client/get_many.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,9 @@ static PyObject *AerospikeClient_Get_Many_Invoke(AerospikeClient *self,
}

if (err.code != AEROSPIKE_OK) {
PyObject *py_err = NULL;
error_to_pyobject(&err, &py_err);
PyObject *exception_type = raise_exception_old(&err);
if (PyObject_HasAttrString(exception_type, "key")) {
PyObject_SetAttrString(exception_type, "key", py_keys);
}
if (PyObject_HasAttrString(exception_type, "bin")) {
PyObject_SetAttrString(exception_type, "bin", Py_None);
}
PyErr_SetObject(exception_type, py_err);
Py_DECREF(py_err);
as_exc_extra_info extra_info[] = {
{"key", py_keys}, {"bin", Py_None}, {0}};
raise_exception_with_api_call_extra_info(&err, extra_info);
return NULL;
}

Expand Down
37 changes: 13 additions & 24 deletions src/main/client/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,21 @@ static bool AerospikeClient_InfoAll_each(as_error *err, const as_node *node,
Py_DECREF(py_res);

CLEANUP:
if (udata_ptr->error.code != AEROSPIKE_OK) {
PyObject *py_err = NULL;
error_to_pyobject(&udata_ptr->error, &py_err);
PyObject *exception_type = raise_exception_old(&udata_ptr->error);
PyErr_SetObject(exception_type, py_err);
Py_DECREF(py_err);
PyGILState_Release(gil_state);
return false;
}
if (err->code != AEROSPIKE_OK) {
PyObject *py_err = NULL;
error_to_pyobject(err, &py_err);
PyObject *exception_type = raise_exception_old(err);
PyErr_SetObject(exception_type, py_err);
Py_DECREF(py_err);
PyGILState_Release(gil_state);
return false;
bool result = true;
if (udata_ptr->error.code != AEROSPIKE_OK || err->code != AEROSPIKE_OK) {
as_error *error;
if (udata_ptr->error.code != AEROSPIKE_OK) {
error = &udata_ptr->error;
}
else {
error = err;
}
raise_exception(error);
result = false;
}

PyGILState_Release(gil_state);
return true;
return result;
}

/**
Expand Down Expand Up @@ -209,12 +203,7 @@ static PyObject *AerospikeClient_InfoAll_Invoke(AerospikeClient *self,
Py_DECREF(py_ustr);
}
if (info_callback_udata.error.code != AEROSPIKE_OK) {
PyObject *py_err = NULL;
error_to_pyobject(&info_callback_udata.error, &py_err);
PyObject *exception_type =
raise_exception_old(&info_callback_udata.error);
PyErr_SetObject(exception_type, py_err);
Py_DECREF(py_err);
raise_exception(&info_callback_udata.error);
if (py_nodes) {
Py_DECREF(py_nodes);
}
Expand Down
24 changes: 5 additions & 19 deletions src/main/client/operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,9 @@ static inline bool isExprOp(int op);

#define EXCEPTION_ON_ERROR() \
if (err.code != AEROSPIKE_OK) { \
PyObject *py_err = NULL; \
error_to_pyobject(&err, &py_err); \
PyObject *exception_type = raise_exception_old(&err); \
if (PyObject_HasAttrString(exception_type, "key")) { \
PyObject_SetAttrString(exception_type, "key", py_key); \
} \
if (PyObject_HasAttrString(exception_type, "bin")) { \
PyObject_SetAttrString(exception_type, "bin", py_bin); \
} \
PyErr_SetObject(exception_type, py_err); \
Py_DECREF(py_err); \
as_exc_extra_info extra_info[] = { \
{"key", py_key}, {"bin", py_bin}, {0}}; \
raise_exception_with_api_call_extra_info(&err, extra_info); \
return NULL; \
}

Expand Down Expand Up @@ -1203,14 +1195,8 @@ PyObject *AerospikeClient_OperateOrdered(AerospikeClient *self, PyObject *args,

CLEANUP:
if (err.code != AEROSPIKE_OK) {
PyObject *py_err = NULL;
error_to_pyobject(&err, &py_err);
PyObject *exception_type = raise_exception_old(&err);
if (PyObject_HasAttrString(exception_type, "key")) {
PyObject_SetAttrString(exception_type, "key", py_key);
}
PyErr_SetObject(exception_type, py_err);
Py_DECREF(py_err);
as_exc_extra_info extra_info[] = {{"key", py_key}, {0}};
raise_exception_with_api_call_extra_info(&err, extra_info);
return NULL;
}
return py_result;
Expand Down
Loading
Loading