whatyouhide/xandra

`Xandra.Cluster` isn't connecting

Closed this issue · 2 comments

I'm trying to connect a cluster with three nodes, but without success. The connection works fine when I test a simple connection (on a single node) with the default Xandra.start_link.

Working on simple Xandra.start_link

options = [username: "user", password: "a-very-cool-password"]

{:ok, cluster} =
  Xandra.start_link(
    authentication: {Xandra.Authenticator.Password, options},
      nodes: [
        "node-0.aws-sa-east-1.xxx"
      ]
  )

statement = "SELECT * FROM mykeyspace.test;"

Xandra.execute(conn, statement)

Not working on Xandra.Cluster.start_link

# With Xandra.Cluster
options = [username: "user", password: "a-very-cool-password"]

{:ok, cluster} =
  Xandra.Cluster.start_link(
    authentication: {Xandra.Authenticator.Password, options},
      nodes: [
        "node-0.aws-sa-east-1.xxx",
        "node-1.aws-sa-east-1.xxx",
        "node-2.aws-sa-east-1.xxx"
      ]
  )

statement = "SELECT * FROM mykeyspace.test;"

Xandra.Cluster.execute(cluster, statement)

Error message:

{:error,
 %Xandra.ConnectionError{
   action: "checkout from cluster #PID<0.259.0>",
   reason: {:cluster, :not_connected}
 }}

Thanks in advance for helping me!

Ok, for some reason this code works fine with clusters. The :time.sleep(3000) await for precise connection. Look at this:
image

Yes this is expected behaviour. The cluster process starts and then attempts to connect to nodes, which is not immediate. If you want the Xandra.Cluster.start_link/1 call to block until at least one connection is established, pass it the :sync_connect option.

In the upcoming version of Xandra, we'll queue requests until the cluster connects to at least one node.