Skip to main content

diskann_disk/utils/aligned_file_reader/
aligned_file_reader_factory.rs

1/*
2 * Copyright (c) Microsoft Corporation.
3 * Licensed under the MIT license.
4 */
5
6use diskann::ANNResult;
7
8#[cfg(all(not(miri), target_os = "linux"))]
9use super::LinuxAlignedFileReader;
10#[cfg(miri)]
11use super::StorageProviderAlignedFileReader;
12#[cfg(all(not(miri), target_os = "windows"))]
13use super::WindowsAlignedFileReader;
14use crate::utils::aligned_file_reader::traits::AlignedReaderFactory;
15
16pub struct AlignedFileReaderFactory {
17    pub file_path: String,
18}
19
20impl AlignedReaderFactory for AlignedFileReaderFactory {
21    /*
22        Fall back to the StorageProviderAlignedFileReader when running in miri. Otherwise, miri fails with this error:
23       --> C:\Users\<user>\.cargo\registry\src\msdata.pkgs.visualstudio.com-32ec7033fece98f6\io-uring-0.6.3\src\sys\mod.rs:97:15
24        |
25    97  |     to_result(syscall(SYSCALL_SETUP, entries as c_long, p as c_long) as _)
26        |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't execute syscall with ID 425
27        |
28        = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
29        = note: BACKTRACE on thread `algorithm::sear`:
30        = note: inside `io_uring::sys::io_uring_setup` at C:\Users\<user>\.cargo\registry\src\msdata.pkgs.visualstudio.com-32ec7033fece98f6\io-uring-0.6.3\src\sys\mod.rs:97:15: 97:69
31        = note: inside `io_uring::IoUring::with_params` at C:\Users\<user>\.cargo\registry\src\msdata.pkgs.visualstudio.com-32ec7033fece98f6\io-uring-0.6.3\src\lib.rs:152:57: 152:93
32        = note: inside `io_uring::Builder::build` at C:\Users\<user>\.cargo\registry\src\msdata.pkgs.visualstudio.com-32ec7033fece98f6\io-uring-0.6.3\src\lib.rs:412:20: 412:62
33        = note: inside `io_uring::IoUring::new` at C:\Users\<user>\.cargo\registry\src\msdata.pkgs.visualstudio.com-32ec7033fece98f6\io-uring-0.6.3\src\lib.rs:82:9: 82:39
34    note: inside `<model::aligned_file_reader::linux_aligned_file_reader::LinuxAlignedFileReader as model::aligned_file_reader::aligned_file_reader::AlignedFileReader>::read`
35       --> diskann\src\model\aligned_file_reader\linux_aligned_file_reader.rs:221:24
36        |
37    221 |         let mut ring = IoUring::new(MAX_IO_CONCURRENCY as u32)?;
38         */
39    #[cfg(miri)]
40    type AlignedReaderType = StorageProviderAlignedFileReader;
41
42    #[cfg(all(not(miri), target_os = "linux"))]
43    type AlignedReaderType = LinuxAlignedFileReader;
44
45    #[cfg(all(not(miri), target_os = "windows"))]
46    type AlignedReaderType = WindowsAlignedFileReader;
47
48    fn build(&self) -> ANNResult<Self::AlignedReaderType> {
49        #[cfg(miri)]
50        return StorageProviderAlignedFileReader::new(
51            &crate::storage::FileStorageProvider,
52            self.file_path.as_str(),
53        );
54
55        #[cfg(all(not(miri), target_os = "windows"))]
56        return WindowsAlignedFileReader::new(self.file_path.as_str());
57
58        #[cfg(all(not(miri), target_os = "linux"))]
59        return LinuxAlignedFileReader::new(self.file_path.as_str());
60    }
61}
62
63impl AlignedFileReaderFactory {
64    pub fn new(file_path: String) -> Self {
65        Self { file_path }
66    }
67}