Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show All 26 Lines | |||||
from . import converters, HashCollision | from . import converters, HashCollision | ||||
from .common import db_transaction_generator, db_transaction | from .common import db_transaction_generator, db_transaction | ||||
from .db import Db | from .db import Db | ||||
from .exc import StorageArgumentException, StorageDBError | from .exc import StorageArgumentException, StorageDBError | ||||
from .algos import diff | from .algos import diff | ||||
from .metrics import timed, send_metric, process_metrics | from .metrics import timed, send_metric, process_metrics | ||||
from .utils import ( | from .utils import ( | ||||
get_partition_bounds_bytes, extract_collision_hash | get_partition_bounds_bytes, extract_collision_hash, content_hex_hashes | ||||
) | ) | ||||
from .writer import JournalWriter | from .writer import JournalWriter | ||||
# Max block size of contents to return | # Max block size of contents to return | ||||
BULK_BLOCK_CONTENT_LEN_MAX = 10000 | BULK_BLOCK_CONTENT_LEN_MAX = 10000 | ||||
EMPTY_SNAPSHOT_ID = hash_to_bytes('1a8893e6a86f444e8be8e7bda6cb34fb1735a00e') | EMPTY_SNAPSHOT_ID = hash_to_bytes('1a8893e6a86f444e8be8e7bda6cb34fb1735a00e') | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | def _content_add_metadata(self, db, cur, content): | ||||
'content_sha256_idx': 'sha256', | 'content_sha256_idx': 'sha256', | ||||
} | } | ||||
hash_name = constraint_to_hash_name \ | hash_name = constraint_to_hash_name \ | ||||
.get(e.diag.constraint_name) | .get(e.diag.constraint_name) | ||||
hash_id = None | hash_id = None | ||||
collision_contents_hashes = None | collision_contents_hashes = None | ||||
raise HashCollision( | raise HashCollision( | ||||
hash_name, hash_id, collision_contents_hashes | hash_name, hash_id, [ | ||||
content_hex_hashes(c) | |||||
for c in collision_contents_hashes | |||||
] | |||||
) from None | ) from None | ||||
else: | else: | ||||
raise | raise | ||||
@timed | @timed | ||||
@process_metrics | @process_metrics | ||||
def content_add( | def content_add( | ||||
self, content: Iterable[Content]) -> Dict: | self, content: Iterable[Content]) -> Dict: | ||||
▲ Show 20 Lines • Show All 953 Lines • Show Last 20 Lines |