as_config * as_config_init(as_config * c) { c->ip_map = 0; c->ip_map_size = 0; c->max_threads = 300; c->async_max_conns_per_node = 300; c->pipe_max_conns_per_node = 64; c->max_socket_idle_sec = 55; c->conn_timeout_ms = 1000; c->tender_interval = 1000; c->use_services_alternate = false; c->thread_pool_size = 16; c->hosts_size = 0; memset(c->user, 0, sizeof(c->user)); memset(c->password, 0, sizeof(c->password)); memset(c->hosts, 0, sizeof(c->hosts)); as_policies_init(&c->policies); c->lua.cache_enabled = MOD_LUA_CACHE_ENABLED; strcpy(c->lua.system_path, AS_CONFIG_LUA_SYSTEM_PATH); strcpy(c->lua.user_path, AS_CONFIG_LUA_USER_PATH); c->fail_if_not_connected = true; c->use_shm = false; c->shm_key = 0xA5000000; c->shm_max_nodes = 16; c->shm_max_namespaces = 8; c->shm_takeover_threshold_sec = 30; return c; }
static bool before(atf_plan * plan) { if ( as ) { error("aerospike was already initialized"); return false; } // Initialize logging. as_log_set_level(AS_LOG_LEVEL_INFO); as_log_set_callback(as_client_log_callback); if (g_use_async) { if (as_event_create_loops(1) == 0) { error("failed to create event loops"); return false; } } // Initialize global lua configuration. as_config_lua lua; as_config_lua_init(&lua); strcpy(lua.system_path, "modules/lua-core/src"); strcpy(lua.user_path, "src/test/lua"); aerospike_init_lua(&lua); // Initialize cluster configuration. as_config config; as_config_init(&config); as_config_add_host(&config, g_host, g_port); as_config_set_user(&config, g_user, g_password); as_policies_init(&config.policies); as_error err; as_error_reset(&err); as = aerospike_new(&config); if ( aerospike_connect(as, &err) == AEROSPIKE_OK ) { debug("connected to %s:%d", g_host, g_port); return true; } else { error("%s @ %s[%s:%d]", err.message, err.func, err.file, err.line); return false; } }
static bool before(atf_plan * plan) { if ( as ) { error("aerospike was already initialized"); return false; } if (! parse_opts(g_argc, g_argv)) { error("failed to parse options"); return false; } as_log_set_level(AS_LOG_LEVEL_INFO); as_log_set_callback(as_client_log_callback); if (g_use_async) { if (as_event_create_loops(1) == 0) { error("failed to create event loops"); return false; } } as_config config; as_config_init(&config); as_config_add_host(&config, g_host, g_port); as_config_set_user(&config, g_user, g_password); config.lua.cache_enabled = false; strcpy(config.lua.system_path, "modules/lua-core/src"); strcpy(config.lua.user_path, "src/test/lua"); as_policies_init(&config.policies); as_error err; as_error_reset(&err); as = aerospike_new(&config); if ( aerospike_connect(as, &err) == AEROSPIKE_OK ) { debug("connected to %s:%d", g_host, g_port); return true; } else { error("%s @ %s[%s:%d]", err.message, err.func, err.file, err.line); return false; } }
as_config * as_config_init(as_config * c) { c->ip_map = 0; c->ip_map_size = 0; c->max_threads = 300; c->max_socket_idle_sec = 14; c->conn_timeout_ms = 1000; c->tender_interval = 1000; c->hosts_size = 0; memset(c->user, 0, sizeof(c->user)); memset(c->password, 0, sizeof(c->password)); memset(c->hosts, 0, sizeof(c->hosts)); as_policies_init(&c->policies); c->lua.cache_enabled = MOD_LUA_CACHE_ENABLED; strcpy(c->lua.system_path, AS_CONFIG_LUA_SYSTEM_PATH); strcpy(c->lua.user_path, AS_CONFIG_LUA_USER_PATH); c->fail_if_not_connected = true; return c; }
static int AerospikeClient_Type_Init(AerospikeClient * self, PyObject * args, PyObject * kwds) { PyObject * py_config = NULL; static char * kwlist[] = {"config", NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwds, "O:client", kwlist, &py_config) == false ) { return -1; } if ( ! PyDict_Check(py_config) ) { return -1; } as_config config; as_config_init(&config); bool lua_system_path = FALSE; bool lua_user_path = FALSE; PyObject * py_lua = PyDict_GetItemString(py_config, "lua"); if ( py_lua && PyDict_Check(py_lua) ) { PyObject * py_lua_system_path = PyDict_GetItemString(py_lua, "system_path"); if ( py_lua_system_path && PyString_Check(py_lua_system_path) ) { lua_system_path = TRUE; memcpy(config.lua.system_path, PyString_AsString(py_lua_system_path), AS_CONFIG_PATH_MAX_LEN); } PyObject * py_lua_user_path = PyDict_GetItemString(py_lua, "user_path"); if ( py_lua_user_path && PyString_Check(py_lua_user_path) ) { lua_user_path = TRUE; memcpy(config.lua.user_path, PyString_AsString(py_lua_user_path), AS_CONFIG_PATH_MAX_LEN); } } if ( ! lua_system_path ) { PyObject * py_prefix = PySys_GetObject("prefix"); if ( py_prefix && PyString_Check(py_prefix) ) { char * prefix = PyString_AsString(py_prefix); size_t prefix_len = strlen(prefix); char system_path[AS_CONFIG_PATH_MAX_LEN] = {0}; memcpy(system_path, prefix, strlen(prefix)); memcpy(system_path + prefix_len, "/aerospike/lua", AS_CONFIG_PATH_MAX_LEN - prefix_len); system_path[prefix_len + strlen("/aerospike/lua")] = '\0'; struct stat info; if( stat( system_path, &info ) == 0 && (info.st_mode & S_IFDIR) ) { memcpy(config.lua.system_path, system_path, AS_CONFIG_PATH_MAX_LEN); } else { memcpy(system_path + prefix_len, "/local/aerospike/lua", AS_CONFIG_PATH_MAX_LEN - prefix_len); system_path[prefix_len + strlen("/local/aerospike/lua")] = '\0'; if( stat( system_path, &info ) == 0 && (info.st_mode & S_IFDIR) ) { memcpy(config.lua.system_path, system_path, AS_CONFIG_PATH_MAX_LEN); } else { config.lua.system_path[0] = '\0'; } } } } if ( ! lua_user_path ) { memcpy(config.lua.user_path, ".", AS_CONFIG_PATH_MAX_LEN); } PyObject * py_hosts = PyDict_GetItemString(py_config, "hosts"); if ( py_hosts && PyList_Check(py_hosts) ) { int size = (int) PyList_Size(py_hosts); for ( int i = 0; i < size && i < AS_CONFIG_HOSTS_SIZE; i++ ) { char *addr = NULL; uint16_t port = 3000; PyObject * py_host = PyList_GetItem(py_hosts, i); PyObject * py_addr, * py_port; if( PyTuple_Check(py_host) && PyTuple_Size(py_host) == 2) { py_addr = PyTuple_GetItem(py_host, 0); if(PyString_Check(py_addr)) { addr = strdup(PyString_AsString(py_addr)); } py_port = PyTuple_GetItem(py_host,1); if( PyInt_Check(py_port) || PyLong_Check(py_port) ) { port = (uint16_t) PyLong_AsLong(py_port); } else { port = 0; } } else if ( PyString_Check(py_host) ) { addr = strdup( strtok( PyString_AsString(py_host), ":" ) ); addr = strtok(addr, ":"); char *temp = strtok(NULL, ":"); if(NULL != temp) { port = (uint16_t)atoi(temp); } } as_config_add_host(&config, addr, port); } } PyObject * py_shm = PyDict_GetItemString(py_config, "shm"); if (py_shm && PyDict_Check(py_shm) ) { config.use_shm = true; PyObject * py_shm_max_nodes = PyDict_GetItemString( py_shm, "shm_max_nodes" ); if(py_shm_max_nodes && PyInt_Check(py_shm_max_nodes) ) { config.shm_max_nodes = PyInt_AsLong(py_shm_max_nodes); } PyObject * py_shm_max_namespaces = PyDict_GetItemString(py_shm, "shm_max_namespaces"); if(py_shm_max_namespaces && PyInt_Check(py_shm_max_namespaces) ) { config.shm_max_namespaces = PyInt_AsLong(py_shm_max_namespaces); } PyObject* py_shm_takeover_threshold_sec = PyDict_GetItemString(py_shm, "shm_takeover_threshold_sec"); if(py_shm_takeover_threshold_sec && PyInt_Check(py_shm_takeover_threshold_sec) ) { config.shm_takeover_threshold_sec = PyInt_AsLong( py_shm_takeover_threshold_sec); } } self->is_client_put_serializer = false; self->user_serializer_call_info.callback = NULL; self->user_deserializer_call_info.callback = NULL; PyObject *py_serializer_option = PyDict_GetItemString(py_config, "serialization"); if (py_serializer_option && PyTuple_Check(py_serializer_option)) { PyObject *py_serializer = PyTuple_GetItem(py_serializer_option, 0); if (py_serializer && py_serializer != Py_None) { if (!PyCallable_Check(py_serializer)) { return -1; } memset(&self->user_serializer_call_info, 0, sizeof(self->user_serializer_call_info)); self->user_serializer_call_info.callback = py_serializer; } PyObject *py_deserializer = PyTuple_GetItem(py_serializer_option, 1); if (py_deserializer && py_deserializer != Py_None) { if (!PyCallable_Check(py_deserializer)) { return -1; } memset(&self->user_deserializer_call_info, 0, sizeof(self->user_deserializer_call_info)); self->user_deserializer_call_info.callback = py_deserializer; } } as_policies_init(&config.policies); PyObject * py_policies = PyDict_GetItemString(py_config, "policies"); if ( py_policies && PyDict_Check(py_policies)) { //global defaults setting PyObject * py_key_policy = PyDict_GetItemString(py_policies, "key"); if ( py_key_policy && PyInt_Check(py_key_policy) ) { config.policies.key = PyInt_AsLong(py_key_policy); } PyObject * py_timeout = PyDict_GetItemString(py_policies, "timeout"); if ( py_timeout && PyInt_Check(py_timeout) ) { config.policies.timeout = PyInt_AsLong(py_timeout); } PyObject * py_retry = PyDict_GetItemString(py_policies, "retry"); if ( py_retry && PyInt_Check(py_retry) ) { config.policies.retry = PyInt_AsLong(py_retry); } PyObject * py_exists = PyDict_GetItemString(py_policies, "exists"); if ( py_exists && PyInt_Check(py_exists) ) { config.policies.exists = PyInt_AsLong(py_exists); } PyObject * py_replica = PyDict_GetItemString(py_policies, "replica"); if ( py_replica && PyInt_Check(py_replica) ) { config.policies.replica = PyInt_AsLong(py_replica); } PyObject * py_consistency_level = PyDict_GetItemString(py_policies, "consistency_level"); if ( py_consistency_level && PyInt_Check(py_consistency_level) ) { config.policies.consistency_level = PyInt_AsLong(py_consistency_level); } PyObject * py_commit_level = PyDict_GetItemString(py_policies, "commit_level"); if ( py_commit_level && PyInt_Check(py_commit_level) ) { config.policies.commit_level = PyInt_AsLong(py_commit_level); } /* * Generation policy is removed from constructor. */ } //conn_timeout_ms PyObject * py_connect_timeout = PyDict_GetItemString(py_config, "connect_timeout"); if ( py_connect_timeout && PyInt_Check(py_connect_timeout) ) { config.conn_timeout_ms = PyInt_AsLong(py_connect_timeout); } self->as = aerospike_new(&config); return 0; }