Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/postgresql/storage.py
Show First 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | class Storage: | ||||
@timed | @timed | ||||
@process_metrics | @process_metrics | ||||
def content_add(self, content: List[Content]) -> Dict: | def content_add(self, content: List[Content]) -> Dict: | ||||
ctime = now() | ctime = now() | ||||
contents = [attr.evolve(c, ctime=ctime) for c in content] | contents = [attr.evolve(c, ctime=ctime) for c in content] | ||||
# Must add to the objstorage before the DB and journal. Otherwise: | |||||
# 1. in case of a crash the DB may "believe" we have the content, but | |||||
# we didn't have time to write to the objstorage before the crash | |||||
# 2. the objstorage mirroring, which reads from the journal, may attempt to | |||||
# read from the objstorage before we finished writing it | |||||
objstorage_summary = self.objstorage.content_add(contents) | objstorage_summary = self.objstorage.content_add(contents) | ||||
with self.db() as db: | with self.db() as db: | ||||
with db.transaction() as cur: | with db.transaction() as cur: | ||||
missing = list( | missing = list( | ||||
self.content_missing( | self.content_missing( | ||||
map(Content.to_dict, contents), | map(Content.to_dict, contents), | ||||
key_hash="sha1_git", | key_hash="sha1_git", | ||||
▲ Show 20 Lines • Show All 1,179 Lines • Show Last 20 Lines |