tensorfs 0.3.51__tar.gz → 0.3.55__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tensorfs might be problematic. Click here for more details.

Files changed (144) hide show
  1. {tensorfs-0.3.51 → tensorfs-0.3.55}/Cargo.lock +21 -2
  2. {tensorfs-0.3.51 → tensorfs-0.3.55}/Cargo.toml +1 -1
  3. {tensorfs-0.3.51 → tensorfs-0.3.55}/PKG-INFO +1 -1
  4. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/Cargo.toml +3 -0
  5. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/bin/tfs/fetch.rs +8 -0
  6. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/cache_roots.rs +11 -10
  7. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/catalog.rs +269 -75
  8. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/derived/graft_tests.rs +2 -2
  9. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/err.rs +1 -0
  10. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/fetch.rs +2 -0
  11. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/lib.rs +1 -0
  12. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/meta.rs +1 -1
  13. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/read.rs +2 -0
  14. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/reclaim.rs +2 -1
  15. tensorfs-0.3.55/crates/tensorfs-core/src/repo_cache/identity.rs +161 -0
  16. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/repo_cache.rs +174 -18
  17. tensorfs-0.3.55/crates/tensorfs-core/src/stats.rs +50 -0
  18. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/storage.rs +323 -4
  19. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/store.rs +249 -77
  20. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/http.rs +187 -28
  21. tensorfs-0.3.55/crates/tensorfs-core/src/transport/http_reuse_tests.rs +603 -0
  22. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/ledger.rs +32 -1
  23. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/mod.rs +2 -1
  24. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/pull.rs +209 -108
  25. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/ranged.rs +5 -8
  26. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/tests.rs +253 -31
  27. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/repo_cache.rs +9 -2
  28. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/source_artifacts.rs +2 -9
  29. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/store_boundaries.rs +77 -0
  30. tensorfs-0.3.55/crates/tensorfs-core/tests/trust_index.rs +157 -0
  31. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-py/src/lib.rs +13 -0
  32. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-py/src/store.rs +84 -15
  33. {tensorfs-0.3.51 → tensorfs-0.3.55}/pyproject.toml +1 -1
  34. {tensorfs-0.3.51 → tensorfs-0.3.55}/python/tensorfs/__init__.py +4 -0
  35. {tensorfs-0.3.51 → tensorfs-0.3.55}/python/tensorfs/_ext.pyi +17 -1
  36. {tensorfs-0.3.51 → tensorfs-0.3.55}/python/tensorfs/errors.py +2 -0
  37. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/build.rs +0 -0
  38. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/examples/h3-swiglu-layout.md +0 -0
  39. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/examples/optional-cache-backfill.md +0 -0
  40. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/examples/resident-conversion.md +0 -0
  41. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/examples/resident_conversion_profile.rs +0 -0
  42. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/asset_update.rs +0 -0
  43. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/b64.rs +0 -0
  44. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/bin/tfs/ckpt.rs +0 -0
  45. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/bin/tfs/conform.rs +0 -0
  46. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/bin/tfs/ingest.rs +0 -0
  47. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/bin/tfs/main.rs +0 -0
  48. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/bin/tfs/rd.rs +0 -0
  49. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/bin/tfs/repo.rs +0 -0
  50. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/bin/tfs/snap.rs +0 -0
  51. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/bin/tfs/watch.rs +0 -0
  52. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/canon.rs +0 -0
  53. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/capability.rs +0 -0
  54. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/cbor.rs +0 -0
  55. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/checkpoint.rs +0 -0
  56. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/checkpoint_root.rs +0 -0
  57. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/corpus.rs +0 -0
  58. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/derived/adoption.rs +0 -0
  59. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/derived/companion_tests.rs +0 -0
  60. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/derived/estimate.rs +0 -0
  61. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/derived/progress.rs +0 -0
  62. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/derived/resume_tests.rs +0 -0
  63. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/derived/retention.rs +0 -0
  64. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/derived/roots.rs +0 -0
  65. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/derived.rs +0 -0
  66. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/dtype.rs +0 -0
  67. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/durability.rs +0 -0
  68. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/fill.rs +0 -0
  69. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/fit.rs +0 -0
  70. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/gc.rs +0 -0
  71. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/header.rs +0 -0
  72. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/home.rs +0 -0
  73. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ids.rs +0 -0
  74. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/carrier.rs +0 -0
  75. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/convert.rs +0 -0
  76. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/fingerprint.rs +0 -0
  77. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/gguf.rs +0 -0
  78. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/h3_lora.rs +0 -0
  79. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/journal.rs +0 -0
  80. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/mod.rs +0 -0
  81. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/preflight.rs +0 -0
  82. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/source.rs +0 -0
  83. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/stamp.rs +0 -0
  84. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/ingest/transaction.rs +0 -0
  85. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/jcs.rs +0 -0
  86. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/limits.rs +0 -0
  87. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/machine.rs +0 -0
  88. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/manifest.rs +0 -0
  89. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/project.rs +0 -0
  90. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/providers.rs +0 -0
  91. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/receipt.rs +0 -0
  92. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/registry.rs +0 -0
  93. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/relation.rs +0 -0
  94. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/repository.rs +0 -0
  95. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/sha256.rs +0 -0
  96. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/source_artifact.rs +0 -0
  97. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/spec.rs +0 -0
  98. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/staging.rs +0 -0
  99. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/api.rs +0 -0
  100. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/hub.rs +0 -0
  101. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/policy.rs +0 -0
  102. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/prefix.rs +0 -0
  103. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/push.rs +0 -0
  104. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/transport/speculate.rs +0 -0
  105. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/src/vectors.rs +0 -0
  106. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/checkpoint_roots.rs +0 -0
  107. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/fetch_url_progress.rs +0 -0
  108. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/fit.rs +0 -0
  109. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/fixtures/repo_apply/blobs.jsonl +0 -0
  110. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/fixtures/repo_apply/expected_list.jsonl +0 -0
  111. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/fixtures/repo_apply/expected_repository.json +0 -0
  112. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/fixtures/repo_apply/expected_rows.jsonl +0 -0
  113. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/fixtures/repo_apply/header.cbor +0 -0
  114. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/fixtures/repo_apply/manifest.json +0 -0
  115. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/fixtures/repo_apply/mutation.json +0 -0
  116. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/h3_lora.rs +0 -0
  117. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/h3_swiglu.rs +0 -0
  118. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/home.rs +0 -0
  119. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/import_tree.rs +0 -0
  120. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/instrument_profiles.rs +0 -0
  121. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/liveness.rs +0 -0
  122. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/qwen_image21_profile.rs +0 -0
  123. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/read_plan.rs +0 -0
  124. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/reclaim.rs +0 -0
  125. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/reclaim_run.rs +0 -0
  126. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/repo_store.rs +0 -0
  127. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/resident_admission.rs +0 -0
  128. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/sha256_backends.rs +0 -0
  129. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/sharded_cas.rs +0 -0
  130. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/source_plan.rs +0 -0
  131. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/source_prefixes.rs +0 -0
  132. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/source_preflight.rs +0 -0
  133. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/staging.rs +0 -0
  134. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/tensor_schema.rs +0 -0
  135. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/version.rs +0 -0
  136. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-core/tests/write_through.rs +0 -0
  137. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-py/Cargo.toml +0 -0
  138. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-py/src/docs.rs +0 -0
  139. {tensorfs-0.3.51 → tensorfs-0.3.55}/crates/tensorfs-py/src/errors.rs +0 -0
  140. {tensorfs-0.3.51 → tensorfs-0.3.55}/python/tensorfs/_derived_channel.py +0 -0
  141. {tensorfs-0.3.51 → tensorfs-0.3.55}/python/tensorfs/_source_channel.py +0 -0
  142. {tensorfs-0.3.51 → tensorfs-0.3.55}/python/tensorfs/_tensors.py +0 -0
  143. {tensorfs-0.3.51 → tensorfs-0.3.55}/python/tensorfs/derived.py +0 -0
  144. {tensorfs-0.3.51 → tensorfs-0.3.55}/python/tensorfs/py.typed +0 -0
@@ -42,6 +42,12 @@ version = "1.0.4"
42
42
  source = "registry+https://github.com/rust-lang/crates.io-index"
43
43
  checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
44
44
 
45
+ [[package]]
46
+ name = "cfg_aliases"
47
+ version = "0.2.2"
48
+ source = "registry+https://github.com/rust-lang/crates.io-index"
49
+ checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
50
+
45
51
  [[package]]
46
52
  name = "deranged"
47
53
  version = "0.5.8"
@@ -150,6 +156,18 @@ version = "2.3.0"
150
156
  source = "registry+https://github.com/rust-lang/crates.io-index"
151
157
  checksum = "c12b4033ffaa92fbf9df03df38d19324f52bad130dd223f811734a8006dd2d69"
152
158
 
159
+ [[package]]
160
+ name = "nix"
161
+ version = "0.31.3"
162
+ source = "registry+https://github.com/rust-lang/crates.io-index"
163
+ checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d"
164
+ dependencies = [
165
+ "bitflags",
166
+ "cfg-if",
167
+ "cfg_aliases",
168
+ "libc",
169
+ ]
170
+
153
171
  [[package]]
154
172
  name = "num-conv"
155
173
  version = "0.2.2"
@@ -421,11 +439,12 @@ checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
421
439
 
422
440
  [[package]]
423
441
  name = "tensorfs-core"
424
- version = "0.3.51"
442
+ version = "0.3.55"
425
443
  dependencies = [
426
444
  "fs2",
427
445
  "libc",
428
446
  "minicbor",
447
+ "nix",
429
448
  "rcgen",
430
449
  "rusqlite",
431
450
  "rustix",
@@ -435,7 +454,7 @@ dependencies = [
435
454
 
436
455
  [[package]]
437
456
  name = "tensorfs-py"
438
- version = "0.3.51"
457
+ version = "0.3.55"
439
458
  dependencies = [
440
459
  "pyo3",
441
460
  "tensorfs-core",
@@ -3,5 +3,5 @@ resolver = "2"
3
3
  members = ["crates/tensorfs-core", "crates/tensorfs-py"]
4
4
 
5
5
  [workspace.package]
6
- version = "0.3.51"
6
+ version = "0.3.55"
7
7
  edition = "2021"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tensorfs
3
- Version: 0.3.51
3
+ Version: 0.3.55
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Rust
@@ -17,6 +17,9 @@ rustix = { version = "1.1.4", default-features = false, features = ["fs", "std",
17
17
  rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
18
18
  webpki-roots = "0.26"
19
19
 
20
+ [target.'cfg(target_os = "linux")'.dependencies]
21
+ nix = { version = "0.31.3", default-features = false, features = ["fs", "user"] }
22
+
20
23
  [dev-dependencies]
21
24
  libc = "0.2"
22
25
  rcgen = "0.13"
@@ -305,6 +305,14 @@ fn pull_with_budget(
305
305
  if !tensorfs_core::repo_cache::finish_optional_backfills() {
306
306
  eprintln!("repo cache replication incomplete; local fetch remains complete");
307
307
  }
308
+ // Exactly one model pull owns this receipt; a shared library process may
309
+ // concurrently finish other pulls without contaminating this observation.
310
+ let quoted = |value: &str| String::from_utf8(canon::write(&canon::Value::str(value))).unwrap();
311
+ eprintln!(
312
+ "{{\"event\":\"pull.cache\",\"model\":{},\"manifest\":{},\"scope\":{},\"cache_written_bytes\":{},\"cache_bytes\":{},\"total_bytes\":{}}}",
313
+ quoted(&report.model), quoted(&report.manifest), quoted(&report.scope),
314
+ report.cache_writes.bytes(), report.bytes_cached, report.bytes_total,
315
+ );
308
316
  println!(
309
317
  "model {}@{} lane {}",
310
318
  report.model, report.release, report.lane
@@ -3,17 +3,15 @@
3
3
 
4
4
  use std::fs::{self, OpenOptions};
5
5
  use std::io::Write;
6
+ use std::os::unix::fs::OpenOptionsExt;
6
7
  use std::path::PathBuf;
7
8
 
8
- use crate::err::{Code, Refusal, Result};
9
+ use crate::err::{Refusal, Result};
9
10
  use crate::repository::RepositoryName;
10
11
  use crate::store::Store;
11
12
 
12
13
  fn io(error: std::io::Error) -> Refusal {
13
- Refusal {
14
- code: Code::IO_FAILED,
15
- detail: format!("cache root provenance: {error}"),
16
- }
14
+ crate::store::classify_io("cache root provenance", error)
17
15
  }
18
16
 
19
17
  fn path(store: &Store, repo: &RepositoryName) -> PathBuf {
@@ -48,7 +46,7 @@ pub(crate) fn clear(store: &Store, repo: &RepositoryName) -> Result<()> {
48
46
  pub(crate) fn record(store: &Store, repo: &RepositoryName, body: &[u8]) -> Result<()> {
49
47
  let path = path(store, repo);
50
48
  let parent = path.parent().unwrap();
51
- fs::create_dir_all(parent).map_err(io)?;
49
+ store.prepare_owned_directory(parent)?;
52
50
  let temporary = parent.join(format!(
53
51
  ".cache-root-{}-{}",
54
52
  repo.name,
@@ -58,10 +56,12 @@ pub(crate) fn record(store: &Store, repo: &RepositoryName, body: &[u8]) -> Resul
58
56
  let mut file = OpenOptions::new()
59
57
  .write(true)
60
58
  .create_new(true)
59
+ .mode(0o600)
61
60
  .open(&temporary)
62
61
  .map_err(io)?;
63
62
  file.write_all(crate::sha256::hex_digest(body).as_bytes())
64
63
  .map_err(io)?;
64
+ store.assign_new_metadata_owner(&file)?;
65
65
  file.sync_all().map_err(io)?;
66
66
  fs::rename(&temporary, &path).map_err(io)?;
67
67
  crate::store::fsync_dir(parent)
@@ -128,6 +128,7 @@ pub(crate) fn reap(store: &Store, limit: usize) -> Result<u64> {
128
128
  mod tests {
129
129
  use super::*;
130
130
  use crate::catalog::WriterGuard;
131
+ use crate::err::Code;
131
132
  use crate::ids::{Doc, ObjectRef};
132
133
  use crate::manifest::{Draft, Entry};
133
134
  use crate::repository::{Mutation, Repository};
@@ -166,7 +167,7 @@ mod tests {
166
167
  };
167
168
  if cached {
168
169
  self.store
169
- .apply_cached_repository(None, &mutation, &Fault::default())
170
+ .apply_cached_repository(None, &[mutation], &Fault::default())
170
171
  .unwrap();
171
172
  } else {
172
173
  self.store
@@ -214,7 +215,7 @@ mod tests {
214
215
  .apply_repository(Some(&body), &mutation, &Fault::default())
215
216
  .unwrap();
216
217
  f.store
217
- .apply_cached_repository(Some(&body), &mutation, &Fault::default())
218
+ .apply_cached_repository(Some(&body), &[mutation], &Fault::default())
218
219
  .unwrap();
219
220
  assert!(!matches(&f.store, &repo, &body).unwrap());
220
221
  }
@@ -309,7 +310,7 @@ mod tests {
309
310
  f.store
310
311
  .apply_cached_repository(
311
312
  Some(&body),
312
- &Mutation::UpdateRelease {
313
+ &[Mutation::UpdateRelease {
313
314
  repo: repo.clone(),
314
315
  version: "1".into(),
315
316
  expected_revision: 0,
@@ -318,7 +319,7 @@ mod tests {
318
319
  lane: "bf16".into(),
319
320
  manifest,
320
321
  }],
321
- },
322
+ }],
322
323
  &Fault::default(),
323
324
  )
324
325
  .unwrap();
@@ -1,8 +1,11 @@
1
1
  //! SQLite is a rebuildable projection and operation coordinator. Repository/manifests/blobs
2
2
  //! remain the authority; SQL is never consulted to decide GC liveness.
3
3
 
4
+ use std::collections::HashMap;
4
5
  use std::fs::{self, File};
6
+ use std::os::unix::fs::MetadataExt;
5
7
  use std::path::{Path, PathBuf};
8
+ use std::sync::{Arc, Mutex, OnceLock, RwLock, Weak};
6
9
  use std::time::Duration;
7
10
 
8
11
  use fs2::FileExt;
@@ -57,10 +60,7 @@ fn sql(what: impl AsRef<str>, error: rusqlite::Error) -> Refusal {
57
60
  }
58
61
 
59
62
  fn io(what: impl AsRef<str>, error: std::io::Error) -> Refusal {
60
- Refusal {
61
- code: Code::IO_FAILED,
62
- detail: format!("{}: {error}", what.as_ref()),
63
- }
63
+ crate::store::classify_io(what, error)
64
64
  }
65
65
 
66
66
  fn verify_schema(connection: &Connection) -> Result<()> {
@@ -114,6 +114,199 @@ fn verify_schema(connection: &Connection) -> Result<()> {
114
114
  Ok(())
115
115
  }
116
116
 
117
+ fn opened() -> &'static Mutex<HashMap<PathBuf, u64>> {
118
+ static OPENED: OnceLock<Mutex<HashMap<PathBuf, u64>>> = OnceLock::new();
119
+ OPENED.get_or_init(Default::default)
120
+ }
121
+
122
+ /// Connections this process has opened to the catalog under `root`. The trust path's
123
+ /// contract is one per catalog file per process; this makes it observable.
124
+ pub fn connections_opened(root: &Path) -> u64 {
125
+ opened()
126
+ .lock()
127
+ .unwrap_or_else(|error| error.into_inner())
128
+ .get(&Catalog::path(root))
129
+ .copied()
130
+ .unwrap_or(0)
131
+ }
132
+
133
+ fn connect(path: &Path) -> Result<Connection> {
134
+ *opened()
135
+ .lock()
136
+ .unwrap_or_else(|error| error.into_inner())
137
+ .entry(path.to_path_buf())
138
+ .or_default() += 1;
139
+ crate::stats::catalog_opened();
140
+ let connection = Connection::open(path).map_err(|error| sql("open catalog", error))?;
141
+ connection
142
+ .busy_timeout(BUSY_TIMEOUT)
143
+ .map_err(|error| sql("set catalog busy timeout", error))?;
144
+ connection
145
+ .execute_batch("PRAGMA foreign_keys=ON; PRAGMA synchronous=FULL;")
146
+ .map_err(|error| sql("configure catalog", error))?;
147
+ Ok(connection)
148
+ }
149
+
150
+ /// A connection to an existing catalog of exactly this schema.
151
+ fn validated(path: &Path) -> Result<Connection> {
152
+ if !path.is_file() {
153
+ return refuse(
154
+ Code::DURABILITY_UNPROVEN,
155
+ format!(
156
+ "{} is absent; store is recovery-only until `tfs store rebuild`",
157
+ path.display()
158
+ ),
159
+ );
160
+ }
161
+ let connection = connect(path)?;
162
+ let version: u64 = connection
163
+ .query_row("PRAGMA user_version", [], |row| row.get(0))
164
+ .map_err(|error| sql("read catalog version", error))?;
165
+ if version != SCHEMA_VERSION {
166
+ return refuse(
167
+ Code::UNKNOWN_FORMAT,
168
+ format!("tensorfs.sqlite user_version {version} != {SCHEMA_VERSION}"),
169
+ );
170
+ }
171
+ verify_schema(&connection)?;
172
+ Ok(connection)
173
+ }
174
+
175
+ /// THE PROCESS'S TRUST INDEX: every `tensorfs_verified_blobs` row of one catalog, loaded
176
+ /// with one query the first time any handle asks, then answered from memory.
177
+ ///
178
+ /// A row is a cache fact bound to `(dev, ino, length, mtime)`; the caller still compares it
179
+ /// with the object's `fstat`. A remembered row therefore stays sound after another process
180
+ /// drops it: unchanged bytes under the same binding are the bytes that were hashed, and
181
+ /// anything that changed them fails the comparison and pays its rehash. A miss asks the one
182
+ /// kept connection, so rows written by other processes are seen; a replaced catalog file
183
+ /// (rebuild) is reopened and reloaded. In-process writes and drops update the index directly.
184
+ pub(crate) struct Trust {
185
+ path: PathBuf,
186
+ rows: RwLock<HashMap<String, crate::store::VRecord>>,
187
+ kept: Mutex<Option<Kept>>,
188
+ }
189
+
190
+ struct Kept {
191
+ identity: (u64, u64),
192
+ connection: Connection,
193
+ }
194
+
195
+ fn trust_index() -> &'static Mutex<HashMap<PathBuf, Weak<Trust>>> {
196
+ static INDEX: OnceLock<Mutex<HashMap<PathBuf, Weak<Trust>>>> = OnceLock::new();
197
+ INDEX.get_or_init(Default::default)
198
+ }
199
+
200
+ impl Trust {
201
+ /// The one index for the catalog under `root`, shared by every live handle in the
202
+ /// process. It, and its kept connection, end with the last handle.
203
+ pub(crate) fn of(root: &Path) -> Arc<Trust> {
204
+ let path = Catalog::path(root);
205
+ let mut index = trust_index()
206
+ .lock()
207
+ .unwrap_or_else(|error| error.into_inner());
208
+ if let Some(trust) = index.get(&path).and_then(Weak::upgrade) {
209
+ return trust;
210
+ }
211
+ index.retain(|_, trust| trust.strong_count() > 0);
212
+ let trust = Arc::new(Trust {
213
+ path: path.clone(),
214
+ rows: RwLock::default(),
215
+ kept: Mutex::default(),
216
+ });
217
+ index.insert(path, Arc::downgrade(&trust));
218
+ trust
219
+ }
220
+
221
+ fn live(path: &Path) -> Option<Arc<Trust>> {
222
+ trust_index()
223
+ .lock()
224
+ .unwrap_or_else(|error| error.into_inner())
225
+ .get(path)
226
+ .and_then(Weak::upgrade)
227
+ }
228
+
229
+ pub(crate) fn get(&self, sha256: &str) -> Option<crate::store::VRecord> {
230
+ if let Some(row) = self
231
+ .rows
232
+ .read()
233
+ .unwrap_or_else(|error| error.into_inner())
234
+ .get(sha256)
235
+ {
236
+ return Some(row.clone());
237
+ }
238
+ self.miss(sha256)
239
+ }
240
+
241
+ /// Validate the catalog on the kept connection: the handle's one open, which also loads
242
+ /// the index. A live connection to the same catalog file is already validated.
243
+ pub(crate) fn validate(&self) -> Result<()> {
244
+ let mut kept = self.kept.lock().unwrap_or_else(|error| error.into_inner());
245
+ self.load(&mut kept).map(|_| ())
246
+ }
247
+
248
+ fn miss(&self, sha256: &str) -> Option<crate::store::VRecord> {
249
+ let mut kept = self.kept.lock().unwrap_or_else(|error| error.into_inner());
250
+ if self.load(&mut kept).ok()? {
251
+ return self
252
+ .rows
253
+ .read()
254
+ .unwrap_or_else(|error| error.into_inner())
255
+ .get(sha256)
256
+ .cloned();
257
+ }
258
+ let open = kept.as_ref()?;
259
+ let row = verification_on(&open.connection, sha256).ok().flatten()?;
260
+ self.remember(&row);
261
+ Some(row)
262
+ }
263
+
264
+ /// Keep a validated connection to the current catalog file, loading every row when it is
265
+ /// newly opened. Returns whether it was (re)opened.
266
+ fn load(&self, kept: &mut Option<Kept>) -> Result<bool> {
267
+ let identity = fs::symlink_metadata(&self.path)
268
+ .map(|metadata| (metadata.dev(), metadata.ino()))
269
+ .ok();
270
+ if kept
271
+ .as_ref()
272
+ .is_some_and(|open| Some(open.identity) == identity)
273
+ {
274
+ return Ok(false);
275
+ }
276
+ let connection = validated(&self.path)?;
277
+ let Some(identity) = identity else {
278
+ return refuse(
279
+ Code::DURABILITY_UNPROVEN,
280
+ format!("{} changed while it was opened", self.path.display()),
281
+ );
282
+ };
283
+ let rows = verifications_on(&connection)?;
284
+ *kept = Some(Kept {
285
+ identity,
286
+ connection,
287
+ });
288
+ self.rows
289
+ .write()
290
+ .unwrap_or_else(|error| error.into_inner())
291
+ .extend(rows.into_iter().map(|row| (row.sha256.clone(), row)));
292
+ Ok(true)
293
+ }
294
+
295
+ fn remember(&self, row: &crate::store::VRecord) {
296
+ self.rows
297
+ .write()
298
+ .unwrap_or_else(|error| error.into_inner())
299
+ .insert(row.sha256.clone(), row.clone());
300
+ }
301
+
302
+ fn forget(&self, sha256: &str) {
303
+ self.rows
304
+ .write()
305
+ .unwrap_or_else(|error| error.into_inner())
306
+ .remove(sha256);
307
+ }
308
+ }
309
+
117
310
  #[derive(Debug, Clone)]
118
311
  pub struct Catalog {
119
312
  path: PathBuf,
@@ -201,40 +394,12 @@ impl Catalog {
201
394
 
202
395
  pub fn open(root: &Path) -> Result<Self> {
203
396
  let path = Self::path(root);
204
- if !path.is_file() {
205
- return refuse(
206
- Code::DURABILITY_UNPROVEN,
207
- format!(
208
- "{} is absent; store is recovery-only until `tfs store rebuild`",
209
- path.display()
210
- ),
211
- );
212
- }
213
- let catalog = Self { path };
214
- let connection = catalog.connection()?;
215
- let version: u64 = connection
216
- .query_row("PRAGMA user_version", [], |row| row.get(0))
217
- .map_err(|error| sql("read catalog version", error))?;
218
- if version != SCHEMA_VERSION {
219
- return refuse(
220
- Code::UNKNOWN_FORMAT,
221
- format!("tensorfs.sqlite user_version {version} != {SCHEMA_VERSION}"),
222
- );
223
- }
224
- verify_schema(&connection)?;
225
- Ok(catalog)
397
+ validated(&path)?;
398
+ Ok(Self { path })
226
399
  }
227
400
 
228
401
  fn connection(&self) -> Result<Connection> {
229
- let connection =
230
- Connection::open(&self.path).map_err(|error| sql("open catalog", error))?;
231
- connection
232
- .busy_timeout(BUSY_TIMEOUT)
233
- .map_err(|error| sql("set catalog busy timeout", error))?;
234
- connection
235
- .execute_batch("PRAGMA foreign_keys=ON; PRAGMA synchronous=FULL;")
236
- .map_err(|error| sql("configure catalog", error))?;
237
- Ok(connection)
402
+ connect(&self.path)
238
403
  }
239
404
 
240
405
  fn initialize_schema(&self) -> Result<()> {
@@ -785,6 +950,9 @@ impl Catalog {
785
950
  transaction
786
951
  .commit()
787
952
  .map_err(|error| sql("commit blob admission", error))?;
953
+ if let (Some(row), Some(trust)) = (&verified, Trust::live(&self.path)) {
954
+ trust.remember(row);
955
+ }
788
956
  Ok(verified.is_some())
789
957
  }
790
958
 
@@ -881,49 +1049,17 @@ impl Catalog {
881
1049
  }
882
1050
 
883
1051
  pub(crate) fn write_verification(&self, row: &crate::store::VRecord) -> Result<()> {
884
- write_verification_on(&self.connection()?, row)
885
- }
886
-
887
- pub(crate) fn verification(&self, sha256: &str) -> Result<Option<crate::store::VRecord>> {
888
- use rusqlite::OptionalExtension;
889
- let row: Option<(u64, String, String, u64, u64)> = self
890
- .connection()?
891
- .query_row(
892
- "SELECT length,dev,ino,mtime_s,mtime_ns
893
- FROM tensorfs_verified_blobs WHERE sha256=?1",
894
- [sha256],
895
- |row| {
896
- Ok((
897
- row.get(0)?,
898
- row.get(1)?,
899
- row.get(2)?,
900
- row.get(3)?,
901
- row.get(4)?,
902
- ))
903
- },
904
- )
905
- .optional()
906
- .map_err(|error| sql("read blob verification", error))?;
907
- row.map(|(length, dev, ino, mtime_s, mtime_ns)| {
908
- Ok(crate::store::VRecord {
909
- sha256: sha256.to_string(),
910
- length,
911
- dev: dev.parse().map_err(|_| Refusal {
912
- code: Code::IO_FAILED,
913
- detail: "invalid verification dev".into(),
914
- })?,
915
- ino: ino.parse().map_err(|_| Refusal {
916
- code: Code::IO_FAILED,
917
- detail: "invalid verification ino".into(),
918
- })?,
919
- mtime_s,
920
- mtime_ns,
921
- })
922
- })
923
- .transpose()
1052
+ write_verification_on(&self.connection()?, row)?;
1053
+ if let Some(trust) = Trust::live(&self.path) {
1054
+ trust.remember(row);
1055
+ }
1056
+ Ok(())
924
1057
  }
925
1058
 
926
1059
  pub(crate) fn drop_verification(&self, sha256: &str) {
1060
+ if let Some(trust) = Trust::live(&self.path) {
1061
+ trust.forget(sha256);
1062
+ }
927
1063
  if let Ok(connection) = self.connection() {
928
1064
  let _ = connection.execute(
929
1065
  "DELETE FROM tensorfs_verified_blobs WHERE sha256=?1",
@@ -953,6 +1089,9 @@ impl Catalog {
953
1089
  [&sha256],
954
1090
  )
955
1091
  .map_err(|error| sql("prune verification row", error))?;
1092
+ if let Some(trust) = Trust::live(&self.path) {
1093
+ trust.forget(&sha256);
1094
+ }
956
1095
  pruned += 1;
957
1096
  }
958
1097
  }
@@ -1001,6 +1140,61 @@ fn hold_on(connection: &Connection, operation: &str, key: &str, length: u64) ->
1001
1140
  }
1002
1141
  }
1003
1142
 
1143
+ type VerificationRow = (String, u64, String, String, u64, u64);
1144
+
1145
+ fn verification_row(row: &rusqlite::Row<'_>) -> rusqlite::Result<VerificationRow> {
1146
+ Ok((
1147
+ row.get(0)?,
1148
+ row.get(1)?,
1149
+ row.get(2)?,
1150
+ row.get(3)?,
1151
+ row.get(4)?,
1152
+ row.get(5)?,
1153
+ ))
1154
+ }
1155
+
1156
+ fn vrecord(
1157
+ (sha256, length, dev, ino, mtime_s, mtime_ns): VerificationRow,
1158
+ ) -> Result<crate::store::VRecord> {
1159
+ let invalid = |what: &str| Refusal {
1160
+ code: Code::IO_FAILED,
1161
+ detail: format!("invalid verification {what}"),
1162
+ };
1163
+ Ok(crate::store::VRecord {
1164
+ sha256,
1165
+ length,
1166
+ dev: dev.parse().map_err(|_| invalid("dev"))?,
1167
+ ino: ino.parse().map_err(|_| invalid("ino"))?,
1168
+ mtime_s,
1169
+ mtime_ns,
1170
+ })
1171
+ }
1172
+
1173
+ fn verification_on(connection: &Connection, sha256: &str) -> Result<Option<crate::store::VRecord>> {
1174
+ use rusqlite::OptionalExtension;
1175
+ connection
1176
+ .prepare_cached(
1177
+ "SELECT sha256,length,dev,ino,mtime_s,mtime_ns
1178
+ FROM tensorfs_verified_blobs WHERE sha256=?1",
1179
+ )
1180
+ .and_then(|mut statement| statement.query_row([sha256], verification_row).optional())
1181
+ .map_err(|error| sql("read blob verification", error))?
1182
+ .map(vrecord)
1183
+ .transpose()
1184
+ }
1185
+
1186
+ fn verifications_on(connection: &Connection) -> Result<Vec<crate::store::VRecord>> {
1187
+ let mut statement = connection
1188
+ .prepare("SELECT sha256,length,dev,ino,mtime_s,mtime_ns FROM tensorfs_verified_blobs")
1189
+ .map_err(|error| sql("prepare verification index", error))?;
1190
+ let rows = statement
1191
+ .query_map([], verification_row)
1192
+ .map_err(|error| sql("read verification index", error))?
1193
+ .collect::<std::result::Result<Vec<_>, _>>()
1194
+ .map_err(|error| sql("collect verification index", error))?;
1195
+ rows.into_iter().map(vrecord).collect()
1196
+ }
1197
+
1004
1198
  fn write_verification_on(connection: &Connection, row: &crate::store::VRecord) -> Result<()> {
1005
1199
  connection
1006
1200
  .execute(
@@ -222,10 +222,10 @@ fn pressure_keeps_cached_inputs_of_a_paused_derive_until_explicit_abandon() {
222
222
  let recorded = store
223
223
  .apply_cached_repository(
224
224
  None,
225
- &Mutation::PutCheckpoint {
225
+ &[Mutation::PutCheckpoint {
226
226
  repo: repo.clone(),
227
227
  manifest: receipt.manifest.clone(),
228
- },
228
+ }],
229
229
  &Default::default(),
230
230
  )
231
231
  .unwrap()
@@ -94,6 +94,7 @@ codes![
94
94
  OBJECT_CORRUPT,
95
95
  RANGE_BOUNDS,
96
96
  NOT_REGULAR_FILE,
97
+ PERMISSION_DENIED,
97
98
  IO_FAILED,
98
99
  // ingest
99
100
  PICKLE_REFUSED,
@@ -164,6 +164,7 @@ impl FetchPlan {
164
164
  sorted.sort_by(|left, right| left.sha256.cmp(&right.sha256));
165
165
  }
166
166
  }
167
+ crate::stats::presence_pass();
167
168
  let mut held = Vec::new();
168
169
  let mut wanted = Vec::new();
169
170
  let mut why = Vec::new();
@@ -226,6 +227,7 @@ impl FetchPlan {
226
227
  store: &Store,
227
228
  walk: fn(&Store, &crate::manifest::Manifest) -> Result<crate::checkpoint::Walk>,
228
229
  ) -> Result<()> {
230
+ crate::stats::presence_pass();
229
231
  if let Some(manifest_ref) = &self.manifest {
230
232
  let manifest = store.read_manifest(manifest_ref)?;
231
233
  let reached = walk(store, &manifest)?;
@@ -48,6 +48,7 @@ pub mod sha256;
48
48
  pub mod source_artifact;
49
49
  pub mod spec;
50
50
  pub mod staging;
51
+ pub mod stats;
51
52
  pub mod storage;
52
53
  pub mod store;
53
54
  pub mod transport;
@@ -59,7 +59,7 @@ pub struct Meta {
59
59
 
60
60
  impl Meta {
61
61
  pub fn open(store: &Store) -> Result<Self> {
62
- crate::catalog::Catalog::open(store.root())?;
62
+ store.trust().validate()?;
63
63
  let lease_dir = store.root().join("tmp/leases");
64
64
  fs::create_dir_all(&lease_dir).map_err(|error| io("mkdir lease markers", error))?;
65
65
  let writer_dir = store.root().join("tmp/writers");
@@ -242,6 +242,7 @@ pub fn acquire_manifest(
242
242
  meta: &Meta,
243
243
  snap: &Manifest,
244
244
  ) -> Result<(ReadLease, Receipts)> {
245
+ crate::stats::presence_pass();
245
246
  let walk = checkpoint::walk(store, snap)?;
246
247
  let objects: Vec<ObjectRef> = walk.distinct().into_iter().cloned().collect();
247
248
  let hex = snap.manifest_id();
@@ -261,6 +262,7 @@ pub fn acquire_cozytensors(
261
262
  meta: &Meta,
262
263
  snap: &Manifest,
263
264
  ) -> Result<(ReadLease, Receipts)> {
265
+ crate::stats::presence_pass();
264
266
  let walk = checkpoint::walk_cozytensors(store, snap)?;
265
267
  let objects: Vec<ObjectRef> = walk.distinct().into_iter().cloned().collect();
266
268
  let hex = snap.manifest_id();
@@ -635,7 +635,8 @@ pub fn run(store: &Store, drop: &[RepositoryName], options: RunOptions) -> Resul
635
635
  sha256: row.sha256.clone(),
636
636
  length: row.length,
637
637
  };
638
- match cache.backfill_store(store, kind, &object) {
638
+ // Demotion drops the local copy: prove the cached one first.
639
+ match cache.repair_store(store, kind, &object) {
639
640
  Ok(CacheWrite::Stored) => {
640
641
  report.demoted_objects += 1;
641
642
  report.demoted_bytes = report.demoted_bytes.saturating_add(row.length);