diff --git a/swh/objstorage/backends/winery/objstorage.py b/swh/objstorage/backends/winery/objstorage.py --- a/swh/objstorage/backends/winery/objstorage.py +++ b/swh/objstorage/backends/winery/objstorage.py @@ -141,14 +141,14 @@ self.shard.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: - return obj_id + return shard = self.base.add_phase_1(obj_id) if shard != self.base.id: # this object is the responsibility of another shard - return obj_id + return self.shard.add(obj_id, content) self.base.add_phase_2(obj_id) @@ -156,8 +156,6 @@ if self.shard.is_full(): self.pack() - return obj_id - def check(self, obj_id: ObjId) -> None: # load all shards packing == True and not locked (i.e. packer # was interrupted for whatever reason) run pack for each of them diff --git a/swh/objstorage/tests/test_objstorage_winery.py b/swh/objstorage/tests/test_objstorage_winery.py --- a/swh/objstorage/tests/test_objstorage_winery.py +++ b/swh/objstorage/tests/test_objstorage_winery.py @@ -97,13 +97,14 @@ def test_winery_add_get(winery): shard = winery.base.whoami content = b"SOMETHING" - obj_id = winery.add(content=content, obj_id=compute_hash(content, "sha256")) + obj_id = compute_hash(content, "sha256") assert ( obj_id.hex() == "866878b165607851782d8d233edf0c261172ff67926330d3bbd10c705b92d24f" ) - assert winery.add(content=content, obj_id=obj_id) == obj_id - assert winery.add(content=content, obj_id=obj_id, check_presence=False) == obj_id + winery.add(content=content, obj_id=obj_id) + winery.add(content=content, obj_id=obj_id) + winery.add(content=content, obj_id=obj_id, check_presence=False) assert winery.base.whoami == shard assert winery.get(obj_id) == content with pytest.raises(exc.ObjNotFoundError): @@ -116,11 +117,7 @@ mocker.patch("swh.objstorage.backends.winery.objstorage.pack", return_value=True) shard = winery.base.whoami content = b"SOMETHING" - obj_id = winery.add(content=content, obj_id=compute_hash(content, "sha256")) - assert ( - obj_id.hex() - == "866878b165607851782d8d233edf0c261172ff67926330d3bbd10c705b92d24f" - ) + winery.add(content=content, obj_id=compute_hash(content, "sha256")) assert winery.base.whoami != shard assert len(winery.packers) == 1 packer = winery.packers[0]