| 363 | return self._child_policy.distance(*args, **kwargs) |
| 364 | |
| 365 | def make_query_plan(self, working_keyspace=None, query=None): |
| 366 | if query and query.keyspace: |
| 367 | keyspace = query.keyspace |
| 368 | else: |
| 369 | keyspace = working_keyspace |
| 370 | |
| 371 | child = self._child_policy |
| 372 | if query is None: |
| 373 | for host in child.make_query_plan(keyspace, query): |
| 374 | yield host |
| 375 | else: |
| 376 | routing_key = query.routing_key |
| 377 | if routing_key is None or keyspace is None: |
| 378 | for host in child.make_query_plan(keyspace, query): |
| 379 | yield host |
| 380 | else: |
| 381 | replicas = self._cluster_metadata.get_replicas(keyspace, routing_key) |
| 382 | if self.shuffle_replicas: |
| 383 | shuffle(replicas) |
| 384 | for replica in replicas: |
| 385 | if replica.is_up and \ |
| 386 | child.distance(replica) == HostDistance.LOCAL: |
| 387 | yield replica |
| 388 | |
| 389 | for host in child.make_query_plan(keyspace, query): |
| 390 | # skip if we've already listed this host |
| 391 | if host not in replicas or \ |
| 392 | child.distance(host) == HostDistance.REMOTE: |
| 393 | yield host |
| 394 | |
| 395 | def on_up(self, *args, **kwargs): |
| 396 | return self._child_policy.on_up(*args, **kwargs) |