risingwave_meta/hummock/
error.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use risingwave_hummock_sdk::{HummockContextId, HummockSstableObjectId};
16use risingwave_object_store::object::ObjectError;
17use risingwave_rpc_client::error::ToTonicStatus;
18use sea_orm::DbErr;
19use thiserror::Error;
20
21use crate::model::MetadataModelError;
22
23pub type Result<T> = std::result::Result<T, Error>;
24
25#[derive(Error, Debug)]
26pub enum Error {
27    #[error("invalid hummock context {0}")]
28    InvalidContext(HummockContextId),
29    #[error("failed to access meta store")]
30    MetaStore(
31        #[source]
32        #[backtrace]
33        anyhow::Error,
34    ),
35    #[error(transparent)]
36    ObjectStore(
37        #[from]
38        #[backtrace]
39        ObjectError,
40    ),
41    #[error("compactor {0} is disconnected")]
42    CompactorUnreachable(HummockContextId),
43    #[error("compaction group error: {0}")]
44    CompactionGroup(String),
45    #[error("SST {0} is invalid")]
46    InvalidSst(HummockSstableObjectId),
47    #[error("time travel")]
48    TimeTravel(
49        #[source]
50        #[backtrace]
51        anyhow::Error,
52    ),
53    #[error(transparent)]
54    Internal(
55        #[from]
56        #[backtrace]
57        anyhow::Error,
58    ),
59}
60
61impl Error {
62    pub fn retryable(&self) -> bool {
63        matches!(self, Error::MetaStore(_))
64    }
65}
66
67impl From<MetadataModelError> for Error {
68    fn from(err: MetadataModelError) -> Self {
69        anyhow::anyhow!(err).into()
70    }
71}
72
73impl From<sea_orm::DbErr> for Error {
74    fn from(value: DbErr) -> Self {
75        MetadataModelError::from(value).into()
76    }
77}
78
79impl From<Error> for tonic::Status {
80    fn from(err: Error) -> Self {
81        err.to_status(tonic::Code::Internal, "hummock")
82    }
83}