diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index e0aeeaeb8..1a1feeff4 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -35440,120 +35440,6 @@ } } ], - "./src/orcapod/hashing/migrate_hash_cache.py": [ - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 20, - "lineCount": 1 - } - }, - { - "code": "reportImplicitStringConcatenation", - "range": { - "startColumn": 12, - "endColumn": 59, - "lineCount": 2 - } - }, - { - "code": "reportImplicitStringConcatenation", - "range": { - "startColumn": 16, - "endColumn": 57, - "lineCount": 2 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 15, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 30, - "endColumn": 33, - "lineCount": 1 - } - }, - { - "code": "reportUnusedCallResult", - "range": { - "startColumn": 12, - "endColumn": 51, - "lineCount": 1 - } - }, - { - "code": "reportImplicitStringConcatenation", - "range": { - "startColumn": 16, - "endColumn": 47, - "lineCount": 2 - } - }, - { - "code": "reportUnusedCallResult", - "range": { - "startColumn": 8, - "endColumn": 9, - "lineCount": 4 - } - }, - { - "code": "reportImplicitStringConcatenation", - "range": { - "startColumn": 12, - "endColumn": 61, - "lineCount": 2 - } - }, - { - "code": "reportUnusedCallResult", - "range": { - "startColumn": 8, - "endColumn": 47, - "lineCount": 1 - } - }, - { - "code": "reportImplicitStringConcatenation", - "range": { - "startColumn": 12, - "endColumn": 62, - "lineCount": 2 - } - }, - { - "code": "reportUnusedCallResult", - "range": { - "startColumn": 4, - "endColumn": 5, - "lineCount": 5 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 30, - "endColumn": 42, - "lineCount": 1 - } - }, - { - "code": "reportAny", - "range": { - "startColumn": 30, - "endColumn": 42, - "lineCount": 1 - } - } - ], "./src/orcapod/hashing/postgres_hash_cacher.py": [ { "code": "reportImplicitStringConcatenation", diff --git a/changelog.d/ITL-1488.md b/changelog.d/ITL-1488.md new file mode 100644 index 000000000..f71ca21ce --- /dev/null +++ b/changelog.d/ITL-1488.md @@ -0,0 +1,24 @@ +### Fixed + +- File hash caches now key entries by path, modification time, size, and algorithm. + Hashes for different algorithms coexist. A hasher declares its hash label through + `FileContentHasherProtocol.hash_algorithm`, and the cache key carries it in the + provisional `FileHashKey.algorithm` field. +- A cache put raises `ValueError` for a mismatched label, an invalid digest length, + or a different well-formed hash already stored under the same key. Putting an + identical hash preserves its timestamp. SQLite and PostgreSQL treat malformed + stored values as misses. The next valid put for the same key replaces the + malformed value, refreshes its timestamp, and logs a warning naming the file + and algorithm. + +### Changed + +- Scripts can now detect per-file errors, including `--force` conflicts, through the `orcapod warm-cache` exit status `1`. + +### Breaking changes and migration + +- SQLite and PostgreSQL use `file_hash_cache_v2` (schema version 2) and leave the + previous `file_hash_cache` table untouched. The old SQLite migration helper + was removed. ITL-1535 tracks migration of both older SQLite layouts (with and + without `cached_at`). Until migration is available, let the next pipeline run + or `orcapod warm-cache` hash the files once more to fill the new table. diff --git a/docs/concepts/file-hash-caching.md b/docs/concepts/file-hash-caching.md index b738a7d2b..cb5705e36 100644 --- a/docs/concepts/file-hash-caching.md +++ b/docs/concepts/file-hash-caching.md @@ -16,17 +16,52 @@ default, configurable via the `algorithm` argument). It does this every time, with no memory of previous results. `HashCacher` is a protocol for any object that maps a `FileHashKey` to a -`ContentHash`. The key is a three-field struct: +`ContentHash`. The key is a four-field struct: ``` -FileHashKey(path, mtime_ns, size) +FileHashKey(path, mtime_ns, size, algorithm) ``` -The `mtime_ns` and `size` fields encode the file's identity at a specific -point in time. If the file is modified — its modification time or byte count -changes — the key is different, so the old entry is never returned. You do -not need to explicitly invalidate entries; the key change handles it -automatically. +An ordinary lookup trusts the file's resolved path, nanosecond modification +time, and byte size. A change to any of these fields gives the file a +different key in the default lookup mode. If a file is rewritten to the same +size at the same path and its original modification time is restored, the +lookup returns the cached hash without reading the file. This hit bypasses +the write and its conflict check. + +`FileHashKey.algorithm` is **PROVISIONAL**. Its value is the hash label +(`ContentHash.method`) reported by the file hasher's `hash_algorithm` property. +The cache stores each algorithm's hash separately for a given file state. +For example, `orcapod warm-cache --algorithm md5` fills MD5 entries. A later +SHA-256 lookup can fill its own entries alongside them. + +A cache write raises `ValueError` if the hash label or digest length is invalid +for the key, or if the key already holds a different well-formed hash. Writing +an identical hash leaves the existing entry and its timestamp unchanged. Reads +accept values in the exact format `