【问题标题】:When cassandra-driver was executing the query, cassandra-driver returned error OperationTimedOut当 cassandra-driver 执行查询时,cassandra-driver 返回错误 OperationTimedOut
【发布时间】:2014-08-01 04:37:11
【问题描述】:

我使用 python 脚本,它传递给 cassandra 批量查询,如下所示:

query = 'BEGIN BATCH ' + 'insert into ... ; insert into ... ; insert into ...; ' + ' APPLY BATCH;'
session.execute(query)



它工作了一段时间,但在启动脚本失败并打印后大约 2 分钟:

Traceback (most recent call last):<br>
  File "/home/fervid/Desktop/cassandra/scripts/parse_and_save_to_cassandra.cgi", line 127, in <module><br>
    session.execute(query)<br>
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 1103, in execute<br>
    result = future.result(timeout)<br>
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 2475, in result<br>
    raise OperationTimedOut(errors=self._errors, last_host=self._current_host)<br>
cassandra.OperationTimedOut: errors={}, last_host=127.0.0.1<br>
<br>
<br>

我将超时从cassandra.yaml 更改为:
read_request_timeout_in_ms:15000
range_request_timeout_in_ms:20000
write_request_timeout_in_ms:20000
cas_contention_timeout_in_ms:10000
request_timeout_in_ms: 25000


然后我重新启动了 cassandra,但它没有帮助。错误一次又一次地发生!

脚本失败时日志中的行数:

INFO [BatchlogTasks:1] 2014-06-11 14:18:10,490 ColumnFamilyStore.java (第 794 行)排队刷新 Memtable-batchlog@28149592(13557969/13557969 序列化/实时字节,4 ops)
信息 [FlushWriter:10] 2014-06-11 14:18:10,490 Memtable.java (第 363 行)写 Memtable-batchlog@28149592(13557969/13557969 序列化/实时字节,4 个操作)
INFO [FlushWriter:10] 2014-06-11 14:18:10,566 Memtable.java(第 410 行)完成刷新;没有 需要保留。提交日志位置是 ReplayPosition(segmentId=1402469922169, position=27138996)
INFO [ScheduledTasks:1] 2014-06-11 14:18:13,758 GCInspector.java(第 116 行) ParNew 的 GC:3 个集合 640 毫秒,使用了 775214160;最大值是 1052770304
INFO [ScheduledTasks:1] 2014-06-11 14:18:16,155 GCInspector.java (line 116) GC for ConcurrentMarkSweep: 1838 ms for 2 收藏,810976000 已使用;最大值为 1052770304
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,959 GCInspector.java(第 116 行) ConcurrentMarkSweep 的 GC:1612 毫秒用于 1 个集合,使用了 858404088; 最大值为 1052770304
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,959 StatusLogger.java(第 55 行)池名称 Active
待完成 已阻止 所有时间已阻止
信息 [ScheduledTasks:1] 2014-06-11 14:18:17,959 StatusLogger.java(第 70 行) 读取阶段 0 0 627 0 0
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,960 StatusLogger.java(第 70 行)RequestResponseStage 0
0 0 0 0
信息 [ScheduledTasks:1] 2014-06-11 14:18:17,960 StatusLogger.java(第 70 行) 读取修复阶段 0 0 0 0 0
INFO [ScheduledTasks:1] 2014-06-11 14:18:17,960 StatusLogger.java(第 70 行)MutationStage 0
0 184386 0 0
信息 [ScheduledTasks:1] 2014-06-11 14:18:17,960 StatusLogger.java(第 70 行) ReplicateOnWriteStage 0 0 0 0 0

【问题讨论】:

  • 检查cassandra日志..这样你就会知道它背后的错误..
  • 我在日志中没有看到任何错误消息...只有 INFO 消息。
  • ok.. 在 cassandra.yaml 文件中,事情必须像 read_request_timeout_in_ms: 15000 不像 read_request_timeout_in_ms: **15000**
    并增加 cas_contention_timeout_in_ms: 60000(更多)
  • 配置中没有'**',它是在我尝试将数字加粗后出现的:)
  • 刚才我已经把cas_contention_timeout_in_ms增加到了60000。但这没有帮助。

标签: python cassandra cql3


【解决方案1】:
  1. 这是客户端超时(请参阅@Syrial 回复中的链接:http://datastax.github.io/python-driver/api/cassandra.html#cassandra.OperationTimedOut

  2. 您可以更改Session default timeout:

    session = cluster.connect()
    session.default_timeout = 30  # this is in *seconds*
    
  3. 你可以改the timeout for a particular query:

    session.execute(statement, 30, ...)
    
  4. 您可以通过在BATCH 中使用准备好的语句来加快执行速度。见Batching statements sections in this post

  5. 如果您想要更好的结果,请阅读这些performance notes

【讨论】:

  • 我通过将整个查询分成更小的查询来解决这个问题。
【解决方案2】:

根据文档,此错误表示操作花费的时间超过了客户端指定的时间。错误是由驱动程序产生的,而不是 Cassandra。我仍在寻找自己处理此错误的方法。

http://datastax.github.io/python-driver/api/cassandra.html#cassandra.OperationTimedOut

【讨论】:

  • 是的,这个错误是由 cassandra 产生的。但是 cassandra 设置可能会导致这样的驱动行为,所以我试图改变它。
猜你喜欢
  • 2016-12-20
  • 2020-05-04
  • 1970-01-01
  • 2016-05-25
  • 2016-07-25
  • 1970-01-01
  • 2021-02-13
  • 2018-03-28
  • 2021-11-21
相关资源
最近更新 更多