CQL SELECT 查询在连接到暂存 Cassandra 服务器时挂起

CQL SELECT query gets hanged while connecting to staging Cassandra servers?

本文关键字:Cassandra 服务器 挂起 SELECT 查询 连接 CQL      更新时间:2023-10-16

>我有一个 DEV 盒子,当我使用新的二进制协议时,我正在尝试从中连接到端口 9042 上的暂存 Cassandra 服务器。我正在使用 Cassandra 的libcql library从 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 服务器。一旦我将暂存卡桑德拉信息更改为本地机器,它就开始正常工作......

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

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

我在暂存服务器上运行的卡桑德拉版本是 1.2.9,本地是 1.2.8

更新:-

我做了一些研究,这条线没有给我带来任何东西 - 这意味着 future.get 不知何故无法正常工作。

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

在它尝试执行我的 CQL 选择查询后。 USE profileks工作正常,但只有 CQL 选择查询被挂起。

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

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

编译为 "g++ -std=gnu++0x ..."它失败了使用"g++..."它有效