use std::fmt::{Display, Formatter};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WalRecordLimit {
RecordBytes,
BatchOperations,
}
impl WalRecordLimit {
pub const fn as_str(self) -> &'static str {
match self {
Self::RecordBytes => "record_bytes",
Self::BatchOperations => "batch_operations",
}
}
pub const fn config_option(self) -> &'static str {
match self {
Self::RecordBytes => "DatabaseConfig.max_wal_record_bytes",
Self::BatchOperations => "DatabaseConfig.max_wal_batch_operations",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WalRecordLimitError {
pub limit: WalRecordLimit,
pub requested: u64,
pub maximum: u64,
}
impl Display for WalRecordLimitError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
match self.limit {
WalRecordLimit::RecordBytes => write!(
formatter,
"WAL record byte limit exceeded before append: the transaction's WAL record is {} bytes, max_wal_record_bytes={}; nothing was written, split the transaction or raise {}",
self.requested,
self.maximum,
self.limit.config_option()
),
WalRecordLimit::BatchOperations => write!(
formatter,
"WAL batch operation limit exceeded before append: the transaction has {} operations, max_wal_batch_operations={}; nothing was written, split the transaction or raise {}",
self.requested,
self.maximum,
self.limit.config_option()
),
}
}
}
impl std::error::Error for WalRecordLimitError {}