我有一個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