1

We are using a pig script to export data into Cassandra from hive. The script will truncate the cassandra table and run export .

To perform TRUNCATE part, we are using the below command. But if that node is down at the moment , the script fails .

$ cqlsh  -u user -p password host1  -e "USE randomkeyspace; CONSISTENCY ALL;TRUNCATE TABLE randomtable"

Is there any other way to run this job so that it can contact other host if host1 is down ?

Or else

can we use this -

host=("host1" "host2" "host3")

$ cqlsh  -u user -p password $host  -e "USE randomkeyspace; CONSISTENCY ALL;TRUNCATE TABLE randomtable"

Thanks!

Tony
  • 671
  • 1
  • 9
  • 29

2 Answers2

3

You could try something like this:

cqlsh  -u user -p password host1  -e "USE randomkeyspace; CONSISTENCY ALL;TRUNCATE TABLE randomtable" || cqlsh  -u user -p password host2  -e "USE randomkeyspace; CONSISTENCY ALL;TRUNCATE TABLE randomtable" || cqlsh  -u user -p password host3  -e "USE randomkeyspace; CONSISTENCY ALL;TRUNCATE TABLE randomtable"

which basically means that if first command fails, the second will be executed and if the second fails, the third one will be executed.

Also, bear in mind that since you're doing a CONSISTENCY ALL, all nodes that have your data must be up.

Horia
  • 2,942
  • 7
  • 14
0

you could check that the host is up before trying to connect to it: one option is to see if the port is open on the remote host (using nc: nc -zv <address> <port>). or even use nodetool -h 127.0.0.1 status to get the list of nodes. something like nodetool status|grep UN|awk {'print $2'}

FuzzyAmi
  • 7,543
  • 6
  • 45
  • 79