Repository: meilisearch/meilisearch
File: crates/milli/src/update/new/channel.rs (Rust)

Code before:
    /// It will never be able to store more than that as the
    /// buffer cannot split data into two parts.
    max_grant: usize,
    /// The total number of attempts to send messages
    /// over the bbqueue channel.
    sent_messages_attempts: Arc<AtomicUsize>,
    /// The number of times an attempt to send a
    /// messages failed and we had to pause for a bit.
    blocking_sent_messages_attempts: Arc<AtomicUsize>,
}

pub struct WriterBbqueueReceiver<'a> {
    /// Used to wake up when new entries are available either in
    /// any BBQueue buffer or directly sent throught this channel
    /// (still written to disk).
    receiver: flume::Receiver<ReceiverAction>,
    /// Indicates the consumer to observe. This cycling range
    /// ensures fair distribution of work among consumers.
    look_at_consumer: Cycle<Range<usize>>,
    /// The BBQueue frames to read when waking-up.
    consumers: Vec<bbqueue::framed::FrameConsumer<'a>>,
    /// The total number of attempts to send messages
    /// over the bbqueue channel.
    sent_messages_attempts: Arc<AtomicUsize>,
    /// The number of times an attempt to send a
    /// messages failed and we had to pause for a bit.
    blocking_sent_messages_attempts: Arc<AtomicUsize>,
}

/// The action to perform on the receiver/writer side.
#[derive(Debug)]
pub enum ReceiverAction {
    /// Wake up, you have frames to read for the BBQueue buffers.
    WakeUp,
    LargeEntry(LargeEntry),
    LargeVectors(LargeVectors),
}

/// An entry that cannot fit in the BBQueue buffers has been
/// written to disk, memory-mapped and must be written in the
/// database.
#[derive(Debug)]
pub struct LargeEntry {
    /// The database where the entry must be written.
    pub database: Database,
    /// The key of the entry that must be written in the database.
    pub key: Box<[u8]>,
    /// The large value that must be written.
    ///
    /// Note: We can probably use a `File` here and
    /// use `Database::put_reserved` instead of memory-mapping.

Review comment (bug):
```suggestion
    /// message failed and we had to pause for a bit.
```

Code after:
    /// It will never be able to store more than that as the
    /// buffer cannot split data into two parts.
    max_grant: usize,
    /// The total number of attempts to send messages
    /// over the bbqueue channel.
    sent_messages_attempts: Arc<AtomicUsize>,
    /// The number of times an attempt to send a
    /// messages failed and we had to pause for a bit.
    blocking_sent_messages_attempts: Arc<AtomicUsize>,
}

pub struct WriterBbqueueReceiver<'a> {
    /// Used to wake up when new entries are available either in
    /// any BBQueue buffer or directly sent throught this channel
    /// (still written to disk).
    receiver: flume::Receiver<ReceiverAction>,
    /// Indicates the consumer to observe. This cycling range
    /// ensures fair distribution of work among consumers.
    look_at_consumer: Cycle<Range<usize>>,
    /// The BBQueue frames to read when waking-up.
    consumers: Vec<bbqueue::framed::FrameConsumer<'a>>,
    /// The total number of attempts to send messages
    /// over the bbqueue channel.
    sent_messages_attempts: Arc<AtomicUsize>,
    /// The number of times an attempt to send a
    /// message failed and we had to pause for a bit.
    blocking_sent_messages_attempts: Arc<AtomicUsize>,
}

/// The action to perform on the receiver/writer side.
#[derive(Debug)]
pub enum ReceiverAction {
    /// Wake up, you have frames to read for the BBQueue buffers.
    WakeUp,
    LargeEntry(LargeEntry),
    LargeVectors(LargeVectors),
}

/// An entry that cannot fit in the BBQueue buffers has been
/// written to disk, memory-mapped and must be written in the
/// database.
#[derive(Debug)]
pub struct LargeEntry {
    /// The database where the entry must be written.
    pub database: Database,
    /// The key of the entry that must be written in the database.
    pub key: Box<[u8]>,
    /// The large value that must be written.
    ///
    /// Note: We can probably use a `File` here and
    /// use `Database::put_reserved` instead of memory-mapping.