cassandra.cluster.nohostavailable未知异常

4xrmg8kj  于 2021-06-15  发布在  Cassandra
关注(0)|答案(0)|浏览(259)

下面是我的python代码,我从一个csv文件中读取密钥并将它们删除到数据库中。它运行了一段时间很好,并抛出了这个超时错误。我没有看到任何gc问题,节点的运行状况良好。

Traceback (most recent call last):
  File "/Users/XXX/Downloads/XXX/XXX", line 65, in <module>
    parse_file(datafile)
  File "/Users/XXX/Downloads/XXX/XXX", line 49, in parse_file
    session = cluster.connect('XXX')
  File "cassandra/cluster.py", line 1193, in cassandra.cluster.Cluster.connect (cassandra/cluster.c:17796)
  File "cassandra/cluster.py", line 1240, in cassandra.cluster.Cluster._new_session (cassandra/cluster.c:18952)
  File "cassandra/cluster.py", line 1980, in cassandra.cluster.Session.__init__ (cassandra/cluster.c:35191)
cassandra.cluster.NoHostAvailable: ("Unable to connect to any servers using keyspace 'qualys_ioc'", ['127.0.0.1'])

python代码:

import argparse
import sys
import itertools
import codecs
import uuid
import os
import subprocess

try:
    import cassandra
    import cassandra.concurrent
except ImportError:
    sys.exit('Python Cassandra driver not installed. You might try \"pip install cassandra-driver\".')
from cassandra.cluster import Cluster, ResultSet, Session
from cassandra.policies import DCAwareRoundRobinPolicy
from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import ConsistencyLevel
from cassandra import ReadTimeout

datafile = "/Users/XXX/adf.csv"

if os.path.exists(datafile):
    os.remove(datafile)

def dumptableascsv():
  os.system(
      "sh /Users/XXX/Documents/dse-5.0.14/bin/cqlsh 127.0.0.1 9042 -u cassandra -p cassandra -e \" COPY XXX.agent_delta_fragment(agent_id,delta_id ,last_fragment_id ,processed) TO \'/Users/XXX/adf.csv\' WITH HEADER = true;\"\n"
      "      ")

# print datafile

def parse_file(datafile):
    global fields
    data = []
    with open(datafile, "rb") as f:
        header = f.readline().split(",")
        # Loop through remaining lines in file object f
        for line in f:
            fields = line.split(",")  # Split line into list
            #print fields[3]
            if fields[3]:
                print "connect"
                print fields[0],fields[1],fields[2],fields[3]
                auth_provider = PlainTextAuthProvider(username='cassandra', password='cassandra')
                cluster = Cluster(['127.0.0.1'],
                                  load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='Cassandra'),
                                  port=9042, auth_provider=auth_provider, connect_timeout=10000,)
                session = cluster.connect('XXX')
                #session = cluster.connect('XXX')
                # session.execute("select * from XXX.agent_delta_fragment LIMIT 1")
                #rows = session.execute('select agent_id from XXX.agent_delta_fragment LIMIT 1')
                #for row in rows:
                 #   print row.agent_id
                #batch = BatchStatement("DELETE FROM XXX.agent_delta_fragment_detail_test WHERE agent_id=%s and delta_id=%s and fragment_id=%s", (uuid.UUID(fields[0]), uuid.UUID(fields[1]), int(fields[3])))
                session.execute("DELETE FROM XXX.agent_delta_fragment_detail WHERE agent_id=%s and delta_id=%s and fragment_id=%s", (uuid.UUID(fields[0]), uuid.UUID(fields[1]), int(fields[2])), timeout=1000000)
                #session.execute(batch)

            else:
                print fields[3]
                print "connect-False"
        # print fields[3]

dumptableascsv()
parse_file(datafile)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题