hawdb_core/error/
wal_record.rs1use std::fmt::{Display, Formatter};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum WalRecordLimit {
11 RecordBytes,
13 BatchOperations,
15}
16
17impl WalRecordLimit {
18 pub const fn as_str(self) -> &'static str {
19 match self {
20 Self::RecordBytes => "record_bytes",
21 Self::BatchOperations => "batch_operations",
22 }
23 }
24
25 pub const fn config_option(self) -> &'static str {
27 match self {
28 Self::RecordBytes => "DatabaseConfig.max_wal_record_bytes",
29 Self::BatchOperations => "DatabaseConfig.max_wal_batch_operations",
30 }
31 }
32}
33
34#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct WalRecordLimitError {
45 pub limit: WalRecordLimit,
46 pub requested: u64,
48 pub maximum: u64,
50}
51
52impl Display for WalRecordLimitError {
53 fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
54 match self.limit {
55 WalRecordLimit::RecordBytes => write!(
56 formatter,
57 "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 {}",
58 self.requested,
59 self.maximum,
60 self.limit.config_option()
61 ),
62 WalRecordLimit::BatchOperations => write!(
63 formatter,
64 "WAL batch operation limit exceeded before append: the transaction has {} operations, max_wal_batch_operations={}; nothing was written, split the transaction or raise {}",
65 self.requested,
66 self.maximum,
67 self.limit.config_option()
68 ),
69 }
70 }
71}
72
73impl std::error::Error for WalRecordLimitError {}