Skip to main content

diskann_disk/search/provider/aligned_file_reader/traits/
aligned_file_reader.rs

1/*
2 * Copyright (c) Microsoft Corporation.
3 * Licensed under the MIT license.
4 */
5
6use diskann::ANNResult;
7
8use crate::search::provider::aligned_file_reader::{aligned_read::Alignment, AlignedRead};
9
10pub trait AlignedFileReader: Send + Sync {
11    /// Alignment requirement applied to every `AlignedRead<u8, Self::Alignment>`
12    /// passed to [`Self::read`]. All three constraints — buffer pointer,
13    /// buffer length, and disk offset — are checked against this value at
14    /// `AlignedRead::new` time.
15    ///
16    /// Direct-I/O readers (O_DIRECT, `FILE_FLAG_NO_BUFFERING`) set this to the
17    /// device sector size (typically 512 bytes); buffered readers use `A1`.
18    /// The caller is responsible for generating offsets and buffers that
19    /// satisfy this alignment — `DiskSectorGraph`, for example, requires its
20    /// `block_size` to be a multiple of `Self::Alignment::VALUE`.
21    type Alignment: Alignment;
22
23    /// Read the data from the file by sending concurrent io requests in batches.
24    fn read(&mut self, read_requests: &mut [AlignedRead<u8, Self::Alignment>]) -> ANNResult<()>;
25}