【问题标题】:Cassandra datastax | TimeoutExceptionCassandra 数据统计 |超时异常
【发布时间】:2019-07-22 04:31:53
【问题描述】:

我对 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

【问题讨论】:

  • 请将错误以文字而非图片的形式发布,以提高您问题的可读性。
  • 请同时发布表结构
  • 什么版本的 DSE/Cassandra

标签: php cassandra datastax


【解决方案1】:
  1. 除非您知道自己在做什么,否则不应使用“允许过滤”。
  2. SELECT * FROM prod.log WHERE db_id = 13913 AND db_table LIKE '%%' product LIMIT 5000 超时,因为您似乎在数据库中有很多条目,并且允许过滤正在执行全表扫描。
  3. 您应该调整表设计以匹配您的查询。

【讨论】:

    【解决方案2】:

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

    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
    

    【讨论】:

      【解决方案3】:
      1. 在 cassandra 上使用“LIKE”我不这么认为 :(
      2. 您的查询 :( 尝试做一些更干净的事情,而不是使用“.$db_table”。正确绑定使用。?然后在您的 exec(query,['value']) 中
      3. 你是什么意思?用 SELECT * FROM ".$this->keyspace.".log 这不是查询!如果你在 php 中使用它,语法肯定是完全错误的。 你写了 SELECT * FROM keyspace_name.log WHERE table like 'wherever' and id = 'something' :( 更糟糕的是选择全部
        这永远不会发生

      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');
      }
      

      【讨论】:

        猜你喜欢
        • 2018-04-21
        • 2018-12-25
        • 2023-01-15
        • 2019-05-19
        • 2014-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多