Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove EmbeddedMeta #16847

Merged
merged 15 commits into from
Nov 16, 2024
Merged
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions src/meta/embedded/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ doctest = false
test = true

[features]
io-uring = ["databend-common-meta-sled-store/io-uring", "databend-common-meta-raft-store/io-uring"]
io-uring = ["databend-common-meta-raft-store/io-uring"]

[dependencies]
async-trait = { workspace = true }
databend-common-base = { workspace = true }
databend-common-meta-api = { workspace = true }
databend-common-meta-kvapi = { workspace = true }
databend-common-meta-raft-store = { workspace = true }
databend-common-meta-sled-store = { workspace = true }
databend-common-meta-stoerr = { workspace = true }
databend-common-meta-types = { workspace = true }
databend-common-tracing = { workspace = true }
fastrace = { workspace = true }
log = { workspace = true }
tempfile = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down
53 changes: 0 additions & 53 deletions src/meta/embedded/src/kv_api_impl.rs

This file was deleted.

15 changes: 2 additions & 13 deletions src/meta/embedded/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Meta store backed with a local sled::Tree.
//!
//! `MetaEmbedded` talks the same API defined in `kvapi::KVApi`.
//!
//! `MetaEmbedded` behave exactly the same as a metasrv without distributed logs(raft), since it is driven by
//! a embedded raft `StateMachine`.

#![allow(clippy::uninlined_format_args)]

mod kv_api_impl;
mod meta_embedded;

pub use meta_embedded::MetaEmbedded;
pub use databend_common_meta_raft_store::mem_meta::MemMeta;
pub use databend_common_meta_raft_store::mem_state_machine::MemStateMachine;
128 changes: 0 additions & 128 deletions src/meta/embedded/src/meta_embedded.rs

This file was deleted.

66 changes: 30 additions & 36 deletions src/meta/embedded/tests/it/kv_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,42 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::BTreeMap;
use std::sync::Once;

use databend_common_base::base::tokio;
use databend_common_meta_embedded::MetaEmbedded;
use databend_common_meta_kvapi::kvapi;

#[tokio::test(flavor = "multi_thread")]
async fn test_kv_write_read() -> anyhow::Result<()> {
let kv = MetaEmbedded::new_temp().await?;
kvapi::TestSuite {}.kv_write_read(&kv).await
}

#[tokio::test(flavor = "multi_thread")]
async fn test_kv_delete() -> anyhow::Result<()> {
let kv = MetaEmbedded::new_temp().await?;
kvapi::TestSuite {}.kv_delete(&kv).await
use databend_common_meta_raft_store::mem_meta::MemMeta;
use databend_common_tracing::init_logging;
use databend_common_tracing::Config;

#[derive(Clone)]
struct Builder;

#[async_trait::async_trait]
impl kvapi::ApiBuilder<MemMeta> for Builder {
async fn build(&self) -> MemMeta {
MemMeta::default()
}

async fn build_cluster(&self) -> Vec<MemMeta> {
unreachable!("InMemoryMeta does not support cluster")
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_kv_update() -> anyhow::Result<()> {
let kv = MetaEmbedded::new_temp().await?;
kvapi::TestSuite {}.kv_update(&kv).await
async fn test_mem_meta_kv_api() -> anyhow::Result<()> {
setup_test();
kvapi::TestSuite {}.test_single_node(&Builder).await
}

#[tokio::test(flavor = "multi_thread")]
async fn test_kv_timeout() -> anyhow::Result<()> {
let kv = MetaEmbedded::new_temp().await?;
kvapi::TestSuite {}.kv_timeout(&kv).await
}
fn setup_test() {
static INIT: Once = Once::new();
INIT.call_once(|| {
let mut config = Config::new_testing();
config.file.prefix_filter = "".to_string();

#[tokio::test(flavor = "multi_thread")]
async fn test_kv_meta() -> anyhow::Result<()> {
let kv = MetaEmbedded::new_temp().await?;
kvapi::TestSuite {}.kv_meta(&kv).await
}

#[tokio::test(flavor = "multi_thread")]
async fn test_kv_list() -> anyhow::Result<()> {
let kv = MetaEmbedded::new_temp().await?;
kvapi::TestSuite {}.kv_list(&kv).await
}

#[tokio::test(flavor = "multi_thread")]
async fn test_kv_mget() -> anyhow::Result<()> {
let kv = MetaEmbedded::new_temp().await?;
kvapi::TestSuite {}.kv_mget(&kv).await
let guards = init_logging("meta_unittests", &config, BTreeMap::new());
Box::leak(Box::new(guards));
});
}
27 changes: 16 additions & 11 deletions src/meta/embedded/tests/it/schema_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,36 @@
use async_trait::async_trait;
use databend_common_meta_api::BackgroundApiTestSuite;
use databend_common_meta_api::SchemaApiTestSuite;
use databend_common_meta_embedded::MetaEmbedded;
use databend_common_meta_kvapi::kvapi;
use databend_common_meta_raft_store::mem_meta::MemMeta;
use test_harness::test;

use crate::testing::embedded_meta_test_harness;
use crate::testing::mem_meta_test_harness;

#[derive(Clone)]
pub struct MetaEmbeddedBuilder {}
pub struct MemMetaBuilder {}

#[async_trait]
impl kvapi::ApiBuilder<MetaEmbedded> for MetaEmbeddedBuilder {
async fn build(&self) -> MetaEmbedded {
MetaEmbedded::new_temp().await.unwrap()
impl kvapi::ApiBuilder<MemMeta> for MemMetaBuilder {
async fn build(&self) -> MemMeta {
MemMeta::default()
}

async fn build_cluster(&self) -> Vec<MetaEmbedded> {
async fn build_cluster(&self) -> Vec<MemMeta> {
unimplemented!("embedded meta does not support cluster mode")
}
}

#[test(harness = embedded_meta_test_harness)]
#[test(harness = mem_meta_test_harness)]
#[fastrace::trace]
async fn test_meta_embedded() -> anyhow::Result<()> {
SchemaApiTestSuite::test_single_node(MetaEmbeddedBuilder {}).await?;
BackgroundApiTestSuite::test_single_node(MetaEmbeddedBuilder {}).await?;
async fn test_mem_meta_schema_api() -> anyhow::Result<()> {
SchemaApiTestSuite::test_single_node(MemMetaBuilder {}).await?;
Ok(())
}

#[test(harness = mem_meta_test_harness)]
#[fastrace::trace]
async fn test_mem_meta_background_api() -> anyhow::Result<()> {
BackgroundApiTestSuite::test_single_node(MemMetaBuilder {}).await?;
Ok(())
}
Loading
Loading