2013-10-13 13 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 ++ ......”和它的作品