diff --git a/swh/storage/cassandra/cql.py b/swh/storage/cassandra/cql.py --- a/swh/storage/cassandra/cql.py +++ b/swh/storage/cassandra/cql.py @@ -59,7 +59,6 @@ DirectoryEntryRow, DirectoryRow, ExtIDByTargetRow, - ExtIDByTargetTypeVersionRow, ExtIDRow, MetadataAuthorityRow, MetadataFetcherRow, @@ -1336,6 +1335,29 @@ def extid_get_from_token(self, token: int, *, statement) -> Iterable[ExtIDRow]: return map(ExtIDRow.from_dict, self._execute_with_retries(statement, [token]),) + @_prepared_select_statement( + ExtIDRow, "WHERE token(extid_type, extid) = ? AND extid_version = ?", + ) + def extid_get_from_token_and_extid_version( + self, token: int, extid_version: int, *, statement + ) -> Iterable[ExtIDRow]: + return map( + ExtIDRow.from_dict, + self._execute_with_retries(statement, [token, extid_version]), + ) + + # @_prepared_select_statement( + # ExtIDRow, + # "WHERE token(extid_type, extid) = ?", + # ) + # def extid_get_from_token_and_extid_version( + # self, token: int, extid_version: int, *, statement + # ) -> Iterable[ExtIDRow]: + # return map( + # ExtIDRow.from_dict, + # self._execute_with_retries(statement, [token]), + # ) + @_prepared_select_statement( ExtIDRow, "WHERE extid_type=? AND extid=?", ) @@ -1365,15 +1387,16 @@ extid_type: Optional[str] = None, extid_version: Optional[int] = None, ) -> Iterable[ExtIDRow]: - if extid_version is not None and extid_type is not None: - extids = self._extid_get_tokens_from_target_with_type_version( - target_type, target, extid_type, extid_version - ) - else: - extids = self._extid_get_tokens_from_target(target_type, target) - for token in extids: + for token in self._extid_get_tokens_from_target(target_type, target): if token is not None: - for extid in self.extid_get_from_token(token): + if extid_type is not None and extid_version is not None: + extids = self.extid_get_from_token_and_extid_version( + token, extid_version + ) + else: + extids = self.extid_get_from_token(token) + + for extid in extids: # re-check the extid against target (in case of murmur3 collision) if ( extid is not None @@ -1403,16 +1426,6 @@ the main 'extid' table.""" self._add_one(statement, row) - @_prepared_insert_statement(ExtIDByTargetTypeVersionRow) - def extid_index_2_add_one( - self, row: ExtIDByTargetTypeVersionRow, *, statement - ) -> None: - """Adds a row mapping extid[target_type, target, extid_type, extid_version] to the token - of the ExtID in the main 'extid' table. - - """ - self._add_one(statement, row) - @_prepared_statement( f""" SELECT target_token @@ -1428,29 +1441,6 @@ for row in self._execute_with_retries(statement, [target_type, target]) ) - @_prepared_statement( - f""" - SELECT target_token - FROM {ExtIDByTargetTypeVersionRow.TABLE} - WHERE target_type = ? AND target = ? and extid_type = ? and extid_version = ? - """ - ) - def _extid_get_tokens_from_target_with_type_version( - self, - target_type: str, - target: bytes, - extid_type: str, - extid_version: int, - *, - statement, - ) -> Iterable[int]: - return ( - row["target_token"] - for row in self._execute_with_retries( - statement, [target_type, target, extid_type, extid_version] - ) - ) - ########################## # Miscellaneous ########################## diff --git a/swh/storage/cassandra/model.py b/swh/storage/cassandra/model.py --- a/swh/storage/cassandra/model.py +++ b/swh/storage/cassandra/model.py @@ -332,16 +332,3 @@ target_type: str target: bytes target_token: int - - -@dataclasses.dataclass -class ExtIDByTargetTypeVersionRow(BaseRow): - TABLE = "extid_by_target_type_version" - PARTITION_KEY = ("target_type", "target", "extid_type", "extid_version") - CLUSTERING_KEY = ("target_token",) - - target_type: str - target: bytes - extid_type: str - extid_version: int - target_token: int diff --git a/swh/storage/cassandra/schema.py b/swh/storage/cassandra/schema.py --- a/swh/storage/cassandra/schema.py +++ b/swh/storage/cassandra/schema.py @@ -281,15 +281,6 @@ target blob, target_token bigint, -- value of token(pk) on the "primary" table PRIMARY KEY ((target_type, target), target_token) -);""", - """ -CREATE TABLE IF NOT EXISTS extid_by_target_type_version ( - target_type ascii, - target blob, - extid_type ascii, - extid_version smallint, - target_token bigint, -- value of token(pk) on the "primary" table - PRIMARY KEY ((target_type, target, extid_type, extid_version), target_token) );""", ] @@ -326,7 +317,6 @@ "metadata_fetcher", "extid", "extid_by_target", - "extid_by_target_type_version", ] HASH_ALGORITHMS = ["sha1", "sha1_git", "sha256", "blake2s256"] diff --git a/swh/storage/cassandra/storage.py b/swh/storage/cassandra/storage.py --- a/swh/storage/cassandra/storage.py +++ b/swh/storage/cassandra/storage.py @@ -72,7 +72,6 @@ DirectoryEntryRow, DirectoryRow, ExtIDByTargetRow, - ExtIDByTargetTypeVersionRow, ExtIDRow, MetadataAuthorityRow, MetadataFetcherRow, @@ -1632,14 +1631,6 @@ target_type=target_type, target=target, target_token=token, ) self._cql_runner.extid_index_add_one(indexrow) - indexrow2 = ExtIDByTargetTypeVersionRow( - target_type=target_type, - target=target, - extid_type=extid.extid_type, - extid_version=extid.extid_version, - target_token=token, - ) - self._cql_runner.extid_index_2_add_one(indexrow2) insertion_finalizer() inserted += 1 return {"extid:add": inserted} diff --git a/swh/storage/in_memory.py b/swh/storage/in_memory.py --- a/swh/storage/in_memory.py +++ b/swh/storage/in_memory.py @@ -31,7 +31,6 @@ DirectoryEntryRow, DirectoryRow, ExtIDByTargetRow, - ExtIDByTargetTypeVersionRow, ExtIDRow, MetadataAuthorityRow, MetadataFetcherRow, @@ -693,9 +692,6 @@ def extid_index_add_one(self, row: ExtIDByTargetRow) -> None: pass - def extid_index_2_add_one(self, row: ExtIDByTargetTypeVersionRow,) -> None: - pass - def extid_get_from_pk( self, extid_type: str, extid: bytes, extid_version: int, target: ExtendedSWHID, ) -> Optional[ExtIDRow]: