AerospikeQuery * AerospikeQuery_Apply(AerospikeQuery * self, PyObject * args, PyObject * kwds) { // Python function arguments PyObject * py_module = NULL; PyObject * py_function = NULL; PyObject * py_args = NULL; PyObject * py_policy = NULL; PyObject * py_umodule = NULL; PyObject * py_ufunction = NULL; // Python function keyword arguments static char * kwlist[] = {"module", "function", "arguments", "policy", NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO:apply", kwlist, &py_module, &py_function, &py_args, &py_policy) == false ){ return NULL; } as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); // Aerospike error object as_error err; // Initialize error object as_error_init(&err); if ( !self || !self->client->as ){ as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid query object"); goto CLEANUP; } if (!self->client->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } self->client->is_client_put_serializer = false; // Aerospike API Arguments char * module = NULL; char * function = NULL; as_arraylist * arglist = NULL; if ( PyUnicode_Check(py_module) ){ py_umodule = PyUnicode_AsUTF8String(py_module); module = PyBytes_AsString(py_umodule); } else if ( PyString_Check(py_module) ) { module = PyString_AsString(py_module); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "udf module argument must be a string or unicode string"); goto CLEANUP; } if ( PyUnicode_Check(py_function) ){ py_ufunction = PyUnicode_AsUTF8String(py_function); function = PyBytes_AsString(py_ufunction); } else if ( PyString_Check(py_function) ) { function = PyString_AsString(py_function); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "udf function argument must be a string or unicode string"); goto CLEANUP; } if ( py_args && PyList_Check(py_args) ){ Py_ssize_t size = PyList_Size(py_args); arglist = as_arraylist_new(size, 0); for ( int i = 0; i < size; i++ ) { PyObject * py_val = PyList_GetItem(py_args, (Py_ssize_t)i); as_val * val = NULL; pyobject_to_val(self->client, &err, py_val, &val, &static_pool, SERIALIZER_PYTHON); if ( err.code != AEROSPIKE_OK ) { as_error_update(&err, err.code, NULL); goto CLEANUP; } else { as_arraylist_append(arglist, val); } } } Py_BEGIN_ALLOW_THREADS as_query_apply(&self->query, module, function, (as_list *) arglist); Py_END_ALLOW_THREADS CLEANUP: POOL_DESTROY(&static_pool); if (py_ufunction) { Py_DECREF(py_ufunction); } if (py_umodule) { Py_DECREF(py_umodule); } if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); 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); return NULL; } Py_INCREF(self); return self; }
int array_pool_destroy(void) { return POOL_DESTROY(array_t); }
/** ******************************************************************************************************* * This function will put record to the Aerospike DB. * * @param self AerospikeClient object * @param py_key The key under which to store the record. * @param py_bins The data to write to the Aerospike DB. * @param py_meta The meatadata for the record. * @param py_policy The dictionary of policies to be given while * reading a record. * * Returns an integer status. 0(Zero) is success value. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************* */ PyObject * AerospikeClient_Put_Invoke( AerospikeClient * self, PyObject * py_key, PyObject * py_bins, PyObject * py_meta, PyObject * py_policy, long serializer_option) { // Aerospike Client Arguments as_error err; as_policy_write write_policy; as_policy_write * write_policy_p = NULL; as_key key; as_record rec; // Initialisation flags bool key_initialised = false; bool record_initialised = false; // Initialize record as_record_init(&rec, 0); record_initialised = true; as_static_pool static_pool; memset(&static_pool, 0, sizeof(static_pool)); // Initialize error as_error_init(&err); if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python key object to as_key pyobject_to_key(&err, py_key, &key); if (err.code != AEROSPIKE_OK) { goto CLEANUP; } // Key is initialised successfully. key_initialised = true; // Convert python bins and metadata objects to as_record pyobject_to_record(self, &err, py_bins, py_meta, &rec, serializer_option, &static_pool); if (err.code != AEROSPIKE_OK) { goto CLEANUP; } // Convert python policy object to as_policy_write pyobject_to_policy_write(&err, py_policy, &write_policy, &write_policy_p, &self->as->config.policies.write); if (err.code != AEROSPIKE_OK) { goto CLEANUP; } // Invoke operation Py_BEGIN_ALLOW_THREADS aerospike_key_put(self->as, &err, write_policy_p, &key, &rec); Py_END_ALLOW_THREADS if (err.code != AEROSPIKE_OK) { as_error_update(&err, err.code, NULL); } CLEANUP: POOL_DESTROY(&static_pool); if (key_initialised == true) { // Destroy the key if it is initialised. as_key_destroy(&key); } if (record_initialised == true) { // Destroy the record if it is initialised. as_record_destroy(&rec); } // If an error occurred, tell Python. if (err.code != AEROSPIKE_OK) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&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_bins); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return PyLong_FromLong(0); }