risingwave_storage/hummock/
error.rs1use risingwave_common::catalog::TableId;
16use risingwave_object_store::object::ObjectError;
17use thiserror::Error;
18use thiserror_ext::AsReport;
19use tokio::sync::oneshot::error::RecvError;
20
21#[derive(Error, thiserror_ext::ReportDebug, thiserror_ext::Arc)]
23#[thiserror_ext(newtype(name = HummockError, backtrace))]
24pub enum HummockErrorInner {
25 #[error("Magic number mismatch: expected {expected}, found: {found}")]
26 MagicMismatch { expected: u32, found: u32 },
27 #[error("Invalid format version: {0}")]
28 InvalidFormatVersion(u32),
29 #[error("Checksum mismatch: expected {expected}, found: {found}")]
30 ChecksumMismatch { expected: u64, found: u64 },
31 #[error("Invalid block")]
32 InvalidBlock,
33 #[error("Encode error: {0}")]
34 EncodeError(String),
35 #[error("Decode error: {0}")]
36 DecodeError(String),
37 #[error("ObjectStore failed with IO error: {0}")]
38 ObjectIoError(
39 #[from]
40 #[backtrace]
41 ObjectError,
42 ),
43 #[error("Meta error: {0}")]
44 MetaError(String),
45 #[error("SharedBuffer error: {0}")]
46 SharedBufferError(String),
47 #[error("Wait epoch error: {0}")]
48 WaitEpoch(String),
49 #[error("Next epoch error: {0}")]
50 NextEpoch(String),
51 #[error("Barrier read is unavailable for now. Likely the cluster is recovering")]
52 ReadCurrentEpoch,
53 #[error("Expired Epoch: watermark {safe_epoch}, epoch {epoch}")]
54 ExpiredEpoch {
55 table_id: u32,
56 safe_epoch: u64,
57 epoch: u64,
58 },
59 #[error("CompactionExecutor error: {0}")]
60 CompactionExecutor(String),
61 #[error("FileCache error: {0}")]
62 FileCache(String),
63 #[error("SstObjectIdTracker error: {0}")]
64 SstObjectIdTrackerError(String),
65 #[error("CompactionGroup error: {0}")]
66 CompactionGroupError(String),
67 #[error("SstableUpload error: {0}")]
68 SstableUploadError(String),
69 #[error("Read backup error: {0}")]
70 ReadBackupError(String),
71 #[error("Foyer error: {0}")]
72 FoyerError(anyhow::Error),
73 #[error("Other error: {0}")]
74 Other(String),
75}
76
77impl HummockError {
78 pub fn invalid_format_version(v: u32) -> HummockError {
79 HummockErrorInner::InvalidFormatVersion(v).into()
80 }
81
82 pub fn invalid_block() -> HummockError {
83 HummockErrorInner::InvalidBlock.into()
84 }
85
86 pub fn encode_error(error: impl ToString) -> HummockError {
87 HummockErrorInner::EncodeError(error.to_string()).into()
88 }
89
90 pub fn decode_error(error: impl ToString) -> HummockError {
91 HummockErrorInner::DecodeError(error.to_string()).into()
92 }
93
94 pub fn magic_mismatch(expected: u32, found: u32) -> HummockError {
95 HummockErrorInner::MagicMismatch { expected, found }.into()
96 }
97
98 pub fn checksum_mismatch(expected: u64, found: u64) -> HummockError {
99 HummockErrorInner::ChecksumMismatch { expected, found }.into()
100 }
101
102 pub fn meta_error(error: impl ToString) -> HummockError {
103 HummockErrorInner::MetaError(error.to_string()).into()
104 }
105
106 pub fn shared_buffer_error(error: impl ToString) -> HummockError {
107 HummockErrorInner::SharedBufferError(error.to_string()).into()
108 }
109
110 pub fn wait_epoch(error: impl ToString) -> HummockError {
111 HummockErrorInner::WaitEpoch(error.to_string()).into()
112 }
113
114 pub fn next_epoch(error: impl ToString) -> HummockError {
115 HummockErrorInner::NextEpoch(error.to_string()).into()
116 }
117
118 pub fn read_current_epoch() -> HummockError {
119 HummockErrorInner::ReadCurrentEpoch.into()
120 }
121
122 pub fn expired_epoch(table_id: TableId, safe_epoch: u64, epoch: u64) -> HummockError {
123 HummockErrorInner::ExpiredEpoch {
124 table_id: table_id.table_id,
125 safe_epoch,
126 epoch,
127 }
128 .into()
129 }
130
131 pub fn is_expired_epoch(&self) -> bool {
132 matches!(self.inner(), HummockErrorInner::ExpiredEpoch { .. })
133 }
134
135 pub fn is_meta_error(&self) -> bool {
136 matches!(self.inner(), HummockErrorInner::MetaError(..))
137 }
138
139 pub fn is_object_error(&self) -> bool {
140 matches!(self.inner(), HummockErrorInner::ObjectIoError { .. })
141 }
142
143 pub fn compaction_executor(error: impl ToString) -> HummockError {
144 HummockErrorInner::CompactionExecutor(error.to_string()).into()
145 }
146
147 pub fn sst_object_id_tracker_error(error: impl ToString) -> HummockError {
148 HummockErrorInner::SstObjectIdTrackerError(error.to_string()).into()
149 }
150
151 pub fn compaction_group_error(error: impl ToString) -> HummockError {
152 HummockErrorInner::CompactionGroupError(error.to_string()).into()
153 }
154
155 pub fn file_cache(error: impl ToString) -> HummockError {
156 HummockErrorInner::FileCache(error.to_string()).into()
157 }
158
159 pub fn sstable_upload_error(error: impl ToString) -> HummockError {
160 HummockErrorInner::SstableUploadError(error.to_string()).into()
161 }
162
163 pub fn read_backup_error(error: impl ToString) -> HummockError {
164 HummockErrorInner::ReadBackupError(error.to_string()).into()
165 }
166
167 pub fn foyer_error(error: anyhow::Error) -> HummockError {
168 HummockErrorInner::FoyerError(error).into()
169 }
170
171 pub fn other(error: impl ToString) -> HummockError {
172 HummockErrorInner::Other(error.to_string()).into()
173 }
174}
175
176impl From<prost::DecodeError> for HummockError {
177 fn from(error: prost::DecodeError) -> Self {
178 HummockErrorInner::DecodeError(error.to_report_string()).into()
179 }
180}
181
182impl From<RecvError> for HummockError {
183 fn from(error: RecvError) -> Self {
184 ObjectError::from(error).into()
185 }
186}
187
188pub type HummockResult<T> = std::result::Result<T, HummockError>;