使用 Python Cassandra 驱动程序写入时出现服务器错误
Server Errors While Writing With Python Cassandra Driver
code=1000 [Unavailable exception] message="Cannot achieve consistency level ONE" info={'required_replicas': 1, 'alive_replicas': 0, 'consistency': 'ONE'}
code=1100 [Coordinator node timed out waiting for replica nodes' responses] message="Operation timed out - received only 0 responses." info={'received_responses': 0, 'required_responses': 1, 'consistency': 'ONE'}
code=1200 [Coordinator node timed out waiting for replica nodes' responses] message="Operation timed out - received only 0 responses." info={'received_responses': 0, 'required_responses': 1, 'consistency': 'ONE'}
我正在通过 python cassandra-driver version 2.6
插入 Cassandra Cassandra 2.0.13(用于测试的单节点)
以下是我的键空间和table定义:
CREATE KEYSPACE test_keyspace WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '1' };
CREATE TABLE test_table (
key text PRIMARY KEY,
column1 text,
...,
column17 text
) WITH COMPACT STORAGE AND
bloom_filter_fp_chance=0.010000 AND
caching='KEYS_ONLY' AND
comment='' AND
dclocal_read_repair_chance=0.000000 AND
gc_grace_seconds=864000 AND
read_repair_chance=0.100000 AND
replicate_on_write='true' AND
populate_io_cache_on_flush='false' AND
compaction={'class': 'SizeTieredCompactionStrategy'} AND
compression={'sstable_compression': 'SnappyCompressor'};
我试过的:
1) 多处理(协议版本设置为 1)
每个进程都有自己的 cluster
、session
(default_timeout 设置为 30.0)
def get_cassandra_session():
"""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 CLUSTER_HOST2:
cluster = cassandra.cluster.Cluster([CLUSTER_HOST1, CLUSTER_HOST2])
else:
# if only one address is available, we have to use older protocol version
cluster = cassandra.cluster.Cluster([CLUSTER_HOST1], protocol_version=1)
session = cluster.connect(KEY_SPACE)
session.default_timeout = 30.0
return session
2)批量插入(协议版本设置为2,因为Cassandra上启用了BatchStatement2.X)
def batch_insert(session, batch_queue, batch):
try:
insert_user = session.prepare("INSERT INTO " + db.TABLE + " (" + db.COLUMN1 + "," + db.COLUMN2 + "," + db.COLUMN3 +
"," + db.COLUMN4 + ") VALUES (?,?,?,?)")
while batch_queue.qsize() > 0:
'''batch queue size is 1000'''
row_tuple = batch_queue.get()
batch.add(insert_user, row_tuple)
session.execute(batch)
except Exception as e:
logger.error("batch insert fail.... %s", e)
以上函数被调用:
batch = BatchStatement(consistency_level=ConsistencyLevel.ONE)
batch_insert(session, batch_queue, batch)
元组存储在 batch_queue.
3)同步执行
几天前我 post 另一个问题 ,cassandra 抱怨超时问题。我正在使用同步执行进行更新。
谁能帮忙,这是我的代码问题还是 python cassandra 驱动程序问题或 Cassandra 本身?
万分感谢!
如果您的问题是关于顶部的那些错误,那么这些是服务器端错误响应。
第一个说您联系的协调器不能满足 CL.ONE 的请求,它认为节点是活动的。如果所有副本都关闭(更有可能是复制因子较低),就会发生这种情况。
另外两个错误是超时,协调器在 configured in the cassandra.yaml.
时间内没有从 'live' 个节点得到响应
所有这些都表明您连接的集群不健康。这可能是因为它不堪重负(高 GC 暂停)或遇到网络问题。检查服务器日志以获取线索。
我收到以下错误,看起来非常相似:
cassandra.Unavailable: Error from server: code=1000 [Unavailable exception] message="Cannot achieve consistency level LOCAL_ONE" info={'consistency': 'LOCAL_ONE', 'alive_replicas': 0, 'required_replicas': 1}
当我在代码中添加一个 sleep(0.5)
时,它运行良好。我试图写得太多太快了...
code=1000 [Unavailable exception] message="Cannot achieve consistency level ONE" info={'required_replicas': 1, 'alive_replicas': 0, 'consistency': 'ONE'}
code=1100 [Coordinator node timed out waiting for replica nodes' responses] message="Operation timed out - received only 0 responses." info={'received_responses': 0, 'required_responses': 1, 'consistency': 'ONE'}
code=1200 [Coordinator node timed out waiting for replica nodes' responses] message="Operation timed out - received only 0 responses." info={'received_responses': 0, 'required_responses': 1, 'consistency': 'ONE'}
我正在通过 python cassandra-driver version 2.6
插入 Cassandra Cassandra 2.0.13(用于测试的单节点)以下是我的键空间和table定义:
CREATE KEYSPACE test_keyspace WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '1' };
CREATE TABLE test_table (
key text PRIMARY KEY,
column1 text,
...,
column17 text
) WITH COMPACT STORAGE AND
bloom_filter_fp_chance=0.010000 AND
caching='KEYS_ONLY' AND
comment='' AND
dclocal_read_repair_chance=0.000000 AND
gc_grace_seconds=864000 AND
read_repair_chance=0.100000 AND
replicate_on_write='true' AND
populate_io_cache_on_flush='false' AND
compaction={'class': 'SizeTieredCompactionStrategy'} AND
compression={'sstable_compression': 'SnappyCompressor'};
我试过的:
1) 多处理(协议版本设置为 1)
每个进程都有自己的 cluster
、session
(default_timeout 设置为 30.0)
def get_cassandra_session():
"""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 CLUSTER_HOST2:
cluster = cassandra.cluster.Cluster([CLUSTER_HOST1, CLUSTER_HOST2])
else:
# if only one address is available, we have to use older protocol version
cluster = cassandra.cluster.Cluster([CLUSTER_HOST1], protocol_version=1)
session = cluster.connect(KEY_SPACE)
session.default_timeout = 30.0
return session
2)批量插入(协议版本设置为2,因为Cassandra上启用了BatchStatement2.X)
def batch_insert(session, batch_queue, batch):
try:
insert_user = session.prepare("INSERT INTO " + db.TABLE + " (" + db.COLUMN1 + "," + db.COLUMN2 + "," + db.COLUMN3 +
"," + db.COLUMN4 + ") VALUES (?,?,?,?)")
while batch_queue.qsize() > 0:
'''batch queue size is 1000'''
row_tuple = batch_queue.get()
batch.add(insert_user, row_tuple)
session.execute(batch)
except Exception as e:
logger.error("batch insert fail.... %s", e)
以上函数被调用:
batch = BatchStatement(consistency_level=ConsistencyLevel.ONE)
batch_insert(session, batch_queue, batch)
元组存储在 batch_queue.
3)同步执行
几天前我 post 另一个问题
谁能帮忙,这是我的代码问题还是 python cassandra 驱动程序问题或 Cassandra 本身?
万分感谢!
如果您的问题是关于顶部的那些错误,那么这些是服务器端错误响应。
第一个说您联系的协调器不能满足 CL.ONE 的请求,它认为节点是活动的。如果所有副本都关闭(更有可能是复制因子较低),就会发生这种情况。
另外两个错误是超时,协调器在 configured in the cassandra.yaml.
时间内没有从 'live' 个节点得到响应所有这些都表明您连接的集群不健康。这可能是因为它不堪重负(高 GC 暂停)或遇到网络问题。检查服务器日志以获取线索。
我收到以下错误,看起来非常相似:
cassandra.Unavailable: Error from server: code=1000 [Unavailable exception] message="Cannot achieve consistency level LOCAL_ONE" info={'consistency': 'LOCAL_ONE', 'alive_replicas': 0, 'required_replicas': 1}
当我在代码中添加一个 sleep(0.5)
时,它运行良好。我试图写得太多太快了...