Ejemplo n.º 1
0
static bool after(atf_plan * plan) {

    if ( ! as ) {
        error("aerospike was not initialized");
        return false;
    }

	as_error err;
	as_error_reset(&err);
	
	if ( aerospike_close(as, &err) == AEROSPIKE_OK ) {
		info("disconnected from %s:%d", g_host, g_port);
		aerospike_destroy(as);

    	return true;
	}
	else {
		error("%s @ %s[%s:%d]", g_host, g_port, err.message, err.func, err.file, err.line);
		aerospike_destroy(as);

		return false;
	}
	
    return true;
}
static bool after(atf_plan * plan) {

    if ( ! as ) {
        error("aerospike was not initialized");
        return false;
    }
	
	as_error err;
	as_error_reset(&err);
	
	as_status status = aerospike_close(as, &err);
	aerospike_destroy(as);

	if (g_use_async) {
		as_event_close_loops();
	}

	if (status == AEROSPIKE_OK) {
		debug("disconnected from %s:%d", g_host, g_port);
		return true;
	}
	else {
		error("%s @ %s[%s:%d]", g_host, g_port, err.message, err.func, err.file, err.line);
		return false;
	}
}
Ejemplo n.º 3
0
static int disconnect(lua_State *L){
	aerospike* as = lua_touserdata(L, 1);
	as_error err;
	aerospike_close(as, &err);
	lua_pushnumber(L, err.code);
	lua_pushstring(L, err.message);
	return 2;
}
Ejemplo n.º 4
0
		void AeroSpike::close()
		{
			std::unique_lock<std::mutex> lock(closeMutex_);
			if (triedConnect_) {
				aerospike_close(&connection_, &error_);

				aerospike_destroy(&connection_);

				triedConnect_ = false;
			}
		}
Ejemplo n.º 5
0
/**
 *******************************************************************************************************
 * Closes already opened connection to the database.
 *
 * @param self                  AerospikeClient object
 * @param args                  The args is a tuple object containing an argument
 *                              list passed from Python to a C function
 * @param kwds                  Dictionary of keywords
 *
 * Returns None.
 * In case of error,appropriate exceptions will be raised.
 *******************************************************************************************************
 */
PyObject * AerospikeClient_Close(AerospikeClient * self, PyObject * args, PyObject * kwds)
{
	as_error err;

	// 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;
	}

	aerospike_close(self->as, &err);

	if ( err.code != AEROSPIKE_OK ) {
		PyObject * py_err = NULL;
		error_to_pyobject(&err, &py_err);
		PyObject *exception_type = raise_exception(&err);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		return NULL;
	}
	self->is_conn_16 = false;

	/*
	 * Need to free memory allocated to host address string
	 * in AerospikeClient_Type_Init.
	 */ 
	for( int i = 0; i < self->as->config.hosts_size; i++) {
		free(self->as->config.hosts[i].addr);
	}

	aerospike_destroy(self->as);
	self->as = NULL;

	Py_INCREF(Py_None);
CLEANUP:
	if ( err.code != AEROSPIKE_OK ) {
		PyObject * py_err = NULL;
		error_to_pyobject(&err, &py_err);
		PyObject *exception_type = raise_exception(&err);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		return NULL;
	}
	return Py_None;
}
Ejemplo n.º 6
0
// ----------------------------------------------------------------------------------
//
// closes connection to the cluster
//
// def close
//
//  ------
//  RETURN:
//    1. self
//
static VALUE close_connection(VALUE self) {
  rb_aero_TIMED(tm);

  as_error err;
  aerospike * as = rb_aero_CLIENT;

  if ( aerospike_close(as, &err) != AEROSPIKE_OK )  {
    raise_as_error(err);
  }

  rb_aero_logger(AS_LOG_LEVEL_DEBUG, &tm, 1, rb_str_new2("[Client][close] success"));

  return self;
}
Ejemplo n.º 7
0
bool asc_exit(aerospike *p_as)
{
    as_status status;
    as_error err;

    // Disconnect from the database cluster and clean up the aerospike object.
    status = aerospike_close(p_as, &err);
    if (status != AEROSPIKE_OK) {
        ERROR("aerospike_close() returned %d - %s", err.code, err.message);
    }
    aerospike_destroy(p_as);

    return (status == AEROSPIKE_OK);
}
Ejemplo n.º 8
0
/**
 *******************************************************************************************************
 * Closes already opened connection to the database.
 *
 * @param self                  AerospikeClient object
 * @param args                  The args is a tuple object containing an argument
 *                              list passed from Python to a C function
 * @param kwds                  Dictionary of keywords
 *
 * Returns None.
 * In case of error,appropriate exceptions will be raised.
 *******************************************************************************************************
 */
PyObject * AerospikeClient_Close(AerospikeClient * self, PyObject * args, PyObject * kwds)
{
	as_error err;
	char *alias_to_search = NULL;

	// Initialize error
	as_error_init(&err);

	if (!self || !self->as) {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
		goto CLEANUP;
	}

	alias_to_search = return_search_string(self->as);
	PyObject *py_persistent_item = NULL;

	py_persistent_item = PyDict_GetItemString(py_global_hosts, alias_to_search); 
	if (py_persistent_item) {
		close_aerospike_object(self->as, &err, alias_to_search, py_persistent_item);
	} else {
		aerospike_close(self->as, &err);

		for (unsigned int i = 0; i < self->as->config.hosts_size; i++) {
			free((void *) self->as->config.hosts[i].addr);
		}

		Py_BEGIN_ALLOW_THREADS
		aerospike_destroy(self->as);
		Py_END_ALLOW_THREADS
	}
	self->is_conn_16 = false;
	self->as = NULL;
	PyMem_Free(alias_to_search);
	alias_to_search = NULL;

	Py_INCREF(Py_None);

CLEANUP:
	if ( err.code != AEROSPIKE_OK ) {
		PyObject * py_err = NULL;
		error_to_pyobject(&err, &py_err);
		PyObject *exception_type = raise_exception(&err);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		return NULL;
	}
	return Py_None;
}
Ejemplo n.º 9
0
//------------------------------------------------
// Remove the test record from database, and
// disconnect from cluster.
//
void
example_cleanup(aerospike* p_as)
{
	// Clean up the database. Note that with database "storage-engine device"
	// configurations, this record may come back to life if the server is re-
	// started. That's why examples that want to start clean remove the test
	// record at the beginning.
	example_remove_test_record(p_as);

	// Note also example_remove_test_records() is not called here - examples
	// using multiple records call that from their own cleanup utilities.

	as_error err;

	// Disconnect from the database cluster and clean up the aerospike object.
	aerospike_close(p_as, &err);
	aerospike_destroy(p_as);
}
Ejemplo n.º 10
0
void close_aerospike_object(aerospike *as, as_error *err, char *alias_to_search, PyObject *py_persistent_item)
{
		if (((AerospikeGlobalHosts*)py_persistent_item)->ref_cnt == 1) {
			PyDict_DelItemString(py_global_hosts, alias_to_search);
			AerospikeGlobalHosts_Del(py_persistent_item);
			aerospike_close(as, err);

			/*
			* Need to free memory allocated to host address string
			* in AerospikeClient_Type_Init.
			*/
			for( int i = 0; i < (int)as->config.hosts_size; i++) {
				free((void *) as->config.hosts[i].addr);
			}

			Py_BEGIN_ALLOW_THREADS
			aerospike_destroy(as);
			Py_END_ALLOW_THREADS
		} else {