Created a cassandra cluster using gocql library.
func CreateCassandraCluster(host string) (*gocql.Session, error) {
cluster := gocql.NewCluster(host)
cluster.ConnectTimeout = time.Second * 10
cluster.DisableInitialHostLookup = true
session, err := cluster.CreateSession()
if err != nil {
return session, err
}
return session, nil
}
my objective is to make a function with *gocql.Session as a argument that will check when passing any cassandra cluster’s session is it connected or not connected?
For redis we have PING query to determine redis is connected or not do we have similar thing for cassandra using gocql?
2
Answers
Tried this approach where we are going to just check session open or closed
Not sure if it is the correct approach or not
This looks like an identical question you asked yesterday although I can’t seem to locate it now so I’m wondering if you deleted it.
It’s not obvious to me what you are trying to achieve. Checking if the session is connected or not is not helpful when it comes to Cassandra.
When the driver establishes a connection to the cluster for the first time, it uses the hosts you passed in
NewCluster()
to do an initial connection to discover the rest of the nodes and the cluster topology (rack configuration, data centres), then establishes connections to the nodes.If a connection fails, the default policy in the driver is smart enough to automatically reconnect so duplicating this functionality is pointless.
As I stated in your other question, you are better off using free open-source tools like Metric Collector for Apache Cassandra (MCAC) if your ultimate goal is to monitor the health of your Cassandra cluster. Cheers!