chore(index): add BiError to fulfil the requirement of returning two errors (#3291)

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
This commit is contained in:
Zhenchi
2024-02-07 00:03:03 +08:00
committed by GitHub
parent e4cd294ac0
commit dbf62f3273
2 changed files with 24 additions and 3 deletions

View File

@@ -549,6 +549,13 @@ pub enum Error {
source: common_recordbatch::error::Error,
location: Location,
},
#[snafu(display("BiError, first: {first}, second: {second}"))]
BiError {
first: Box<Error>,
second: Box<Error>,
location: Location,
},
}
pub type Result<T, E = Error> = std::result::Result<T, E>;
@@ -650,6 +657,7 @@ impl ErrorExt for Error {
StaleLogEntry { .. } => StatusCode::Unexpected,
FilterRecordBatch { source, .. } => source.status_code(),
Upload { .. } => StatusCode::StorageUnavailable,
BiError { .. } => StatusCode::Internal,
}
}

View File

@@ -32,7 +32,7 @@ use tokio::io::duplex;
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
use crate::error::{
IndexFinishSnafu, OperateAbortedIndexSnafu, PuffinAddBlobSnafu, PuffinFinishSnafu,
BiSnafu, IndexFinishSnafu, OperateAbortedIndexSnafu, PuffinAddBlobSnafu, PuffinFinishSnafu,
PushIndexValueSnafu, Result,
};
use crate::metrics::{
@@ -249,8 +249,21 @@ impl SstIndexCreator {
self.index_creator.finish(&mut index_writer),
puffin_writer.add_blob(blob)
);
index_finish.context(IndexFinishSnafu)?;
puffin_add_blob.context(PuffinAddBlobSnafu)?;
match (
puffin_add_blob.context(PuffinAddBlobSnafu),
index_finish.context(IndexFinishSnafu),
) {
(Err(e1), Err(e2)) => BiSnafu {
first: Box::new(e1),
second: Box::new(e2),
}
.fail()?,
(Ok(_), e @ Err(_)) => e?,
(e @ Err(_), Ok(_)) => e?,
_ => {}
}
let byte_count = puffin_writer.finish().await.context(PuffinFinishSnafu)?;
guard.inc_byte_count(byte_count);