Cassandra datastax | TimeoutException异常

问题描述 投票:0回答:3

我有cassandra的问题我有以下错误。我链接了一张照片

代码语法:

 public function find($db_table = null, $db_id = null) {
        $filter = "";
        $return = array();

        $cluster = $this->cluster();
        $session = $cluster->connect($this->keyspace);

        if(isset($db_table)) {
            $filter .= " WHERE db_table like '%".$db_table."%' ";

            if($db_id != null) {
                $filter .= " AND db_id = '".$db_id."' ALLOW FILTERING";
            }
        }

        $query  = new Cassandra\SimpleStatement("SELECT * FROM ".$this->keyspace.".log $filter;");
        $result = $session->executeAsync($query);
        $rows   = $result->get();

Cassandra Error picture

php cassandra datastax
3个回答
1
投票
  1. 除非您知道自己在做什么,否则不应使用“允许过滤”。
  2. SELECT * FROM prod.log WHERE db_id = 13913 AND db_table LIKE'%%'产品LIMIT 5000超时,因为您似乎在DB中有很多条目并且允许过滤正在进行全表扫描。
  3. 您应该调整表格设计以匹配您的查询。

0
投票

更多细节可以在这里找到。

https://docs.datastax.com/en/developer/php-driver/1.2/api/Cassandra/Cluster/class.Builder/

使用withConnectTimeout可以帮助避免TimeoutException

$cluster = $this->cluster()->withConnectTimeout(60);

您可以增加超时值虽然您通过更改/etc/cassandra/cassandra.yaml中的值更新了更多

类似于以下 -

sudo nano /etc/cassandra/cassandra.yaml(用于编辑cassandra.yaml文件)

# How long the coordinator should wait for read operations to complete
read_request_timeout_in_ms: 50000
# How long the coordinator should wait for seq or index scans to complete
range_request_timeout_in_ms: 100000
# How long the coordinator should wait for writes to complete
write_request_timeout_in_ms: 20000
# How long the coordinator should wait for counter writes to complete
counter_write_request_timeout_in_ms: 50000
# How long a coordinator should continue to retry a CAS operation
# that contends with other proposals for the same row
cas_contention_timeout_in_ms: 10000
# How long the coordinator should wait for truncates to complete
# (This can be much longer, because unless auto_snapshot is disabled
# we need to flush first so we can snapshot before removing the data.)
truncate_request_timeout_in_ms: 600000
# The default timeout for other, miscellaneous operations
request_timeout_in_ms: 100000

# How long before a node logs slow queries. Select queries that take longer than
# this timeout to execute, will generate an aggregated log message, so that slow queries
# can be identified. Set this value to zero to disable slow query logging.
slow_query_log_timeout_in_ms: 5000

0
投票
  1. 在cassandra上使用“LIKE”我不这么认为:(
  2. 你的查询:(尝试做一些更干净的事情而不是使用“。$ db_table。”正确绑定使用。?然后在你的exec内部(查询,['值'])
  3. 你是什​​么意思?使用SELECT * FROM“。$ this-> keyspace。”。log这不是查询!如果你在php中使用它,语法绝对是完全错误的。你写了SELECT * FROM keyspace_name.log WHERE表,如'wherever'和id ='something':(更糟糕的是选择ALL 这永远不会发生
  4. 你用$ this从哪里调用你的集群?这是从哪里来的?

好吧,我可以列举10个不同的原因,你的代码不起作用,但这不是我的目标,我想要帮助你所以只是尝试一些简单的事情。

____好_____

<?

$cluster   = Cassandra::cluster()
               ->withContactPoints('127.0.0.1')
               ->build();
$session   = $cluster->connect("your_k_space");


$table_list = $session->execute("SELECT table_name FROM system_schema.tables WHERE keyspace_name = 'your_k_space'");


if (in_array($db_table, $table_list)) {
   $options = array('arguments' => [$db_table,$db_id]);
    $result = $session->execute("SELECT * FROM ? WHERE db_id = ?  ALLOW FILTERING",$options);
    foreach ($result as $key => $value) print_r($value);



}else{
    die('table not found');
}
© www.soinside.com 2019 - 2024. All rights reserved.