mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 05:34:02 +00:00
Expose live compaction tasks through the datanode inspection path with node pruning, lazy projected batches, and residual SQL filtering. Reuse inspection request and plan helpers across compaction and SST tables. Cover routing, projection, predicates, and lifecycle behavior in datanode, standalone and distributed integration, and SQL tests. Use the production information extension in the standalone test fixture. Signed-off-by: WenyXu <wenymedia@gmail.com>
138 lines
4.9 KiB
Rust
138 lines
4.9 KiB
Rust
// Copyright 2023 Greptime Team
|
|
//
|
|
// 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 tables;
|
|
|
|
use std::sync::{Arc, Weak};
|
|
|
|
use common_meta::key::TableMetadataManagerRef;
|
|
use common_query::logical_plan::is_lossless_substrait_type;
|
|
use datafusion::common::DFSchema;
|
|
use datafusion::common::tree_node::{TreeNode, TreeNodeRecursion};
|
|
use datafusion::logical_expr::ExprSchemable;
|
|
use datafusion::physical_plan::ExecutionPlan;
|
|
use datatypes::schema::SchemaRef;
|
|
use snafu::{OptionExt, ResultExt};
|
|
use store_api::storage::ScanRequest;
|
|
|
|
use crate::CatalogManager;
|
|
use crate::error::{
|
|
GetInformationExtensionSnafu, ProjectSchemaSnafu, Result, UpgradeWeakCatalogManagerRefSnafu,
|
|
};
|
|
use crate::information_schema::{
|
|
DatanodeInspectKind, DatanodeInspectRequest, InformationExtensionRef,
|
|
};
|
|
use crate::kvbackend::KvBackendCatalogManager;
|
|
use crate::system_schema::semantic_graph::EntityGraphProviderRef;
|
|
|
|
/// Projects an inspection table schema according to the scan request.
|
|
pub(crate) fn projected_schema(schema: &SchemaRef, request: &ScanRequest) -> Result<SchemaRef> {
|
|
if let Some(p) = request.projection.as_deref() {
|
|
Ok(Arc::new(schema.try_project(p).context(ProjectSchemaSnafu)?))
|
|
} else {
|
|
Ok(schema.clone())
|
|
}
|
|
}
|
|
|
|
/// Builds a datanode inspection plan with the requested output schema.
|
|
pub(crate) fn inspect_plan(
|
|
catalog_manager: &Weak<dyn CatalogManager>,
|
|
kind: DatanodeInspectKind,
|
|
schema: &SchemaRef,
|
|
request: ScanRequest,
|
|
) -> Result<Option<Arc<dyn ExecutionPlan>>> {
|
|
let projected_schema = projected_schema(schema, &request)?;
|
|
let info_ext = information_extension(catalog_manager)?;
|
|
let req = inspect_request(kind, schema, request)?;
|
|
|
|
info_ext.inspect_datanode_plan(req, projected_schema)
|
|
}
|
|
|
|
/// System table predicates are inexact: the frontend keeps a residual filter. Dropping
|
|
/// an unsafe remote filter preserves correctness only if no remote limit truncates it.
|
|
pub(crate) fn inspect_request(
|
|
kind: DatanodeInspectKind,
|
|
schema: &SchemaRef,
|
|
mut scan: ScanRequest,
|
|
) -> Result<DatanodeInspectRequest> {
|
|
let schema =
|
|
DFSchema::try_from(schema.arrow_schema().clone()).context(crate::error::DatafusionSnafu)?;
|
|
let filter_count = scan.filters.len();
|
|
scan.filters.retain(|filter| {
|
|
let mut supported = true;
|
|
let visited = filter.apply(|expr| {
|
|
if !expr
|
|
.get_type(&schema)
|
|
.is_ok_and(|data_type| is_lossless_substrait_type(&data_type))
|
|
{
|
|
supported = false;
|
|
return Ok(TreeNodeRecursion::Stop);
|
|
}
|
|
Ok(TreeNodeRecursion::Continue)
|
|
});
|
|
visited.is_ok() && supported
|
|
});
|
|
if scan.filters.len() != filter_count {
|
|
scan.limit = None;
|
|
}
|
|
Ok(DatanodeInspectRequest { kind, scan })
|
|
}
|
|
|
|
/// Try to get the entity-graph provider from a `[CatalogManager]` weak reference.
|
|
/// Returns `None` when the manager is not the kv-backed one or the provider has
|
|
/// not been injected yet (the computed graph tables then stream empty).
|
|
pub fn entity_graph_provider(
|
|
catalog_manager: &Weak<dyn CatalogManager>,
|
|
) -> Result<Option<EntityGraphProviderRef>> {
|
|
let catalog_manager = catalog_manager
|
|
.upgrade()
|
|
.context(UpgradeWeakCatalogManagerRefSnafu)?;
|
|
|
|
Ok(catalog_manager
|
|
.as_any()
|
|
.downcast_ref::<KvBackendCatalogManager>()
|
|
.and_then(|manager| manager.entity_graph_provider()))
|
|
}
|
|
|
|
/// Try to get the `[InformationExtension]` from `[CatalogManager]` weak reference.
|
|
pub fn information_extension(
|
|
catalog_manager: &Weak<dyn CatalogManager>,
|
|
) -> Result<InformationExtensionRef> {
|
|
let catalog_manager = catalog_manager
|
|
.upgrade()
|
|
.context(UpgradeWeakCatalogManagerRefSnafu)?;
|
|
|
|
let information_extension = catalog_manager
|
|
.as_any()
|
|
.downcast_ref::<KvBackendCatalogManager>()
|
|
.map(|manager| manager.information_extension())
|
|
.context(GetInformationExtensionSnafu)?;
|
|
|
|
Ok(information_extension)
|
|
}
|
|
|
|
/// Try to get the `[TableMetadataManagerRef]` from `[CatalogManager]` weak reference.
|
|
pub fn table_meta_manager(
|
|
catalog_manager: &Weak<dyn CatalogManager>,
|
|
) -> Result<Option<TableMetadataManagerRef>> {
|
|
let catalog_manager = catalog_manager
|
|
.upgrade()
|
|
.context(UpgradeWeakCatalogManagerRefSnafu)?;
|
|
|
|
Ok(catalog_manager
|
|
.as_any()
|
|
.downcast_ref::<KvBackendCatalogManager>()
|
|
.map(|manager| manager.table_metadata_manager_ref().clone()))
|
|
}
|