Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/model.py
Show All 29 Lines | |||||||||
NULLs (or all-empty blobs) are not allowed in primary keys; instead we use a | NULLs (or all-empty blobs) are not allowed in primary keys; instead we use a | ||||||||
special value that can't possibly be a valid hash. | special value that can't possibly be a valid hash. | ||||||||
""" | """ | ||||||||
T = TypeVar("T", bound="BaseRow") | T = TypeVar("T", bound="BaseRow") | ||||||||
def content_index_table_name(algo: str, skipped_content: bool) -> str: | |||||||||
"""Given an algorithm name, returns the name of one of the 'content_by_*' | |||||||||
ardumontUnsubmitted Not Done Inline Actions
ardumont: | |||||||||
and 'skipped_content_by_*' tables that serve as index for the 'content' | |||||||||
and 'skipped_content' tables based on this algorithm's hashes. | |||||||||
For now it is a simple substitution, but future versions may append a version | |||||||||
number to it, if needed for schema updates.""" | |||||||||
if skipped_content: | |||||||||
return f"skipped_content_by_{algo}" | |||||||||
else: | |||||||||
return f"content_by_{algo}" | |||||||||
class BaseRow: | class BaseRow: | ||||||||
TABLE: ClassVar[str] | TABLE: ClassVar[str] | ||||||||
PARTITION_KEY: ClassVar[Tuple[str, ...]] | PARTITION_KEY: ClassVar[Tuple[str, ...]] | ||||||||
CLUSTERING_KEY: ClassVar[Tuple[str, ...]] = () | CLUSTERING_KEY: ClassVar[Tuple[str, ...]] = () | ||||||||
@classmethod | @classmethod | ||||||||
def from_dict(cls: Type[T], d: Dict[str, Any]) -> T: | def from_dict(cls: Type[T], d: Dict[str, Any]) -> T: | ||||||||
return cls(**d) # type: ignore | return cls(**d) # type: ignore | ||||||||
▲ Show 20 Lines • Show All 241 Lines • ▼ Show 20 Lines | |||||||||
class ExtIDRow(BaseRow): | class ExtIDRow(BaseRow): | ||||||||
TABLE = "extid" | TABLE = "extid" | ||||||||
PARTITION_KEY = ("target", "target_type", "extid", "extid_type") | PARTITION_KEY = ("target", "target_type", "extid", "extid_type") | ||||||||
extid_type: str | extid_type: str | ||||||||
extid: bytes | extid: bytes | ||||||||
target_type: str | target_type: str | ||||||||
target: bytes | target: bytes | ||||||||
@dataclasses.dataclass | |||||||||
class ExtIDByTargetRow(BaseRow): | |||||||||
TABLE = "extid_by_target" | |||||||||
PARTITION_KEY = ("target_type", "target") | |||||||||
CLUSTERING_KEY = ("target_token",) | |||||||||
target_type: str | |||||||||
target: bytes | |||||||||
target_token: int |