Skip to content

Commit

Permalink
chore: fix some style problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachelint committed May 9, 2023
1 parent b056310 commit 60e6e6c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions analytic_engine/src/instance/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Instance {
store_picker.default_store().clone(),
));

let table_snapshot_provider = Arc::new(TableMetaSetImpl {
let table_meta_set_impl = Arc::new(TableMetaSetImpl {
spaces: spaces.clone(),
file_purger: file_purger.clone(),
preflush_write_buffer_size_ratio: ctx.config.preflush_write_buffer_size_ratio,
Expand All @@ -74,7 +74,7 @@ impl Instance {
ctx.config.manifest.clone(),
manifest_storages.wal_manager,
manifest_storages.oss_storage,
table_snapshot_provider,
table_meta_set_impl,
)
.await
.context(OpenManifest)?;
Expand Down
10 changes: 5 additions & 5 deletions analytic_engine/src/manifest/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ use wal::{
},
};

use super::meta_edit::{MetaEdit, Snapshot};
use crate::{
manifest::{
meta_edit::{MetaEditRequest, MetaUpdate, MetaUpdateDecoder, MetaUpdatePayload},
meta_edit::{
MetaEdit, MetaEditRequest, MetaUpdate, MetaUpdateDecoder, MetaUpdatePayload, Snapshot,
},
meta_snapshot::{MetaSnapshot, MetaSnapshotBuilder},
LoadRequest, Manifest, SnapshotRequest,
},
Expand Down Expand Up @@ -178,9 +179,9 @@ impl MetaUpdateLogEntryIterator for MetaUpdateReaderImpl {
}
}

/// Table snapshot provider
/// Table meta set
///
/// Mainly for getting the [TableManifestData] from memory.
/// Get snapshot of or modify table's metadata through it.
pub(crate) trait TableMetaSet: fmt::Debug + Send + Sync {
fn get_table_snapshot(
&self,
Expand Down Expand Up @@ -462,7 +463,6 @@ impl Manifest for ManifestImpl {
let shard_id = shard_info.shard_id;
let location = WalLocation::new(shard_id as u64, table_id.as_u64());
let space_id = meta_update.space_id();
let table_id = meta_update.table_id();

self.maybe_do_snapshot(space_id, table_id, location, false)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion analytic_engine/src/manifest/meta_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use snafu::{Backtrace, OptionExt, ResultExt, Snafu};
use table_engine::table::TableId;
use wal::log_batch::{Payload, PayloadDecoder};

use super::meta_snapshot::MetaSnapshot;
use crate::{
manifest::meta_snapshot::MetaSnapshot,
space::SpaceId,
table::{
data::{MemTableId, TableShardInfo},
Expand Down
63 changes: 32 additions & 31 deletions analytic_engine/src/table_meta_set_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,28 @@ impl fmt::Debug for TableMetaSetImpl {
}

impl TableMetaSetImpl {
fn find_space_and_apply_edit<F>(
&self,
space_id: SpaceId,
apply_edit: F,
) -> crate::manifest::details::Result<()>
where
F: FnOnce(Arc<Space>) -> crate::manifest::details::Result<()>,
{
let spaces = self.spaces.read().unwrap();
let space = spaces
.get_by_id(space_id)
.with_context(|| ApplyUpdateToTableNoCause {
msg: format!("space not found, space_id:{space_id}"),
})?;
apply_edit(space.clone())
}

fn apply_update(
&self,
meta_update: MetaUpdate,
shard_info: TableShardInfo,
) -> crate::manifest::details::Result<()> {
// `FnOnce` can only be pass as the instance but not reference, however `Impl
// FnOnce` can not act as the parameter of the closure... So Box<dyn
// FnOnce> is used here.
let find_space_and_apply_edit = |space_id: SpaceId,
apply_edit: Box<
dyn FnOnce(Arc<Space>) -> crate::manifest::details::Result<()>,
>| {
let spaces = self.spaces.read().unwrap();
let space = spaces
.get_by_id(space_id)
.with_context(|| ApplyUpdateToTableNoCause {
msg: format!("space not found, space_id:{space_id}"),
})?;
apply_edit(space.clone())
};

match meta_update {
MetaUpdate::AddTable(AddTableMeta {
space_id,
Expand All @@ -74,7 +75,7 @@ impl TableMetaSetImpl {
schema,
opts,
}) => {
let add_table = Box::new(move |space: Arc<Space>| {
let add_table = move |space: Arc<Space>| {
let table_data = TableData::new(
space.id,
table_id,
Expand All @@ -95,16 +96,16 @@ impl TableMetaSetImpl {
})?;
space.insert_table(Arc::new(table_data));
Ok(())
});
};

find_space_and_apply_edit(space_id, add_table)
self.find_space_and_apply_edit(space_id, add_table)
}
MetaUpdate::DropTable(DropTableMeta {
space_id,
table_name,
..
}) => {
let drop_table = Box::new(move |space: Arc<Space>| {
let drop_table = move |space: Arc<Space>| {
let table_data = match space.find_table(table_name.as_str()) {
Some(v) => v,
None => return Ok(()),
Expand All @@ -119,9 +120,9 @@ impl TableMetaSetImpl {
space.remove_table(&table_data.name);

Ok(())
});
};

find_space_and_apply_edit(space_id, drop_table)
self.find_space_and_apply_edit(space_id, drop_table)
}
MetaUpdate::VersionEdit(VersionEditMeta {
space_id,
Expand All @@ -131,7 +132,7 @@ impl TableMetaSetImpl {
files_to_delete,
mems_to_remove,
}) => {
let version_edit = Box::new(move |space: Arc<Space>| {
let version_edit = move |space: Arc<Space>| {
let table_data = space.find_table_by_id(table_id).with_context(|| {
ApplyUpdateToTableNoCause {
msg: format!(
Expand All @@ -148,17 +149,17 @@ impl TableMetaSetImpl {
table_data.current_version().apply_edit(edit);

Ok(())
});
};

find_space_and_apply_edit(space_id, version_edit)
self.find_space_and_apply_edit(space_id, version_edit)
}
MetaUpdate::AlterSchema(AlterSchemaMeta {
space_id,
table_id,
schema,
..
}) => {
let alter_schema = Box::new(move |space: Arc<Space>| {
let alter_schema = move |space: Arc<Space>| {
let table_data = space.find_table_by_id(table_id).with_context(|| {
ApplyUpdateToTableNoCause {
msg: format!(
Expand All @@ -169,15 +170,15 @@ impl TableMetaSetImpl {
table_data.set_schema(schema);

Ok(())
});
find_space_and_apply_edit(space_id, alter_schema)
};
self.find_space_and_apply_edit(space_id, alter_schema)
}
MetaUpdate::AlterOptions(AlterOptionsMeta {
space_id,
table_id,
options,
}) => {
let alter_option = Box::new(move |space: Arc<Space>| {
let alter_option = move |space: Arc<Space>| {
let table_data = space.find_table_by_id(table_id).with_context(|| {
ApplyUpdateToTableNoCause {
msg: format!(
Expand All @@ -188,8 +189,8 @@ impl TableMetaSetImpl {
table_data.set_table_options(options);

Ok(())
});
find_space_and_apply_edit(space_id, alter_option)
};
self.find_space_and_apply_edit(space_id, alter_option)
}
}
}
Expand Down

0 comments on commit 60e6e6c

Please sign in to comment.