mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-23 08:20:36 +00:00
feat: implement manual type for async index build (#7104)
* feat: prepare for index_build command Signed-off-by: SNC123 <sinhco@outlook.com> * feat: impl manual index build Signed-off-by: SNC123 <sinhco@outlook.com> * chore: clippy and fmt Signed-off-by: SNC123 <sinhco@outlook.com> * test: add idempotency check for manual build Signed-off-by: SNC123 <sinhco@outlook.com> * chore: apply suggestions Signed-off-by: SNC123 <sinhco@outlook.com> * chore: update proto Signed-off-by: SNC123 <sinhco@outlook.com> * chore: apply suggestions Signed-off-by: SNC123 <sinhco@outlook.com> * chore: fmt Signed-off-by: SNC123 <sinhco@outlook.com> * chore: update proto souce to greptimedb Signed-off-by: SNC123 <sinhco@outlook.com> * fix: cargo.lock Signed-off-by: SNC123 <sinhco@outlook.com> --------- Signed-off-by: SNC123 <sinhco@outlook.com>
This commit is contained in:
@@ -15,19 +15,19 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use api::v1::region::region_request::Body as RegionRequestBody;
|
||||
use api::v1::region::{CompactRequest, FlushRequest, RegionRequestHeader};
|
||||
use api::v1::region::{BuildIndexRequest, CompactRequest, FlushRequest, RegionRequestHeader};
|
||||
use catalog::CatalogManagerRef;
|
||||
use common_catalog::build_db_string;
|
||||
use common_meta::node_manager::{AffectedRows, NodeManagerRef};
|
||||
use common_meta::peer::Peer;
|
||||
use common_telemetry::tracing_context::TracingContext;
|
||||
use common_telemetry::{error, info};
|
||||
use common_telemetry::{debug, error, info};
|
||||
use futures_util::future;
|
||||
use partition::manager::{PartitionInfo, PartitionRuleManagerRef};
|
||||
use session::context::QueryContextRef;
|
||||
use snafu::prelude::*;
|
||||
use store_api::storage::RegionId;
|
||||
use table::requests::{CompactTableRequest, FlushTableRequest};
|
||||
use table::requests::{BuildIndexTableRequest, CompactTableRequest, FlushTableRequest};
|
||||
|
||||
use crate::error::{
|
||||
CatalogSnafu, FindRegionLeaderSnafu, FindTablePartitionRuleSnafu, JoinTaskSnafu,
|
||||
@@ -90,6 +90,43 @@ impl Requester {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Handle the request to build index for table.
|
||||
pub async fn handle_table_build_index(
|
||||
&self,
|
||||
request: BuildIndexTableRequest,
|
||||
ctx: QueryContextRef,
|
||||
) -> Result<AffectedRows> {
|
||||
let partitions = self
|
||||
.get_table_partitions(
|
||||
&request.catalog_name,
|
||||
&request.schema_name,
|
||||
&request.table_name,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let requests = partitions
|
||||
.into_iter()
|
||||
.map(|partition| {
|
||||
RegionRequestBody::BuildIndex(BuildIndexRequest {
|
||||
region_id: partition.id.into(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
info!(
|
||||
"Handle table manual build index for table {}",
|
||||
request.table_name
|
||||
);
|
||||
debug!("Request details: {:?}", request);
|
||||
|
||||
self.do_request(
|
||||
requests,
|
||||
Some(build_db_string(&request.catalog_name, &request.schema_name)),
|
||||
&ctx,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Handle the request to compact table.
|
||||
pub async fn handle_table_compaction(
|
||||
&self,
|
||||
@@ -201,6 +238,7 @@ impl Requester {
|
||||
let region_id = match req {
|
||||
RegionRequestBody::Flush(req) => req.region_id,
|
||||
RegionRequestBody::Compact(req) => req.region_id,
|
||||
RegionRequestBody::BuildIndex(req) => req.region_id,
|
||||
_ => {
|
||||
error!("Unsupported region request: {:?}", req);
|
||||
return UnsupportedRegionRequestSnafu {}.fail();
|
||||
|
||||
@@ -23,8 +23,8 @@ use session::context::QueryContextRef;
|
||||
use snafu::ResultExt;
|
||||
use store_api::storage::RegionId;
|
||||
use table::requests::{
|
||||
CompactTableRequest, DeleteRequest as TableDeleteRequest, FlushTableRequest,
|
||||
InsertRequest as TableInsertRequest,
|
||||
BuildIndexTableRequest, CompactTableRequest, DeleteRequest as TableDeleteRequest,
|
||||
FlushTableRequest, InsertRequest as TableInsertRequest,
|
||||
};
|
||||
|
||||
use crate::delete::DeleterRef;
|
||||
@@ -97,6 +97,18 @@ impl TableMutationHandler for TableMutationOperator {
|
||||
.context(query_error::TableMutationSnafu)
|
||||
}
|
||||
|
||||
async fn build_index(
|
||||
&self,
|
||||
request: BuildIndexTableRequest,
|
||||
ctx: QueryContextRef,
|
||||
) -> QueryResult<AffectedRows> {
|
||||
self.requester
|
||||
.handle_table_build_index(request, ctx)
|
||||
.await
|
||||
.map_err(BoxedError::new)
|
||||
.context(query_error::TableMutationSnafu)
|
||||
}
|
||||
|
||||
async fn flush_region(
|
||||
&self,
|
||||
region_id: RegionId,
|
||||
|
||||
Reference in New Issue
Block a user