Skip to content

Commit

Permalink
[mqtt] Ring buffer write succeeds when no space to fit a new insert (A…
Browse files Browse the repository at this point in the history
…zure#4825)

There was an issue when ring buffer calculated free space available to insert a new publication.
  • Loading branch information
dmolokanov authored and ggjjj committed Jul 22, 2021
1 parent 25ff198 commit 87b4225
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 178 deletions.
14 changes: 11 additions & 3 deletions mqtt/mqtt-bridge/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,17 @@ where
if let Some(publication) = forward_publication {
debug!("saving message to store");
return match self.store.push(&publication) {
Ok(_) |
// If we are full we are dropping the message on ground.
Err(PersistError::RingBuffer(RingBufferError::Full)) => Ok(Handled::Fully),
Ok(_) => Ok(Handled::Fully),
Err(
err
@
PersistError::RingBuffer(RingBufferError::InsufficientSpace {
..
}),
) => {
error!(error = %err, "dropping incoming publication");
Ok(Handled::Fully)
}
Err(err) => Err(BridgeError::Store(err)),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub enum RingBufferError {
#[error("Flushing failed. Caused by {0}")]
Flush(std::io::Error),

#[error("Buffer is full and messages must be drained to continue")]
Full,
#[error("Storage has insufficient space to insert data: required: {required}b, but only {free}b available")]
InsufficientSpace { free: u64, required: u64 },

#[error("Unable to create file. Caused by {0}")]
FileCreate(std::io::Error),
Expand Down
Loading

0 comments on commit 87b4225

Please sign in to comment.