Skip to main content

Command Palette

Search for a command to run...

How Does the Apache Cassandra GoCQL Driver Function?

Part 1: host discovery, control connection and executor connection

Updated
1 min read
How Does the Apache Cassandra GoCQL Driver Function?
P

Hi, I'm Phuong. I'm a funny guy who spend a lot of time around digital devices. If you are reading these lines, I'm either probably playing some video games or learning something from the internet.

When you connect to Cassandra, you need to initialize a Session . This session will create a 2 connection pools to C*

Session will try to discover hosts for control connection pool first by resolving the provided hosts with DNS lookup. It will then use this host to discover other members in the cluster by querying system.peers and system.local for host info. (https://github.com/apache/cassandra-gocql-driver/blob/7279756d7311211939f1466d20d1a029ab69f4a4/host_source.go#L711)

Control connection pool also maintains a go routine to periodically heartbeat the connected host and reinitialize the connection when the heartbeat fails. (https://github.com/apache/cassandra-gocql-driver/blob/7279756d7311211939f1466d20d1a029ab69f4a4/control.go#L125)

When a node join/leave the cluster, Cassandra will send a corresponding event to the connected client via the mentioned above control connection. The driver when then issue a ring refresh request for a new host list. (https://github.com/apache/cassandra-gocql-driver/blob/7279756d7311211939f1466d20d1a029ab69f4a4/events.go#L166)