Skip to content

Commit

Permalink
feat: use simple filter to prune memtable (#3269)
Browse files Browse the repository at this point in the history
* switch on clippy warnings

Signed-off-by: Ruihang Xia <[email protected]>

* feat: use simple filter to prune memtable

Signed-off-by: Ruihang Xia <[email protected]>

* remove deadcode

Signed-off-by: Ruihang Xia <[email protected]>

* refine util function

Signed-off-by: Ruihang Xia <[email protected]>

---------

Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored Feb 4, 2024
1 parent 902570a commit 51feec2
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 163 deletions.
3 changes: 1 addition & 2 deletions src/metric-engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use std::sync::{Arc, RwLock};
use async_trait::async_trait;
use common_error::ext::{BoxedError, ErrorExt};
use common_error::status_code::StatusCode;
use common_query::Output;
use common_recordbatch::SendableRecordBatchStream;
use mito2::engine::MitoEngine;
use store_api::metadata::RegionMetadataRef;
Expand Down Expand Up @@ -133,7 +132,7 @@ impl RegionEngine for MetricEngine {
RegionRequest::Flush(_) => todo!(),
RegionRequest::Compact(_) => todo!(),
RegionRequest::Truncate(_) => todo!(),
/// It always Ok(0), all data is latest.
// It always Ok(0), all data is the latest.
RegionRequest::Catchup(_) => Ok(0),
};

Expand Down
18 changes: 4 additions & 14 deletions src/metric-engine/src/engine/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,15 @@

//! Close a metric region
use mito2::engine::MITO_ENGINE_NAME;
use object_store::util::join_dir;
use snafu::{OptionExt, ResultExt};
use store_api::metric_engine_consts::{
DATA_REGION_SUBDIR, METADATA_REGION_SUBDIR, PHYSICAL_TABLE_METADATA_KEY,
};
use snafu::ResultExt;
use store_api::region_engine::RegionEngine;
use store_api::region_request::{
AffectedRows, RegionCloseRequest, RegionOpenRequest, RegionRequest,
};
use store_api::region_request::{AffectedRows, RegionCloseRequest, RegionRequest};
use store_api::storage::RegionId;

use super::MetricEngineInner;
use crate::error::{
CloseMitoRegionSnafu, Error, LogicalRegionNotFoundSnafu, OpenMitoRegionSnafu,
PhysicalRegionNotFoundSnafu, Result,
};
use crate::error::{CloseMitoRegionSnafu, LogicalRegionNotFoundSnafu, Result};
use crate::metrics::PHYSICAL_REGION_COUNT;
use crate::{metadata_region, utils};
use crate::utils;

impl MetricEngineInner {
pub async fn close_region(
Expand Down
16 changes: 4 additions & 12 deletions src/metric-engine/src/engine/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,17 @@

//! Drop a metric region
use mito2::engine::MITO_ENGINE_NAME;
use object_store::util::join_dir;
use snafu::{OptionExt, ResultExt};
use store_api::metric_engine_consts::{
DATA_REGION_SUBDIR, METADATA_REGION_SUBDIR, PHYSICAL_TABLE_METADATA_KEY,
};
use snafu::ResultExt;
use store_api::region_engine::RegionEngine;
use store_api::region_request::{
AffectedRows, RegionDropRequest, RegionOpenRequest, RegionRequest,
};
use store_api::region_request::{AffectedRows, RegionDropRequest, RegionRequest};
use store_api::storage::RegionId;

use super::MetricEngineInner;
use crate::error::{
CloseMitoRegionSnafu, Error, LogicalRegionNotFoundSnafu, OpenMitoRegionSnafu,
PhysicalRegionBusySnafu, PhysicalRegionNotFoundSnafu, Result,
CloseMitoRegionSnafu, LogicalRegionNotFoundSnafu, PhysicalRegionBusySnafu, Result,
};
use crate::metrics::PHYSICAL_REGION_COUNT;
use crate::{metadata_region, utils};
use crate::utils;

impl MetricEngineInner {
pub async fn drop_region(
Expand Down
2 changes: 1 addition & 1 deletion src/metric-engine/src/engine/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use store_api::region_request::{AffectedRows, RegionOpenRequest, RegionRequest};
use store_api::storage::RegionId;

use super::MetricEngineInner;
use crate::error::{Error, LogicalRegionNotFoundSnafu, OpenMitoRegionSnafu, Result};
use crate::error::{OpenMitoRegionSnafu, Result};
use crate::metrics::{LOGICAL_REGION_COUNT, PHYSICAL_REGION_COUNT};
use crate::utils;

Expand Down
6 changes: 3 additions & 3 deletions src/metric-engine/src/engine/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::hash::{BuildHasher, Hash, Hasher};
use std::hash::Hash;

use api::v1::value::ValueData;
use api::v1::{ColumnDataType, ColumnSchema, Row, Rows, SemanticType};
Expand All @@ -29,7 +29,7 @@ use crate::error::{
ColumnNotFoundSnafu, ForbiddenPhysicalAlterSnafu, LogicalRegionNotFoundSnafu, Result,
};
use crate::metrics::{FORBIDDEN_OPERATION_COUNT, MITO_OPERATION_ELAPSED};
use crate::utils::{to_data_region_id, to_metadata_region_id};
use crate::utils::to_data_region_id;

// A random number
const TSID_HASH_SEED: u32 = 846793005;
Expand Down Expand Up @@ -84,6 +84,7 @@ impl MetricEngineInner {
.await?;

// write to data region

// TODO: retrieve table name
self.modify_rows(logical_region_id.table_id(), &mut request.rows)?;
self.data_region.write_data(data_region_id, request).await
Expand All @@ -101,7 +102,6 @@ impl MetricEngineInner {
request: &RegionPutRequest,
) -> Result<()> {
// check if the region exists
let metadata_region_id = to_metadata_region_id(physical_region_id);
let data_region_id = to_data_region_id(physical_region_id);
let state = self.state.read().unwrap();
if !state.is_logical_region_exist(logical_region_id) {
Expand Down
9 changes: 3 additions & 6 deletions src/metric-engine/src/engine/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use common_recordbatch::SendableRecordBatchStream;
use common_telemetry::{error, info, tracing};
use datafusion::logical_expr;
use snafu::{OptionExt, ResultExt};
use store_api::metadata::{RegionMetadata, RegionMetadataBuilder, RegionMetadataRef};
use store_api::metadata::{RegionMetadataBuilder, RegionMetadataRef};
use store_api::metric_engine_consts::DATA_SCHEMA_TABLE_ID_COLUMN_NAME;
use store_api::region_engine::RegionEngine;
use store_api::storage::consts::ReservedColumnId;
use store_api::storage::{RegionId, ScanRequest};

use crate::engine::MetricEngineInner;
Expand Down Expand Up @@ -259,7 +258,6 @@ mod test {
use store_api::region_request::RegionRequest;

use super::*;
use crate::engine::alter;
use crate::test_util::{
alter_logical_region_add_tag_columns, create_logical_region_request, TestEnv,
};
Expand All @@ -271,7 +269,6 @@ mod test {

let logical_region_id = env.default_logical_region_id();
let physical_region_id = env.default_physical_region_id();
let data_region_id = utils::to_data_region_id(physical_region_id);

// create another logical region
let logical_region_id2 = RegionId::new(1112345678, 999);
Expand All @@ -291,7 +288,7 @@ mod test {
.unwrap();

// check explicit projection
let mut scan_req = ScanRequest {
let scan_req = ScanRequest {
projection: Some(vec![0, 1, 2, 3, 4, 5, 6]),
filters: vec![],
..Default::default()
Expand All @@ -314,7 +311,7 @@ mod test {
);

// check default projection
let mut scan_req = ScanRequest::default();
let scan_req = ScanRequest::default();
let scan_req = env
.metric()
.inner
Expand Down
6 changes: 1 addition & 5 deletions src/metric-engine/src/engine/region_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@

//! Implementation of retrieving logical region's region metadata.
use std::collections::{HashMap, HashSet};

use api::v1::SemanticType;
use store_api::metadata::{ColumnMetadata, RegionMetadata};
use store_api::storage::consts::ReservedColumnId;
use store_api::metadata::ColumnMetadata;
use store_api::storage::RegionId;

use crate::engine::MetricEngineInner;
Expand Down
1 change: 0 additions & 1 deletion src/metric-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#![feature(let_chains)]

mod data_region;
#[allow(unused)]
pub mod engine;
pub mod error;
mod metadata_region;
Expand Down
3 changes: 0 additions & 3 deletions src/metric-engine/src/metadata_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,11 @@ impl MetadataRegion {
format!("{COLUMN_PREFIX}{}_", region_id.as_u64())
}

#[allow(dead_code)]
pub fn parse_region_key(key: &str) -> Option<&str> {
key.strip_prefix(REGION_PREFIX)
}

/// Parse column key to (logical_region_id, column_name)
#[allow(dead_code)]
pub fn parse_column_key(key: &str) -> Result<Option<(RegionId, String)>> {
if let Some(stripped) = key.strip_prefix(COLUMN_PREFIX) {
let mut iter = stripped.split('_');
Expand Down Expand Up @@ -271,7 +269,6 @@ impl MetadataRegion {
// simulate to `KvBackend`
//
// methods in this block assume the given region id is transformed.
#[allow(unused_variables)]
impl MetadataRegion {
/// Put if not exist, return if this put operation is successful (error other
/// than "key already exist" will be wrapped in [Err]).
Expand Down
Loading

0 comments on commit 51feec2

Please sign in to comment.