【发布时间】:2016-10-02 15:05:10
【问题描述】:
我有一个 python 脚本,用于与 datastax python driver 与 cassandra 交互
它从 2016 年 3 月 14 日开始运行,直到今天都没有问题。
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',)})
下面是用于创建会话的函数,每次查询完成时关闭会话(session.shutdown())。(每天我们只有不到100个来自订阅者的查询,因此我选择了构建连接,执行查询并关闭它,而不是让连接保持活动状态)
会话不在线程和进程之间共享。如果我在 python 控制台中调用以下函数,它会正确连接到数据库,但正在运行的脚本无法再连接到数据库。
任何人都可以帮助或阐明这个问题吗?谢谢
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
规格: 蟒蛇2.7 卡桑德拉 2.1.11
来自datastax doc的引述:
操作完成的时间超过了指定的(客户端)超时时间。这不是 Cassandra 产生的错误,只是驱动程序产生的错误。
问题是我没有触摸驱动程序。我将默认超时设置为 30.0 秒,但为什么它在 5 秒后超时(日志中说)
【问题讨论】: