qdrant_edge/edge/update_only/
lifecycle.rs1use std::path::{Path, PathBuf};
2
3use crate::common::universal_io::{MmapFile, MmapFs, UniversalRead, UniversalReadFs};
4use parking_lot::RwLock;
5use rayon::prelude::*;
6use crate::segment::common::operation_error::OperationResult;
7use crate::segment::segment::update_only::UpdateOnlySegment;
8use uuid::Uuid;
9
10use crate::edge::read_only::{LocalSegmentEnumerator, SegmentEnumerator};
11use crate::edge::read_view::build_segment_pool;
12use crate::edge::update_only::UpdateOnlyEdgeShard;
13use crate::edge::update_only::holder::UpdateOnlySegmentHolder;
14
15impl UpdateOnlyEdgeShard<MmapFile> {
16 pub fn open_mmap(path: &Path) -> OperationResult<Self> {
20 Self::open(MmapFs, path, LocalSegmentEnumerator::new(path))
21 }
22}
23
24impl<S: UniversalRead + 'static> UpdateOnlyEdgeShard<S> {
25 pub fn open(
36 fs: S::Fs,
37 path: &Path,
38 enumerator: impl SegmentEnumerator + 'static,
39 ) -> OperationResult<Self>
40 where
41 S::Fs: UniversalReadFs<File = S>,
42 {
43 let pool = build_segment_pool(
46 "edge-update",
47 crate::common::defaults::search_thread_count(0),
48 None,
49 )?;
50
51 let segments: Vec<(Uuid, PathBuf)> = enumerator.list_segments()?.into_iter().collect();
52 let opened: Vec<(Uuid, UpdateOnlySegment<S>)> = pool.install(|| {
53 segments
54 .into_par_iter()
55 .map(|(uuid, segment_path)| {
56 let segment = UpdateOnlySegment::<S>::open(&fs, &segment_path, uuid, None)?;
60 Ok((uuid, segment))
61 })
62 .collect::<OperationResult<Vec<_>>>()
63 })?;
64
65 let mut holder = UpdateOnlySegmentHolder::default();
66 for (uuid, segment) in opened {
67 holder.insert(uuid, segment);
68 }
69
70 if holder.is_empty() {
71 todo!("creating the initial appendable segment needs the append-only components");
75 }
76
77 Ok(Self {
78 path: path.to_path_buf(),
79 fs,
80 segments: RwLock::new(holder),
81 pool,
82 })
83 }
84}