Open or create the array store. Loads the manifest if present; mmap's every referenced segment and validates schema_hash.
(
root: PathBuf,
schema: Arc<ArraySchema>,
schema_hash: u64,
)
| 60 | /// Open or create the array store. Loads the manifest if present; |
| 61 | /// mmap's every referenced segment and validates schema_hash. |
| 62 | pub fn open( |
| 63 | root: PathBuf, |
| 64 | schema: Arc<ArraySchema>, |
| 65 | schema_hash: u64, |
| 66 | ) -> Result<Self, ArrayStoreError> { |
| 67 | std::fs::create_dir_all(&root).map_err(|e| ArrayStoreError::Io { |
| 68 | detail: format!("mkdir {root:?}: {e}"), |
| 69 | })?; |
| 70 | let manifest = Manifest::load_or_new(&root, schema_hash)?; |
| 71 | if manifest.schema_hash != schema_hash && !manifest.segments.is_empty() { |
| 72 | return Err(ArrayStoreError::SchemaHashMismatch { |
| 73 | store: manifest.schema_hash, |
| 74 | new: schema_hash, |
| 75 | }); |
| 76 | } |
| 77 | let mut segments = HashMap::with_capacity(manifest.segments.len()); |
| 78 | let mut max_seq: u64 = 0; |
| 79 | for seg in &manifest.segments { |
| 80 | let h = SegmentHandle::open( |
| 81 | &segment_path(&root, &seg.id), |
| 82 | seg.id.clone(), |
| 83 | schema_hash, |
| 84 | None, |
| 85 | )?; |
| 86 | if let Some(seq) = parse_segment_seq(&seg.id) { |
| 87 | max_seq = max_seq.max(seq); |
| 88 | } |
| 89 | segments.insert(seg.id.clone(), h); |
| 90 | } |
| 91 | Ok(Self { |
| 92 | root, |
| 93 | schema, |
| 94 | schema_hash, |
| 95 | manifest, |
| 96 | memtable: Memtable::new(), |
| 97 | segments, |
| 98 | next_segment_seq: max_seq + 1, |
| 99 | kek: None, |
| 100 | }) |
| 101 | } |
| 102 | |
| 103 | /// Install the at-rest encryption key for SEGA segment envelopes. |
| 104 | /// |
nothing calls this directly
no test coverage detected