MCPcopy Create free account
hub / github.com/cosdata/cosdata / get_or_create_version

Method get_or_create_version

src/models/prob_node.rs:47–92  ·  view source on GitHub ↗
(
        this: *mut Self,
        version: VersionNumber,
        synchronization_map: &TSHashTable<SharedLatestNode, ()>,
        cache: &HNSWIndexCache,
        file_id: IndexFileId,
        offset

Source from the content-addressed store, hash-verified

45 #[allow(invalid_reference_casting)]
46 #[allow(clippy::not_unsafe_ptr_arg_deref)]
47 pub fn get_or_create_version(
48 this: *mut Self,
49 version: VersionNumber,
50 synchronization_map: &TSHashTable<SharedLatestNode, ()>,
51 cache: &HNSWIndexCache,
52 file_id: IndexFileId,
53 offset_counter: &HNSWIndexFileOffsetCounter,
54 ) -> Result<(SharedNode, bool), BufIoError> {
55 let self_ = unsafe { &*this };
56 let latest = unsafe { &*self_.latest };
57 let node = latest.try_get_data(cache)?;
58 if node.version.load(Ordering::Relaxed) == *version {
59 return Ok((self_.latest, false));
60 }
61 synchronization_map.lock_key_and_try(this, || {
62 if node.version.load(Ordering::Relaxed) == *version {
63 return Ok((self_.latest, false));
64 }
65
66 let offset = if node.hnsw_level.0 == 0 {
67 offset_counter.next_level_0_offset()
68 } else {
69 offset_counter.next_offset()
70 };
71
72 unsafe {
73 *(&latest.file_index as *const _ as *mut _) = FileIndex { file_id, offset };
74 }
75
76 node.version.store(*version, Ordering::Release);
77
78 let cursor = cache.latest_version_links_bufman.open_cursor()?;
79 cache
80 .latest_version_links_bufman
81 .seek_with_cursor(cursor, self_.file_offset.0 as u64)?;
82 cache
83 .latest_version_links_bufman
84 .update_u32_with_cursor(cursor, offset.0)?;
85 cache
86 .latest_version_links_bufman
87 .update_u32_with_cursor(cursor, *file_id)?;
88 cache.latest_version_links_bufman.close_cursor(cursor)?;
89
90 Ok((self_.latest, true))
91 })
92 }
93}
94
95pub type SharedLatestNode = *mut LatestNode;

Callers

nothing calls this directly

Calls 9

try_get_dataMethod · 0.80
loadMethod · 0.80
lock_key_and_tryMethod · 0.80
next_level_0_offsetMethod · 0.80
next_offsetMethod · 0.80
open_cursorMethod · 0.80
seek_with_cursorMethod · 0.80
close_cursorMethod · 0.80

Tested by

no test coverage detected