Skip to content

Commit 495bccc

Browse files
committed
Remove DNS cache from client_routes
- Remove socket import and DNS resolution from resolve_host - Remove cache_ttl_seconds parameter from ClientRoutesConfig - Remove dead _dns_cache/_dns_cache_lock type annotations - Remove cache_ttl_seconds from tests
1 parent 2fa4651 commit 495bccc

3 files changed

Lines changed: 9 additions & 33 deletions

File tree

cassandra/client_routes.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
from dataclasses import dataclass
2525
import enum
2626
import logging
27-
import socket
2827
import threading
29-
from time import sleep
28+
import time
3029
import uuid
3130
from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Set, Tuple
3231

@@ -75,14 +74,11 @@ class ClientRoutesConfig:
7574
Configuration for client routes (Private Link support).
7675
7776
:param contact_points: List of ClientRoutesContactPoint objects (REQUIRED, at least one)
78-
:param cache_ttl_seconds: How long DNS resolution results are cached (default: 300 seconds = 5 minutes)
7977
"""
8078

81-
def __init__(self, contact_points: List[ClientRoutesContactPoint],
82-
cache_ttl_seconds: int = 300):
79+
def __init__(self, contact_points: List[ClientRoutesContactPoint]):
8380
"""
8481
:param contact_points: List of ClientRoutesContactPoint objects
85-
:param cache_ttl_seconds: DNS cache TTL in seconds (must be >= 0, default: 300 = 5 minutes)
8682
"""
8783
if not contact_points:
8884
raise ValueError("At least one contact point must be specified")
@@ -215,8 +211,6 @@ class _ClientRoutesHandler:
215211
ssl_enabled: bool
216212
_routes: _RouteStore
217213
_initial_contact_points: Set[str]
218-
_dns_cache: Dict[str, Tuple[str, float]]
219-
_dns_cache_lock: threading.Lock
220214

221215
def __init__(self, config: 'ClientRoutesConfig', ssl_enabled: bool = False):
222216
"""
@@ -400,17 +394,4 @@ def resolve_host(self, host_id: uuid.UUID) -> Optional[Tuple[str, int]]:
400394
if route is None:
401395
return None
402396

403-
if not route.port:
404-
raise AttributeError("Mapping for host %s has no port" % host_id)
405-
406-
try:
407-
result = socket.getaddrinfo(route.address, route.port,
408-
socket.AF_UNSPEC, socket.SOCK_STREAM)
409-
if not result:
410-
raise socket.gaierror("No addresses found for %s" % route.address)
411-
resolved_ip = result[0][4][0]
412-
return resolved_ip, route.port
413-
except socket.gaierror as e:
414-
log.warning('[client routes] Could not resolve hostname "%s" (host_id=%s): %s',
415-
route.address, host_id, e)
416-
raise
397+
return route.address, route.port

tests/integration/standard/test_client_routes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ def _make_client_routes_cluster(self, **extra_kwargs):
702702
port=self.nlb.discovery_port,
703703
client_routes_config=ClientRoutesConfig(
704704
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
705-
cache_ttl_seconds=0,
705+
706706
),
707707
load_balancing_policy=RoundRobinPolicy(),
708708
**extra_kwargs,
@@ -824,7 +824,7 @@ def test_route_update_causes_reconnect_to_new_port(self):
824824
port=nlb_v1.discovery_port,
825825
client_routes_config=ClientRoutesConfig(
826826
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
827-
cache_ttl_seconds=0,
827+
828828
),
829829
load_balancing_policy=RoundRobinPolicy(),
830830
) as cluster:
@@ -957,7 +957,7 @@ def test_mixed_direct_and_nlb_connections(self):
957957
contact_points=["127.0.0.1"],
958958
client_routes_config=ClientRoutesConfig(
959959
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
960-
cache_ttl_seconds=0,
960+
961961
),
962962
load_balancing_policy=RoundRobinPolicy(),
963963
) as cluster:
@@ -1088,7 +1088,7 @@ def routes_visible():
10881088
ssl_context=ssl_ctx,
10891089
client_routes_config=ClientRoutesConfig(
10901090
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
1091-
cache_ttl_seconds=0,
1091+
10921092
),
10931093
load_balancing_policy=RoundRobinPolicy(),
10941094
) as cluster:
@@ -1178,7 +1178,7 @@ def test_should_survive_full_node_replacement_through_nlb(self):
11781178
port=nlb.discovery_port,
11791179
client_routes_config=ClientRoutesConfig(
11801180
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
1181-
cache_ttl_seconds=0,
1181+
11821182
),
11831183
load_balancing_policy=RoundRobinPolicy(),
11841184
) as cluster:

tests/unit/test_client_routes.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ def test_config_invalid_contact_point_type(self):
5252
with self.assertRaises(TypeError):
5353
ClientRoutesConfig(["not-a-contact-point"])
5454

55-
def test_config_cache_ttl_validation(self):
56-
ep = ClientRoutesContactPoint(str(uuid.uuid4()))
57-
with self.assertRaises(ValueError):
58-
ClientRoutesConfig([ep], cache_ttl_seconds=-1)
59-
config = ClientRoutesConfig([ep], cache_ttl_seconds=0)
60-
self.assertEqual(config.cache_ttl_seconds, 0)
55+
6156

6257

6358
class TestRouteStore(unittest.TestCase):

0 commit comments

Comments
 (0)