2

我想对单个节点上的 Cassandra 实例(v1.1.10)进行简单的写入操作。我只是想看看它如何处理持续写入,以及它是否能跟上写入速度。

pool = ConnectionPool('testdb')
test_cf = ColumnFamily(pool,'test')
test2_cf = ColumnFamily(pool,'test2')
test3_cf = ColumnFamily(pool,'test3')
test_batch = test_cf.batch(queue_size=1000)
test2_batch = test2_cf.batch(queue_size=1000)
test3_batch = test3_cf.batch(queue_size=1000)

chars=string.ascii_uppercase
counter = 0
while True:
    counter += 1
    uid = uuid.uuid1()
    junk = ''.join(random.choice(chars) for x in range(50))
    test_batch.insert(uid, {'junk':junk})
    test2_batch.insert(uid, {'junk':junk})
    test3_batch.insert(uid, {'junk':junk})
    sys.stdout.write(str(counter)+'\n')

pool.dispose()

长时间写入后(当计数器约为 10M+ 时),代码不断崩溃,并显示以下消息

pycassa.pool.AllServersUnavailable: An attempt was made to connect to each of the servers twice, but none of the attempts succeeded. The last failure was timeout: timed out

我设置了queue_size=100这没有帮助。cqlsh -3此外,在脚本崩溃并出现以下错误后,我启动了控制台以截断表格:

Unable to complete request: one or more nodes were unavailable.

Tailing/var/log/cassandra/system.log没有给出错误信号,但有关于 Compaction、FlushWriter 等的 INFO。我究竟做错了什么?

4

1 回答 1

0

我也遇到过这个问题——正如@tyler-hobbs 在他的评论中所建议的那样,节点可能已经超载(这是给我的)。我使用的一个简单修复方法是后退并让节点赶上。我已经重写了你上面的循环来捕捉错误,睡一会儿再试一次。我已经在一个单节点集群上运行了这个,它很有效——暂停(一分钟)并定期退出(连续不超过 5 次)。使用此脚本不会丢失任何数据,除非错误连续抛出五次(在这种情况下,您可能希望失败而不是返回循环)。

while True:
  counter += 1
  uid = uuid.uuid1()
  junk = ''.join(random.choice(chars) for x in range(50))
  tryCount = 5 # 5 is probably unnecessarily high
  while tryCount > 0:
    try:
      test_batch.insert(uid, {'junk':junk})
      test2_batch.insert(uid, {'junk':junk})
      test3_batch.insert(uid, {'junk':junk})
      tryCount = -1
    except pycassa.pool.AllServersUnavailable as e:
      print "Trying to insert [" + str(uid) + "] but got error " + str(e) + " (attempt " + str(tryCount) + "). Backing off for a minute to let Cassandra settle down"
      time.sleep(60) # A delay of 60s is probably unnecessarily high
      tryCount = tryCount - 1
  sys.stdout.write(str(counter)+'\n')

我在这里添加了一个完整的要点

于 2013-09-13T08:54:31.243 回答