FEAT: streamed upload with checksum in `StorageBackend.put_file`

未關閉
#1,745 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 5 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
aws, python
領域
backend, cloud

研究方向

Start in src/datajoint/storage.py at StorageBackend.put_file and the companion safe_copy path to see how the file and s3 stores currently copy bytes. The issue leaves the API shape open, so first settle whether checksum returns a digest or takes an expected value, then trace how each backend writes and moves files. Done means a single-read streamed copy with mismatch rejection, no leftover file, and tests covering both the file and s3 backends.

由索引模型根據 Issue 內容生成。

描述

enhancement

Feature Request

Problem

We keep large raw recordings (often tens of GB) in a <filepath@store> column, at a content-addressed
path sha256/ab/<sha256>. The same code writes to a file store on lab servers and an s3 store
centrally. With StorageBackend.put_file we must read each file twice (hash it, then copy it) and
cannot check that the stored bytes are the ones we hashed: if the source changes between the two reads,
the store holds other bytes under that hash. DataJoint's hash-addressed codecs avoid this only by
holding the whole value in memory (<attach@> reads the full file), which does not work for large files.

Requirements
  • put_file can compute a checksum while it copies, reading the source once, and return it, e.g.
    digest = backend.put_file(src, dest, checksum="sha256").
  • It can check an expected checksum and refuse a mismatch without leaving the file in place, e.g.
    backend.put_file(src, dest, checksum=("sha256", expected_hex)).
  • file protocol: write to a unique temp file and move it into place only when the checksum matches.
  • s3: send the checksum as an S3 additional checksum (x-amz-checksum-sha256) so the server
    rejects a mismatch, or upload to a temp key and copy it into place.
Justification
  • Large files go into a store once, checked, without reading them twice.
  • Content-addressed layouts (any path derived from a hash) become safe with DataJoint's own backend,
    instead of each project writing its own copy-and-check code.
  • <attach@> and <hash@> could then stream large files instead of reading them into memory.
Alternative Considerations

Our workaround: hash the file, put_file it, compare the stored size, and audit later by re-reading
the stored copy. This misses a same-size change between the two reads. Writing our own streamed copy
on fsspec works, but duplicates what StorageBackend is for.

Related Errors

None: without the feature, a mismatch goes unnoticed.

Screenshots

n/a

Additional Research and Context
  • StorageBackend.put_file: src/datajoint/storage.py (v2.3.6 and master); no checksum option.
  • The file path goes through safe_copy, see the companion issue on safe_copy / os.replace.
  • No open issue or PR found for checksums in put_file.
  • Would a PR along these lines be welcome, and which API shape do you prefer?
主要語言
Python
星號
198
分支
107
平均合併
4 天 7 小時
30 天內合併 PR
12

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

datajoint/datajoint-python 的其他 Issue

查看 datajoint/datajoint-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。