Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/backends/winery/objstorage.py
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | class WineryWriter(WineryReader): | ||||
def init(self): | def init(self): | ||||
super().init() | super().init() | ||||
self.shard = RWShard(self.base.whoami, **self.args) | self.shard = RWShard(self.base.whoami, **self.args) | ||||
def uninit(self): | def uninit(self): | ||||
self.shard.uninit() | self.shard.uninit() | ||||
super().uninit() | super().uninit() | ||||
def add(self, content: bytes, obj_id: ObjId, check_presence: bool = True) -> ObjId: | def add(self, content: bytes, obj_id: ObjId, check_presence: bool = True) -> None: | ||||
if check_presence and obj_id in self: | if check_presence and obj_id in self: | ||||
return obj_id | return | ||||
shard = self.base.add_phase_1(obj_id) | shard = self.base.add_phase_1(obj_id) | ||||
if shard != self.base.id: | if shard != self.base.id: | ||||
# this object is the responsibility of another shard | # this object is the responsibility of another shard | ||||
return obj_id | return | ||||
self.shard.add(obj_id, content) | self.shard.add(obj_id, content) | ||||
self.base.add_phase_2(obj_id) | self.base.add_phase_2(obj_id) | ||||
if self.shard.is_full(): | if self.shard.is_full(): | ||||
self.pack() | self.pack() | ||||
return obj_id | |||||
def check(self, obj_id: ObjId) -> None: | def check(self, obj_id: ObjId) -> None: | ||||
# load all shards packing == True and not locked (i.e. packer | # load all shards packing == True and not locked (i.e. packer | ||||
# was interrupted for whatever reason) run pack for each of them | # was interrupted for whatever reason) run pack for each of them | ||||
pass | pass | ||||
def pack(self): | def pack(self): | ||||
self.base.shard_packing_starts() | self.base.shard_packing_starts() | ||||
p = Process(target=pack, args=(self.shard.name,), kwargs=self.args) | p = Process(target=pack, args=(self.shard.name,), kwargs=self.args) | ||||
Show All 9 Lines |