Skip to content

Commit

Permalink
Merge pull request #2590 from drmingdrmer/catalog-backend
Browse files Browse the repository at this point in the history
[query] refactor: simplify meta backend for catalog
  • Loading branch information
drmingdrmer authored Nov 2, 2021
2 parents 04542ab + 8f46916 commit 9e14a97
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 192 deletions.
48 changes: 0 additions & 48 deletions query/src/catalogs/backends/impls/embedded_backend.rs

This file was deleted.

4 changes: 0 additions & 4 deletions query/src/catalogs/backends/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
// limitations under the License.
//

mod embedded_backend;
mod meta_cached;
mod meta_remote;
mod meta_sync;
mod remote_backend;

pub use embedded_backend::MetaEmbeddedSync;
pub use meta_cached::MetaCached;
pub use meta_remote::MetaRemote;
pub use meta_sync::MetaSync;
pub use remote_backend::MetaRemoteSync;
132 changes: 0 additions & 132 deletions query/src/catalogs/backends/impls/remote_backend.rs

This file was deleted.

5 changes: 3 additions & 2 deletions query/src/catalogs/backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ mod backend;
mod impls;

pub use backend::MetaApiSync;
pub use impls::MetaEmbeddedSync;
pub use impls::MetaRemoteSync;
pub use impls::MetaCached;
pub use impls::MetaRemote;
pub use impls::MetaSync;
39 changes: 33 additions & 6 deletions query/src/catalogs/impls/catalog/metastore_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@

use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;

use common_base::BlockingWait;
use common_context::TableDataContext;
use common_dal::InMemoryData;
use common_exception::ErrorCode;
use common_exception::Result;
use common_infallible::RwLock;
use common_meta_api::MetaApi;
use common_meta_embedded::MetaEmbedded;
use common_meta_types::CreateDatabaseReply;
use common_meta_types::DatabaseInfo;
use common_meta_types::MetaId;
Expand All @@ -36,8 +40,9 @@ use common_planners::DropTablePlan;
use common_tracing::tracing;

use crate::catalogs::backends::MetaApiSync;
use crate::catalogs::backends::MetaEmbeddedSync;
use crate::catalogs::backends::MetaRemoteSync;
use crate::catalogs::backends::MetaCached;
use crate::catalogs::backends::MetaRemote;
use crate::catalogs::backends::MetaSync;
use crate::catalogs::catalog::Catalog;
use crate::catalogs::Database;
use crate::catalogs::Table;
Expand Down Expand Up @@ -73,18 +78,40 @@ pub struct MetaStoreCatalog {
}

impl MetaStoreCatalog {
/// The component hierarchy is layered as:
/// ```text
/// Remote:
///
/// RPC
/// MetaSync -> MetaCached -> MetaRemote -------> Meta server Meta server
/// raft <---------> raft <----..
/// MetaEmbedded MetaEmbedded
///
/// Embedded:
///
/// MetaSync -> MetaCached -> MetaEmbedded
/// ```
pub fn try_create_with_config(conf: Config) -> Result<Self> {
let local_mode = conf.meta.meta_address.is_empty();
let meta: Arc<dyn MetaApiSync> = if local_mode {

let meta_store: Arc<dyn MetaApi> = if local_mode {
tracing::info!("use embedded meta");
// TODO(xp): This can only be used for test: data will be removed when program quit.
Arc::new(MetaEmbeddedSync::create()?)

let meta_embedded = MetaEmbedded::new_temp().wait(None)??;
Arc::new(meta_embedded)
} else {
tracing::info!("use remote meta");
let store_client_provider = Arc::new(MetaClientProvider::new(&conf));
Arc::new(MetaRemoteSync::create(store_client_provider))

let meta_client_provider = Arc::new(MetaClientProvider::new(&conf));
let meta_remote = MetaRemote::create(meta_client_provider);
Arc::new(meta_remote)
};

let meta_cached = MetaCached::create(meta_store);
let meta_sync = MetaSync::create(Arc::new(meta_cached), Some(Duration::from_millis(5000)));
let meta: Arc<dyn MetaApiSync> = Arc::new(meta_sync);

let plan = CreateDatabasePlan {
if_not_exists: true,
db: "default".to_string(),
Expand Down

0 comments on commit 9e14a97

Please sign in to comment.