Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transfer: add naive objects transfer function #64

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/dvc_objects/transfer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import TYPE_CHECKING, Set

if TYPE_CHECKING:
from .db import ObjectDB


def transfer(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking about whether we even need this function. Based on how we calculate status on dvc-data side, the logic here will not be reusable there. Although, this will be useful for the naive transfer of objects.

src: "ObjectDB", dest: "ObjectDB", oids: Set["str"], jobs: int = None
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a question of how oids will be discovered by the caller. I guess it's a responsibility of odb.

See iterative/dvc#7874.

) -> Set["str"]:
src_exists = set(src.oids_exist(oids, jobs=jobs))
src_missing = oids - src_exists

dest_exists = set(dest.oids_exist(oids, jobs=jobs))
dest_missing = oids - dest_exists

missing = dest_missing & src_missing
new = src_exists - dest_exists

for oid in new:
path = src.oid_to_path(oid)
dest.add(path, src.fs, oid)
Comment on lines +19 to +21
Copy link
Member Author

@skshetry skshetry Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add batching support, as soon as ObjectDB.add gets batching support.


if missing:
raise Exception("missing objects", missing)
return new
11 changes: 11 additions & 0 deletions tests/test_transfer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dvc_objects.db import ObjectDB
from dvc_objects.transfer import transfer


def test_transfer(memfs):
src = ObjectDB(memfs, "/odb1")
dest = ObjectDB(memfs, "/odb2")

src.add_bytes("1234", b"content")
assert transfer(src, dest, {"1234"}) == {"1234"}
assert dest.exists("1234")