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

bugfix(client): model copy compression and fileExisted issue #2402

Merged
merged 1 commit into from
Jun 26, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions client/starwhale/core/model/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ async def _compress_and_upload_blob(
limiter=_cpu_limiter.get(),
)
if compression is None:
if len(compressed) + 2 < len(chunk):
if len(compressed) < len(chunk) * 0.9:
compression = pb2.COMPRESSION_ALGORITHM_LZ4
else:
compression = pb2.COMPRESSION_ALGORITHM_NO_COMPRESSION
await compression_channel.send(compression)
if compression == pb2.COMPRESSION_ALGORITHM_NO_COMPRESSION:
b.extend(chunk)
continue
if len(compressed) > 65536:
if len(compressed) >= 65536:
mid = len(chunk) // 2
c1 = await trio.to_thread.run_sync(
functools.partial(
Expand Down Expand Up @@ -568,6 +568,8 @@ async def _write_blob(
def get_file_from_cache(store: LocalFileStore, path: Path, file: pb2.File) -> bool:
f = store.get(file.md5.hex())
if f is not None and f.exists():
if path.exists():
path.unlink()
f.link(path)
os.chmod(path, file.permission)
_progress.get().advance(_task_id.get(), file.size)
Expand Down
7 changes: 7 additions & 0 deletions client/tests/base/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,13 @@ def compress_chunk(b: bytes) -> t.Any:
self.assertEqual(
b"0" * 65536 + b"1" * 65536 + b"2" * 65536 + b"3" * 65536, data
)
BundleCopy(
src_uri=cloud_uri,
dest_uri=cases[0]["dest_uri"],
typ=ResourceType.model,
dest_local_project_uri=cases[0]["dest_local_project_uri"],
force=True,
).do()

@Mocker()
@respx.mock
Expand Down