forked from qdrant/qdrant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attempt to replace sled for storing vectors
- Loading branch information
Showing
11 changed files
with
140 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod vector_storage; | ||
pub mod simple_vector_storage; | ||
pub mod memmap_vector_storage; | ||
mod persisted_vector_storage; |
80 changes: 80 additions & 0 deletions
80
lib/segment/src/vector_storage/persisted_vector_storage.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::fs::OpenOptions; | ||
use std::path::{Path, PathBuf}; | ||
use memmap::{Mmap, MmapMut}; | ||
|
||
use crate::entry::entry_point::OperationResult; | ||
use std::intrinsics::size_of; | ||
use std::ops; | ||
|
||
|
||
const MAX_SEGMENT_SIZE: usize = 32 * 1024 * 1024; // 32 mb | ||
const SEGMENT_MAGIC: &'static [u8; 4] = b"vect"; | ||
|
||
const SEGMENT_HEADER_SIZE: usize = size_of::<usize> + SEGMENT_MAGIC.len(); | ||
|
||
|
||
|
||
/// Storage for fixed-length records | ||
/// | ||
struct Segment { | ||
mmap: MmapMut, | ||
path: PathBuf, | ||
|
||
record_size: usize, | ||
/// Number of records which could be stored in total in this segment | ||
capacity: usize, | ||
/// Number of currently stored vectors | ||
occupancy: usize, | ||
unflashed: uszie | ||
} | ||
|
||
impl Segment { | ||
pub fn new(path: &Path, record_size: usize) -> OperationResult<Self> { | ||
let max_records = MAX_SEGMENT_SIZE / record_size; | ||
let storage_size = max_records * record_size; | ||
|
||
let file = OpenOptions::new().read(true).write(true).create(true).open(&path)?; | ||
file.allocate(storage_size as u64)?; | ||
|
||
let mmap = unsafe { MmapMut::map_mut(&file)? }; | ||
|
||
Ok(Segment { | ||
mmap, | ||
path: path.to_owned(), | ||
record_size, | ||
capacity: max_records, | ||
occupancy: 0, | ||
unflashed: 0 | ||
}) | ||
} | ||
|
||
pub fn append<T>(&mut self, record: &T) -> OperationResult<usize> where T: ops::Deref<Target=[u8]> { | ||
self.unflashed += 1; | ||
unimplemented!() | ||
} | ||
|
||
pub fn update<T>(&mut self, idx: usize, record: &T) -> OperationResult<()> where T: ops::Deref<Target=[u8]> { | ||
self.unflashed += 1; | ||
unimplemented!() | ||
} | ||
|
||
/// Flushes recently written entries to durable storage. | ||
pub fn flush(&mut self) -> OperationResult<()> { | ||
if self.unflashed == 0 { | ||
Ok(()) | ||
} else { | ||
self.mmap.flush()?; | ||
self.unflashed = 0; | ||
} | ||
} | ||
|
||
pub fn read<T>(&self, idx: usize) -> &[u8] { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
struct PersistedVectorStorage { | ||
storage_path: PathBuf, | ||
vector_size: usize, | ||
segments: Vec<Segment>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters