2013-10-13 12 views
0

我有一個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查詢被絞死..

回答

0

您是否嘗試從CQLsh運行相同的查詢? 我認爲你的查詢時間可能是因爲返回的行數很大,也許如果你添加一個限制X,它會有所幫助。 如果您打算使用'SELECT * FROM mycolumnfamily'獲取所有數據,則可能需要查看您的數據體系結構。 查看SELECT文檔http://cassandra.apache.org/doc/cql/CQL.html#SELECT 同樣來自文檔'使用範圍時,限制可作爲每行的一部分返回的列數是有用的(因爲Cassandra是無模式的,所以不一定可行提前確定結果集中有多少列)。要完成此操作,請使用帶整數的FIRST子句來指定每行返回的列數的上限。默認限制是10,000列。'

+0

是從cqlsh,它工作正常......正如我在我的問題中提到的,它適用於本地主機cassandra羣集...順便說一句,我只有兩行內的表,所以它沒有意義,不來背部... – ferhan

0

我遇到了一些類似的東西。 future.get()。結果始終具有空指針,以便在其他地方使用完全相同的代碼。我跟蹤下來的G ++命令行選項:

與編譯「G ++ -std = GNU ++ 0x中......」,也未能 編譯「G ++ ......」和它的作品