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

feat: add vacuum impl #11320

Merged
merged 16 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ members = [
"src/query/storages/parquet",
"src/query/storages/result_cache",
"src/query/users",
"src/query/ee-features/vacuum-handler",
# databend-query
"src/query/service",
# enterprise
Expand Down
1 change: 1 addition & 0 deletions src/binaries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ common-config = { path = "../query/config" }
common-exception = { path = "../common/exception" }
common-expression = { path = "../query/expression" }
common-grpc = { path = "../common/grpc" }
common-license = { path = "../common/license" }
common-meta-api = { path = "../meta/api" }
common-meta-app = { path = "../meta/app" }
common-meta-client = { path = "../meta/client" }
Expand Down
4 changes: 4 additions & 0 deletions src/binaries/query/oss_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use common_base::mem_allocator::GlobalAllocator;
use common_base::runtime::Runtime;
use common_config::InnerConfig;
use common_exception::Result;
use common_license::license_manager::LicenseManager;
use common_license::license_manager::OssLicenseManager;

use crate::entry::init_services;
use crate::entry::start_services;
Expand All @@ -47,5 +49,7 @@ fn main() {
async fn main_entrypoint() -> Result<()> {
let conf: InnerConfig = InnerConfig::load()?;
init_services(&conf).await?;
// init oss license manager
OssLicenseManager::init()?;
BohuTANG marked this conversation as resolved.
Show resolved Hide resolved
start_services(&conf).await
}
28 changes: 28 additions & 0 deletions src/common/license/src/license_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use std::sync::Arc;

use common_base::base::GlobalInstance;
use common_exception::ErrorCode;
use common_exception::Result;
use jwt_simple::claims::JWTClaims;

Expand Down Expand Up @@ -61,6 +62,33 @@ pub struct LicenseManagerWrapper {
unsafe impl Send for LicenseManagerWrapper {}
unsafe impl Sync for LicenseManagerWrapper {}

pub struct OssLicenseManager {}

impl LicenseManager for OssLicenseManager {
fn init() -> Result<()> {
let rm = OssLicenseManager {};
let wrapper = LicenseManagerWrapper {
manager: Box::new(rm),
};
GlobalInstance::set(Arc::new(wrapper));
Ok(())
}

fn instance() -> Arc<Box<dyn LicenseManager>> {
GlobalInstance::get()
}

fn is_active(&self) -> bool {
false
}

fn make_license(_raw: &str) -> Result<JWTClaims<LicenseInfo>> {
Err(ErrorCode::LicenceDenied(
"Need Commercial License".to_string(),
))
}
}

pub fn get_license_manager() -> Arc<LicenseManagerWrapper> {
GlobalInstance::get()
}
1 change: 1 addition & 0 deletions src/query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Databend Query is a Distributed Query Engine at scale.
- [`streams`](./streams/) contains data sources and streams.
- [`users`](./users/), role-based access and control.
- [`ee`](ee/) contains enterprise functionalities.
- [`ee-features`](ee-features/) contains enterprise features.
1 change: 1 addition & 0 deletions src/query/ee-features/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`ee-features` contains all the enterprise version feature traits.
28 changes: 28 additions & 0 deletions src/query/ee-features/vacuum-handler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "vacuum-handler"
description = "vacuum handler"
version = { workspace = true }
authors = { workspace = true }
license = { workspace = true }
publish = { workspace = true }
edition = { workspace = true }

[lib]
doctest = false
test = false

[dependencies]
# Workspace dependencies
common-base = { path = "../../../common/base" }
common-catalog = { path = "../../catalog" }
common-exception = { path = "../../../common/exception" }
common-storages-fuse = { path = "../../storages/fuse" }

async-backtrace = { workspace = true }
async-trait = "0.1.57"
chrono = { workspace = true }

[build-dependencies]

[package.metadata.cargo-machete]
ignored = ["match-template"]
19 changes: 19 additions & 0 deletions src/query/ee-features/vacuum-handler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod vacuum_handler;

pub use vacuum_handler::get_vacuum_handler;
pub use vacuum_handler::VacuumHandler;
pub use vacuum_handler::VacuumHandlerWrapper;
58 changes: 58 additions & 0 deletions src/query/ee-features/vacuum-handler/src/vacuum_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;

use chrono::DateTime;
use chrono::Utc;
use common_base::base::GlobalInstance;
use common_catalog::table_context::TableContext;
use common_exception::Result;
use common_storages_fuse::FuseTable;

#[async_trait::async_trait]
pub trait VacuumHandler: Sync + Send {
async fn do_vacuum(
&self,
fuse_table: &FuseTable,
ctx: Arc<dyn TableContext>,
retention_time: DateTime<Utc>,
) -> Result<()>;
}

pub struct VacuumHandlerWrapper {
handler: Box<dyn VacuumHandler>,
}

impl VacuumHandlerWrapper {
pub fn new(handler: Box<dyn VacuumHandler>) -> Self {
Self { handler }
}

#[async_backtrace::framed]
pub async fn do_vacuum(
&self,
fuse_table: &FuseTable,
ctx: Arc<dyn TableContext>,
retention_time: DateTime<Utc>,
) -> Result<()> {
self.handler
.do_vacuum(fuse_table, ctx, retention_time)
.await
}
}

pub fn get_vacuum_handler() -> Arc<VacuumHandlerWrapper> {
GlobalInstance::get()
}
10 changes: 10 additions & 0 deletions src/query/ee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ test = false
# Workspace dependencies
async-backtrace = { workspace = true }
common-base = { path = "../../common/base" }
common-catalog = { path = "../catalog" }
common-config = { path = "../config" }
common-exception = { path = "../../common/exception" }
common-license = { path = "../../common/license" }
common-storages-fuse = { path = "../storages/fuse" }
databend-query = { path = "../service" }
storages-common-cache = { path = "../storages/common/cache" }
storages-common-table-meta = { path = "../storages/common/table-meta" }
vacuum-handler = { path = "../ee-features/vacuum-handler" }

async-trait = "0.1.57"
chrono = { workspace = true }
jwt-simple = "0.11.0"
tracing = "0.1.36"

[build-dependencies]
common-building = { path = "../../common/building" }
Expand Down
2 changes: 2 additions & 0 deletions src/query/ee/src/enterprise_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ use common_exception::Result;
use common_license::license_manager::LicenseManager;

use crate::license::license_mgr::RealLicenseManager;
use crate::storages::fuse::operations::RealVacuumHandler;

pub struct EnterpriseServices;
impl EnterpriseServices {
#[async_backtrace::framed]
pub async fn init(_config: InnerConfig) -> Result<()> {
RealLicenseManager::init()?;
RealVacuumHandler::init()?;
Ok(())
}
}
1 change: 1 addition & 0 deletions src/query/ee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@

pub mod enterprise_services;
pub mod license;
pub mod storages;
1 change: 1 addition & 0 deletions src/query/ee/src/license/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
// limitations under the License.

pub mod license_mgr;
pub use license_mgr::RealLicenseManager;
15 changes: 15 additions & 0 deletions src/query/ee/src/storages/fuse/io/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 Databend Cloud
//
// Licensed under the Elastic License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.elastic.co/licensing/elastic-license
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod snapshots;
Loading