3

I'm running Scylladb locally in a docker container and I want to access the cluster outside the docker container. That's when I'm getting the following error: cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers')

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address     Load       Tokens       Owns    Host ID                               Rack
UN  172.17.0.2  776 KB     256          ?       ad698c75-a465-4deb-a92c-0b667e82a84f  rack1

Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless
Cluster Information:
    Name: Test Cluster
    Snitch: org.apache.cassandra.locator.SimpleSnitch
    DynamicEndPointSnitch: disabled
    Partitioner: org.apache.cassandra.dht.Murmur3Partitioner
    Schema versions:
        443048b2-c1fe-395e-accd-5ae9b6828464: [172.17.0.2]

I have no problem accessing the cluster using cqlsh on port 9042:

Connected to  at 172.17.0.2:9042.
[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]

Now I'm trying to access the cluster from my fastapi app that is outside the docker container.

from cassandra.cluster import Cluster

cluster = Cluster(['172.17.0.2'])

session = cluster.connect('Test Cluster')

And here's the Error that I'm getting:

raise NoHostAvailable("Unable to connect to any servers", errors)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'172.17.0.2:9042': OSError(51, "Tried connecting to [('172.17.0.2', 9042)]. Last error: Network is unreachable")})
  • 2
    Is your host machine a Mac? One of the known limitations is that you can't directly route traffic from the host to containers in a Mac. If not, then please demonstrate the relevant connection section of your Python program. – Felipe Mendes Oct 31 '22 at 20:06
  • @FelipeMendes Yes my host is a Mac. Do you know of any workarounds? – john meiners Nov 01 '22 at 13:18
  • 2
    Yes, run your program within a Docker container and you shall be able to route traffic to Scylla. That's a Mac limitation. – Felipe Mendes Nov 01 '22 at 13:41

1 Answers1

0

with a little bit of tinkering, it's possible to achieve a connection to the Scylla running in a container outside of the container for local development.

I've tried on M1 Mac with docker desktop:

  1. Run scylla container with couple of new parameters[src]:

    • --listen-address 0.0.0.0 for simplification as we are spawning Scylla inside the container to allow connection to the container from any network
    • --broadcast-rpc-address 127.0.0.1 required if --listen-address set to 0.0.0.0. We are going to port forward 9042 from container to host (local) machine, so this is an IP where it will be acessible.

    The final command to spawn the container is:

    $ docker run --rm -ti \
       -p 127.0.0.1:9042:9042 \
       scylladb/scylla \
           --smp 1 \
           --listen-address 0.0.0.0 \
           --broadcast-rpc-address 127.0.0.1
    

    The -p 127.0.0.1:9042:9042 is to make port 9042 accessible on host (local) machine.

  2. Install pip3 install scylla-driver as it has support of darwin/arm64 architecture.

  3. Write a simple python script:

    # so74265199.py
    
    from cassandra.cluster import Cluster
    
    cluster = Cluster(['127.0.0.1'])
    
    session = cluster.connect()
    # Select from a table that is available without keyspace
    res = session.execute('SELECT * FROM system.versions')
    print(res.one())
    
  4. Run your script

    $ python3 so74265199.py
    Row(key='local', build_id='71178cf6db7021896cd8251751b78b3d9e3afa8d', build_mode='release', version='5.0.5-0.20221009.5a97a1060')
    

Disclaimer: I'm not an expert in Scylla's configuration, so feel free to point out a better approach.