Information about the layout of the ring.
| 1703 | |
| 1704 | |
| 1705 | class TokenMap(object): |
| 1706 | """ |
| 1707 | Information about the layout of the ring. |
| 1708 | """ |
| 1709 | |
| 1710 | token_class = None |
| 1711 | """ |
| 1712 | A subclass of :class:`.Token`, depending on what partitioner the cluster uses. |
| 1713 | """ |
| 1714 | |
| 1715 | token_to_host_owner = None |
| 1716 | """ |
| 1717 | A map of :class:`.Token` objects to the :class:`.Host` that owns that token. |
| 1718 | """ |
| 1719 | |
| 1720 | tokens_to_hosts_by_ks = None |
| 1721 | """ |
| 1722 | A map of keyspace names to a nested map of :class:`.Token` objects to |
| 1723 | sets of :class:`.Host` objects. |
| 1724 | """ |
| 1725 | |
| 1726 | ring = None |
| 1727 | """ |
| 1728 | An ordered list of :class:`.Token` instances in the ring. |
| 1729 | """ |
| 1730 | |
| 1731 | _metadata = None |
| 1732 | |
| 1733 | def __init__(self, token_class, token_to_host_owner, all_tokens, metadata): |
| 1734 | self.token_class = token_class |
| 1735 | self.ring = all_tokens |
| 1736 | self.token_to_host_owner = token_to_host_owner |
| 1737 | |
| 1738 | self.tokens_to_hosts_by_ks = {} |
| 1739 | self._metadata = metadata |
| 1740 | self._rebuild_lock = RLock() |
| 1741 | |
| 1742 | def rebuild_keyspace(self, keyspace, build_if_absent=False): |
| 1743 | with self._rebuild_lock: |
| 1744 | try: |
| 1745 | current = self.tokens_to_hosts_by_ks.get(keyspace, None) |
| 1746 | if (build_if_absent and current is None) or (not build_if_absent and current is not None): |
| 1747 | ks_meta = self._metadata.keyspaces.get(keyspace) |
| 1748 | if ks_meta: |
| 1749 | replica_map = self.replica_map_for_keyspace(self._metadata.keyspaces[keyspace]) |
| 1750 | self.tokens_to_hosts_by_ks[keyspace] = replica_map |
| 1751 | except Exception: |
| 1752 | # should not happen normally, but we don't want to blow up queries because of unexpected meta state |
| 1753 | # bypass until new map is generated |
| 1754 | self.tokens_to_hosts_by_ks[keyspace] = {} |
| 1755 | log.exception("Failed creating a token map for keyspace '%s' with %s. PLEASE REPORT THIS: https://datastax-oss.atlassian.net/projects/PYTHON", keyspace, self.token_to_host_owner) |
| 1756 | |
| 1757 | def replica_map_for_keyspace(self, ks_metadata): |
| 1758 | strategy = ks_metadata.replication_strategy |
| 1759 | if strategy: |
| 1760 | return strategy.make_token_replica_map(self.token_to_host_owner, self.ring) |
| 1761 | else: |
| 1762 | return None |
no outgoing calls