mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-17 21:40:37 +00:00
feat: persist table metadata when creating it
This commit is contained in:
@@ -8,6 +8,7 @@ use common_error::ext::BoxedError;
|
||||
use common_telemetry::logging;
|
||||
use object_store::ObjectStore;
|
||||
use snafu::{OptionExt, ResultExt};
|
||||
use store_api::manifest::{action::ProtocolAction, Manifest};
|
||||
use store_api::storage::{
|
||||
self, ColumnDescriptorBuilder, ColumnFamilyDescriptor, ColumnFamilyDescriptorBuilder, ColumnId,
|
||||
CreateOptions, OpenOptions, Region, RegionDescriptorBuilder, RegionId, RegionMeta,
|
||||
@@ -27,6 +28,7 @@ use crate::error::{
|
||||
self, BuildColumnDescriptorSnafu, BuildColumnFamilyDescriptorSnafu, BuildRegionDescriptorSnafu,
|
||||
BuildRowKeyDescriptorSnafu, MissingTimestampIndexSnafu, Result,
|
||||
};
|
||||
use crate::manifest::action::*;
|
||||
use crate::manifest::TableManifest;
|
||||
use crate::table::MitoTable;
|
||||
|
||||
@@ -317,7 +319,16 @@ impl<S: StorageEngine> MitoEngineInner<S> {
|
||||
let manifest =
|
||||
TableManifest::new(&table_manifest_dir(table_name), self.object_store.clone());
|
||||
|
||||
//TODO(dennis): persist table info to table manifest service.
|
||||
manifest
|
||||
.update(TableMetaActionList::new(vec![
|
||||
TableMetaAction::Protocol(ProtocolAction::new()),
|
||||
TableMetaAction::Change(Box::new(TableChange {
|
||||
table_info: table_info.clone(),
|
||||
})),
|
||||
]))
|
||||
.await
|
||||
.context(error::UpdateTableManifestSnafu { table_name })?;
|
||||
|
||||
logging::info!("Mito engine created table: {:?}.", table_info);
|
||||
|
||||
let table = Arc::new(MitoTable::new(table_info, region, manifest));
|
||||
|
||||
@@ -95,6 +95,17 @@ pub enum Error {
|
||||
region_name: String,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
|
||||
#[snafu(display(
|
||||
"Failed to update table metadata to manifest, table: {}, source: {}",
|
||||
table_name,
|
||||
source,
|
||||
))]
|
||||
UpdateTableManifest {
|
||||
#[snafu(backtrace)]
|
||||
source: storage::error::Error,
|
||||
table_name: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<Error> for table::error::Error {
|
||||
@@ -111,6 +122,7 @@ impl ErrorExt for Error {
|
||||
|
||||
match self {
|
||||
CreateRegion { source, .. } | OpenRegion { source, .. } => source.status_code(),
|
||||
|
||||
BuildRowKeyDescriptor { .. }
|
||||
| BuildColumnDescriptor { .. }
|
||||
| BuildColumnFamilyDescriptor { .. }
|
||||
@@ -118,6 +130,8 @@ impl ErrorExt for Error {
|
||||
| BuildTableInfo { .. }
|
||||
| BuildRegionDescriptor { .. }
|
||||
| MissingTimestampIndex { .. } => StatusCode::InvalidArguments,
|
||||
|
||||
UpdateTableManifest { .. } => StatusCode::StorageUnavailable,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Table manifest service
|
||||
mod action;
|
||||
pub mod action;
|
||||
|
||||
use storage::manifest::ManifestImpl;
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ pub struct TableRemove {
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub enum TableMetaAction {
|
||||
Protocol(ProtocolAction),
|
||||
Change(TableChange),
|
||||
// Boxed TableChange to reduce the total size of enum
|
||||
Change(Box<TableChange>),
|
||||
Remove(TableRemove),
|
||||
}
|
||||
|
||||
@@ -37,6 +38,22 @@ pub struct TableMetaActionList {
|
||||
pub prev_version: ManifestVersion,
|
||||
}
|
||||
|
||||
impl TableMetaActionList {
|
||||
pub fn with_action(action: TableMetaAction) -> Self {
|
||||
Self {
|
||||
actions: vec![action],
|
||||
prev_version: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(actions: Vec<TableMetaAction>) -> Self {
|
||||
Self {
|
||||
actions,
|
||||
prev_version: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MetaAction for TableMetaActionList {
|
||||
type Error = StorageError;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user