我有一个DEV盒,我试图通过端口9042连接到我的STAGING Cassandra服务器,因为我使用的是新的二进制协议。我使用libcql library
为卡桑德拉DEV机器上运行我的C++代码..连接到分级Cassandra服务器时,CQL SELECT查询会被挂起吗?
但不知何故,我想,我能够做我的临时卡桑德拉服务器端口9042作为Connected Successfully
的连接被打印出来..
下面是我的头文件中的代码我有 -
static cql_client_t* client;
shared_future<cql_future_connection_t> connect_future;
const string server = "sc-host01.vip.slc.qa.host.com"; //"localhost";
//Open the connection
void connection_open() {
connect_future = client->connect(server, 9042);
cout<<"Connected Successfully"<< endl;
connect_future.wait();
}
//Execute a Query
cql_result_t& execute_query(string query) {
bool error = false;
cql_result_t* result=NULL;
try{
if (!connect_future.get().error.is_err()) {
cout << "query " << query << endl;
shared_future<cql_future_result_t> future = client->query(query,CQL_CONSISTENCY_ONE);
future.wait();
error = future.get().error.is_err();
result = &*future.get().result;
} else{
cout << "Query status... " << (!error ? "true" : "false") << std::endl;
}
}catch (int e){
cout << "An exception occurred when executing query. " << e << endl;
}
return *result;
}
#endif
,下面将我在.cc file
这会令使用上述类的连接..然后执行查询以及代码。
/**
* This method will retrieve the data from Cassandra..
* And then call print_rows method to print it out on the console
*/
void get_attributes(string id){
try{
// some code
cout << "id " << id << endl;
//Connection open
connection_open();
execute_query("USE profileks;");
//this will give me the result back of the select query
cql_result_t& result = execute_query("select * from profile_user where key ='"+id+"';");
// and this is printing it out on the console
print_rows(result);
// some code
} catch (int e){
// some code here
}
}
现在我面临的问题是它没有返回我任何结果回来。它被以某种方式上的选择查询上吊 -
这是我看到我的控制台上 -
id 1
Connected Successfully
query USE profileks;
query select record_name, record_value from user_data where user_id ='1';
连带后上吊,这意味着它没有返回我的任何结果回来......但是,同样的代码工作正常,我的本地服务器卡桑德拉。只要我将cassandra的临时信息更改为本地机器,它就会开始正常工作...
我还检查了端口(9042)是否打开正常。那么为什么查询会被绞死?
我假设,可能会有一些变化,我需要在execute_query
方法使其工作?我正在分期服务器上运行
卡桑德拉版本是1.2.9,并在当地是1.2.8
更新: -
我做了一些研究,该行没有回我什么 - 意的Future.get不做工精细不知为什么...
result = &*future.get().result;
它试图执行我的CQL选择查询后.. USE profileks
工作正常,但只有CQL Select查询被绞死..
是从cqlsh,它工作正常......正如我在我的问题中提到的,它适用于本地主机cassandra群集...顺便说一句,我只有两行内的表,所以它没有意义,不来背部... – ferhan