连接到登台Cassandra服务器时,CQL SELECT查询被挂起了吗?

时间:2013-10-13 20:44:56

标签: c++ cassandra cql libcql

我有一个DEV盒子,当我使用新的二进制协议时,我正试图通过端口9042连接到我的STAGING Cassandra服务器。我正在使用libcql library为Cassandra从DEV框运行我的C ++代码..

但不知怎的,我想,当Connected Successfully被打印出来时,我可以在端口9042上建立与我的登台Cassandra服务器的连接。

以下是我头文件中的代码 -

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服务器。一旦我将登台cassandra信息更改为本地机器,它就会开始正常工作......

我还检查了端口(9042)是否正常打开..然后为什么查询被挂起了?

我假设,我需要在execute_query方法中进行一些更改才能使其正常工作?

我在Staging服务器上运行的Cassandra版本是1.2.9,本地是1.2.8

更新: -

我做了一些研究,这条线并没有给我任何回报 - 意味着future.get在某种程度上不能正常工作..

result = &*future.get().result;

尝试执行我的CQL Select查询后.. USE profileks工作正常,但只有CQL Select查询被挂起..

2 个答案:

答案 0 :(得分:0)

您是否尝试从CQLsh运行相同的查询? 我认为您的查询是时间可能是因为返回了大量行,也许如果您添加限制X,它会有所帮助。 如果您打算使用'SELECT * FROM mycolumnfamily'获取所有数据,您可能需要查看数据架构。 查看SELECT文档http://cassandra.apache.org/doc/cql/CQL.html#SELECT 同样来自文档'当使用范围时,有时限制可以作为每行的一部分返回的列数是有用的(因为Cassandra是无模式的,所以不一定可以提前确定将有多少列。在结果集中)。要完成此操作,请使用带有整数的FIRST子句指定每行返回的列数的上限。默认限制为10,000列。'

答案 1 :(得分:0)

我碰到了一些模糊的东西。 future.get()。result总是有一个空指针,用于在其他地方工作的完全相同的代码。我将其追溯到g ++命令行选项:

使用“g ++ -std = gnu ++ 0x ...”进行编译,但失败了 使用“g ++ ...”进行编译并且可以正常工作