Cassandra Python 驱动程序 OperationTimedOut 问题 [英] Cassandra Python driver OperationTimedOut issue

查看:110
本文介绍了Cassandra Python 驱动程序 OperationTimedOut 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 python 脚本,用于通过 datastax python 驱动程序与 cassandra 交互>

从 2016 年 3 月 14 日开始运行,直到今天都没有问题.

2016-06-02 13:53:38,362 ERROR('无法连接到任何服务器',{'172.16.47.155':OperationTimedOut('errors=超时创建连接(5秒),last_host=没有任何',)})2016-06-02 13:54:18,362 错误('无法连接到任何服务器',{'172.16.47.155':OperationTimedOut('errors=超时创建连接(5 秒),last_host=None',)})

下面是用于创建会话的函数,并在每次查询完成时关闭会话(session.shutdown()).(每天我们只有不到100个来自订阅者的查询,因此我选择了构建连接,执行查询并关闭它而不是让连接保持活动状态)

会话不在线程和进程之间共享.如果我在 python 控制台中调用以下函数,它会正确连接数据库,但运行脚本无法再连接到数据库.

任何人都可以帮助或阐明这个问题?谢谢

def get_cassandra_session(stat=None):"""创建集群并根据密钥空间获取会话"""# 注意会话不能在线程/进程之间共享# 否则会引发 OperationTimedOut 异常如果 config.CLUSTER_HOST2:cluster = cassandra.cluster.Cluster([config.CLUSTER_HOST1, config.CLUSTER_HOST2])别的:# 如果只有一个地址可用,我们必须使用旧的协议版本cluster = cassandra.cluster.Cluster([config.CLUSTER_HOST1], protocol_version=2)如果 stat 和 type(stat) == BatchStatement:retry_policy = cassandra.cluster.RetryPolicy()retry_policy.on_write_timeout(BatchStatement, ConsistencyLevel, WriteType.BATCH_LOG, ConsistencyLevel.ONE,ConsistencyLevel.ONE,retry_num=0)cluster.default_retry_policy = retry_policysession = cluster.connect(config.KEY_SPACE)session.default_timeout = 30.0返回会话

规格:蟒蛇 2.7卡桑德拉 2.1.11

引自 datastax 文档:

<块引用>

该操作的完成时间超过了指定的(客户端)超时时间.这不是 Cassandra 产生的错误,而是驱动程序产生的错误.

问题是我没有碰驱动程序.我将默认超时设置为 30.0 秒,但为什么它在 5 秒内超时(日志中说)

解决方案

我了解到 gevent 模块会干扰 cassandra-driver

  • cassandra 驱动程序 (3.10)
  • gevent (1.1.1)

卸载 gevent 为我解决了问题

pip 卸载 gevent

I have a python script which is used to interact with cassandra with datastax python driver

It has been running since March 14th, 2016 and had not problem until today.

2016-06-02 13:53:38,362 ERROR ('Unable to connect to any servers', {'172.16.47.155': OperationTimedOut('errors=Timed out creating connection (5 seconds), last_host=None',)})
2016-06-02 13:54:18,362 ERROR ('Unable to connect to any servers', {'172.16.47.155': OperationTimedOut('errors=Timed out creating connection (5 seconds), last_host=None',)})

Below is the function used for creating a session, and shutdown the session (session.shutdown()) every time a query is done.(Every day we only have less than 100 queries from the subscribers side, therefore I chose build connection, do the query and close it instead of leaving the connection alive)

The session is not shared between threads and processes. If i invoke the below function in python console, it connects with the DB properly, but the running script cannot connect to the DB anymore.

Any one can help or shed some light on this issue? Thanks

def get_cassandra_session(stat=None):
    """creates cluster and gets the session base on key space"""
    # be aware that session cannot be shared between threads/processes
    # or it will raise OperationTimedOut Exception
    if config.CLUSTER_HOST2:
        cluster = cassandra.cluster.Cluster([config.CLUSTER_HOST1, config.CLUSTER_HOST2])
    else:
        # if only one address is available, we have to use older protocol version
        cluster = cassandra.cluster.Cluster([config.CLUSTER_HOST1], protocol_version=2)

    if stat and type(stat) == BatchStatement:
        retry_policy = cassandra.cluster.RetryPolicy()
        retry_policy.on_write_timeout(BatchStatement, ConsistencyLevel, WriteType.BATCH_LOG, ConsistencyLevel.ONE,
                                      ConsistencyLevel.ONE, retry_num=0)
        cluster.default_retry_policy = retry_policy
    session = cluster.connect(config.KEY_SPACE)
    session.default_timeout = 30.0
    return session

Specs: python 2.7 Cassandra 2.1.11

Quotes from datastax doc:

The operation took longer than the specified (client-side) timeout to complete. This is not an error generated by Cassandra, only the driver.

The problem is I didn't touch the driver. I set the default timeout to 30.0 seconds but why it timedout in 5 seconds(it is said in the log)

解决方案

I've learned that the gevent module interferes with the cassandra-driver

  • cassandra-driver (3.10)
  • gevent (1.1.1)

Uninstalling gevent solved the problem for me

pip uninstall gevent

这篇关于Cassandra Python 驱动程序 OperationTimedOut 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆