CQL SELECT 查询在连接到暂存 Cassandra 服务器时挂起
CQL SELECT query gets hanged while connecting to staging Cassandra servers?
>我有一个 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++..."它有效
- "unknown ca"自生成的 CA、证书和客户端/服务器
- 当我编译webrtc服务器时,Windows上只支持clang-cl
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 有没有办法知道Tracer是否成功地完全连接到了jaegerclientcpp中的jaeger后端服务器
- 从服务器传输到客户端的消息不会出现
- QTcpSocket在不阻塞GUI的情况下重新连接到服务器
- OpenSSL TLS服务器-使用客户端证书白名单
- 我正在开发服务器,ip作为参数传递不起作用
- 我可以与 python 服务器而不是 c++ 客户端建立 tcp/ip 套接字吗?
- 提升 Asio TCP 服务器 处理多个客户端
- 如何在 Minecraft 服务器上执行命令
- 调试编译的服务器在数据库打开时崩溃
- C++套接字客户端到 Python 服务器未创建连接
- 用于解析 win64 堆栈跟踪的命令行客户端(可以访问符号服务器)
- 将相机数据从服务器实时流式传输到客户端
- 为什么创建服务器后C++ httplib 库阻塞了我的主线程?
- 每个服务器请求的内存预算
- 如何将 Firebase 与基于 Linux 的客户端应用配合使用,以便与服务器进行双向消息通信
- 使用嵌入式猫鼬服务器托管应用程序
- CQL SELECT 查询在连接到暂存 Cassandra 服务器时挂起