Skip to content

Commit

Permalink
bugfix(client):
Browse files Browse the repository at this point in the history
  1. improve compression judgement logics
  2. fix a boundary error when dealing with compressed chunks
  3. fix FileExistsError when copy model with force
  • Loading branch information
xuchuan committed Jun 26, 2023
1 parent fe1f3e3 commit 8201185
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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

0 comments on commit 8201185

Please sign in to comment.