scylladb / python-driver

ScyllaDB Python Driver, originally DataStax Python Driver for Apache Cassandra
https://python-driver.docs.scylladb.com
Apache License 2.0
70 stars 42 forks source link

Add support for unix domain sockets to `WhiteListRoundRobinPolicy` #287

Closed sylwiaszunejko closed 8 months ago

sylwiaszunejko commented 8 months ago

If the contact point is unix domain socket, there is no need to try to resolve it and use socket.getaddrinfo. In fact calling this function on unix domain socket makes it fail.

This PR adds checking if host is UnixSocketEndPoint and adapts the behavior to the type of endpoint.

I tested it manually by running this example:

from cassandra.cluster import Cluster
from cassandra.connection import UnixSocketEndPoint
from cassandra.policies import HostFilterPolicy, RoundRobinPolicy

socket = "<node's workdir>/cql.m"
cluster = Cluster([UnixSocketEndPoint(socket)],
                  # Driver tries to connect to other nodes in the cluster, so we need to filter them out.
                  load_balancing_policy=WhiteListRoundRobinPolicy([UnixSocketEndPoint(socket)])
session = cluster.connect()

Partially fixes: https://github.com/scylladb/python-driver/issues/280 (it adds support inWhiteListRoundRobinPolicy, but it is not enough for cqlsh to work)

avelanarius commented 8 months ago

@sylwiaszunejko Could you add a unit test that verifies it works?

Does the distance function continue to work properly? host.address in self._allowed_hosts_resolved (this part of that function)

sylwiaszunejko commented 8 months ago

@avelanarius I added unit test, is that enough or should I test something more?

kbr-scylla commented 8 months ago

Nice, thanks.