cassandra.cluster.NoHostAvailable unknown exception

539 views Asked by At

Below is my python code I read the keys from a CSV file and delete them in the database.It's running fine for a while and throwing me this timeout error. I don't see any GC issue and health of the node is working fine.

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 Code:

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)
0

There are 0 answers