about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabui@proton.me>2026-10-13 15:11:33 +0300
committerAlexander_Kabui <alexanderkabui@proton.me>2026-10-14 07:27:03 +0300
commitadde6d8e8d80246c099c4b39e82f34faa0d14d9a (patch)
tree2d17cff1328ab4b5c390bd6c2a0b55f9a417e0ee /src
parent4d298c51d46184f8067c0a1c22c249dcabba0663 (diff)
downloadgenenetwork4-adde6d8e8d80246c099c4b39e82f34faa0d14d9a.tar.gz
* src/indexer/sidecar.rs (shard filename): use a 64-bit digest.
shard_filename truncated the label's SHA-256 to 32 bits, so two labels
sharing a sanitized stem and a 32-bit prefix could merge into one shard
(last writer wins).  Use 16 hex chars and assert length and distinctness.
Diffstat (limited to 'src')
-rw-r--r--src/indexer/sidecar.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/indexer/sidecar.rs b/src/indexer/sidecar.rs
index 394fe50..e3f91b7 100644
--- a/src/indexer/sidecar.rs
+++ b/src/indexer/sidecar.rs
@@ -10,7 +10,7 @@
 //!
 //! Each shard is a JSON map `identity-term -> source-hash` at
 //! `<index>.sidecar.d/<file>`, where the filename is the dataset label
-//! sanitized for the filesystem plus a short digest of the raw label (so
+//! sanitized for the filesystem plus a 64-bit digest of the raw label (so
 //! two labels that sanitize to the same string still get distinct files).
 //!
 //! Why sharding: the per-dataset shard is the unit the incremental diff
@@ -118,11 +118,14 @@ pub fn sanitize_label(label: &str) -> String {
 }
 
 /// The shard filename for a dataset label: the sanitized stem plus a
-/// short digest of the raw label, so distinct labels cannot collide.
+/// 64-bit digest of the raw label, so distinct labels cannot collide.
+/// The digest is truncated to 16 hex chars (64 bits) — long enough that
+/// two labels sharing a sanitized stem cannot silently merge into one
+/// shard file.
 pub fn shard_filename(label: &str) -> String {
     let stem = sanitize_label(label);
     let digest = hex_digest(label.as_bytes());
-    format!("{}-{}.json", stem, &digest[..8])
+    format!("{}-{}.json", stem, &digest[..16])
 }
 
 impl Manifest {
@@ -450,3 +453,23 @@ fn open_new(path: &Path) -> Result<File, String> {
         .open(path)
         .map_err(|e| format!("create {}: {e}", path.display()))
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    /// The shard filename carries a 64-bit (16 hex char) digest of the raw
+    /// label, so two distinct labels that sanitize to the same stem get
+    /// distinct files instead of silently merging.
+    #[test]
+    fn shard_filename_carries_64_bit_digest() {
+        let a = shard_filename("Foo/Publish");
+        let b = shard_filename("Foo_Publish");
+        assert!(a.ends_with(".json") && b.ends_with(".json"));
+        let digest_a = a.trim_end_matches(".json");
+        let digest_a = digest_a.rsplit('-').next().unwrap();
+        assert_eq!(digest_a.len(), 16, "filename = {a}");
+        assert!(digest_a.chars().all(|c| c.is_ascii_hexdigit()));
+        assert_ne!(a, b, "distinct labels must not share a shard file");
+    }
+}