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;
}
//------------------------------------------------
// Connect to database cluster, setting UDF
// configuration.
//
void
example_connect_to_aerospike_with_udf_config(aerospike* p_as,
		const char* lua_user_path)
{
	// Start with default configuration.
	as_config cfg;
	as_config_init(&cfg);

	// Must provide host and port. Example must have called example_get_opts()!
	cfg.hosts[0].addr = g_host;
	cfg.hosts[0].port = g_port;

	// Explicitly set Lua system path if it's not the default installation path
	// '/opt/aerospike/sys/udf/lua'
//	strcpy(cfg.lua.system_path, "/home/citrusleaf/aerospike-client-c/aerospike-mod-lua/src/lua");

	if (lua_user_path) {
		strcpy(cfg.lua.user_path, lua_user_path);
	}

	as_error err;

	// Connect to the Aerospike database cluster. Assume this is the first thing
	// done after calling example_get_opts(), so it's ok to exit on failure.
	if (aerospike_connect(aerospike_init(p_as, &cfg), &err) != AEROSPIKE_OK) {
		LOG("aerospike_connect() returned %d - %s", err.code, err.message);
		aerospike_destroy(p_as);
		exit(-1);
	}
}
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;
	}
}
Beispiel #4
0
		void AeroSpike::close()
		{
			std::unique_lock<std::mutex> lock(closeMutex_);
			if (triedConnect_) {
				aerospike_close(&connection_, &error_);

				aerospike_destroy(&connection_);

				triedConnect_ = false;
			}
		}
/**
 *******************************************************************************************************
 * 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;
}
Beispiel #6
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);
}
/**
 *******************************************************************************************************
 * 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;
}
//------------------------------------------------
// 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);
}
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 {
//------------------------------------------------
// Connect to database cluster, setting UDF
// configuration.
//
void
example_connect_to_aerospike_with_udf_config(aerospike* p_as,
		const char* lua_user_path)
{
	// Start with default configuration.
	as_config cfg;
	as_config_init(&cfg);
	as_config_add_host(&cfg, g_host, g_port);
	as_config_set_user(&cfg, g_user, g_password);

	// Examples can be run from client binary package-installed lua files or
	// from git client source tree lua files. If client binary package is not
	// installed, look for lua system files in client source tree.
	int rc = access(cfg.lua.system_path, R_OK);

	if (rc != 0) {
		// Use lua files in source tree if they exist.
		char* path = "../../../modules/lua-core/src";

		rc = access(path, R_OK);

		if (rc == 0) {
			strcpy(cfg.lua.system_path, path);
		}
	}

	if (lua_user_path) {
		strcpy(cfg.lua.user_path, lua_user_path);
	}

	aerospike_init(p_as, &cfg);

	as_error err;

	// Connect to the Aerospike database cluster. Assume this is the first thing
	// done after calling example_get_opts(), so it's ok to exit on failure.
	if (aerospike_connect(p_as, &err) != AEROSPIKE_OK) {
		LOG("aerospike_connect() returned %d - %s", err.code, err.message);
		aerospike_destroy(p_as);
		exit(-1);
	}
}
Beispiel #11
0
// ----------------------------------------------------------------------------------
//
// def initialize(host, port, options = {})
//
static void client_initialize(int argc, VALUE * argv, VALUE self) {
  rb_aero_TIMED(tm);

  VALUE host;
  VALUE port;
  VALUE options;

  rb_scan_args(argc, argv, "21", &host, &port, &options);

  if ( NIL_P(options) ) options = rb_hash_new();

  rb_iv_set(self, "@host", host);
  rb_iv_set(self, "@port", port);
  rb_iv_set(self, "@last_scan_id", Qnil);
  rb_iv_set(self, "@last_query_id", Qnil);

  as_config config;
  as_config_init(&config);
  as_config_add_host(&config, StringValueCStr(host), FIX2INT(port));

  options2config(&config, options, self);
  rb_iv_set(self, "@options", options);

  aerospike * as;
  Data_Get_Struct(self, aerospike, as);

  aerospike_init(as, &config);

  as_error err;
  if (aerospike_connect(as, &err) != AEROSPIKE_OK) {
    aerospike_destroy(as);
    raise_as_error(err);
  }

  as_log_set_level(AS_LOG_LEVEL_DEBUG);

  VALUE option_tmp = rb_hash_aref(options, c_log_sym);

  if ( TYPE(option_tmp) == T_TRUE ) {
    as_log_set_callback(rb_aero_log_callback);
  }
}
Beispiel #12
0
bool asc_init(aerospike *p_as)
{
    as_status status;
    as_error err;

    // Start with default configuration.
    as_config cfg;
    as_config_init(&cfg);
    as_config_add_host(&cfg, HOST, PORT);
    as_config_set_user(&cfg, USER, PASS);
    aerospike_init(p_as, &cfg);

    // Connect to the Aerospike database cluster.
    status = aerospike_connect(p_as, &err);
    if (status != AEROSPIKE_OK) {
        ERROR("aerospike_connect() returned %d - %s", err.code, err.message);
        aerospike_destroy(p_as);
    }

    return (status == AEROSPIKE_OK);
}