feat: manual compact api (#1912)

* merge develop

* chore: merge develop

* fix: some cr commentx

* fix: cr comments
This commit is contained in:
Lei, HUANG
2023-07-11 12:00:39 +08:00
committed by GitHub
parent fc850c9988
commit a7ea3bbc16
22 changed files with 327 additions and 85 deletions

View File

@@ -33,8 +33,9 @@ use object_store::ObjectStore;
use snafu::{ensure, OptionExt, ResultExt};
use store_api::manifest::{self, Manifest, ManifestVersion, MetaActionIterator};
use store_api::storage::{
AddColumn, AlterOperation, AlterRequest, ChunkReader, FlushContext, FlushReason, ReadContext,
Region, RegionMeta, RegionNumber, ScanRequest, SchemaRef, Snapshot, WriteContext, WriteRequest,
AddColumn, AlterOperation, AlterRequest, ChunkReader, CompactContext, FlushContext,
FlushReason, ReadContext, Region, RegionMeta, RegionNumber, ScanRequest, SchemaRef, Snapshot,
WriteContext, WriteRequest,
};
use table::error::{
InvalidTableSnafu, RegionSchemaMismatchSnafu, Result as TableResult, TableOperationSnafu,
@@ -332,6 +333,33 @@ impl<R: Region> Table for MitoTable<R> {
Ok(())
}
async fn compact(
&self,
region_number: Option<RegionNumber>,
wait: Option<bool>,
) -> TableResult<()> {
let compact_ctx = wait.map(|wait| CompactContext { wait }).unwrap_or_default();
let regions = self.regions.load();
if let Some(region_number) = region_number {
if let Some(region) = regions.get(&region_number) {
region
.compact(&compact_ctx)
.await
.map_err(BoxedError::new)
.context(table_error::TableOperationSnafu)?;
}
} else {
let _ = futures::future::try_join_all(
regions.values().map(|region| region.compact(&compact_ctx)),
)
.await
.map_err(BoxedError::new)
.context(TableOperationSnafu)?;
}
Ok(())
}
fn region_stats(&self) -> TableResult<Vec<RegionStat>> {
let regions = self.regions.load();

View File

@@ -26,9 +26,10 @@ use datatypes::schema::{ColumnSchema, Schema};
use storage::metadata::{RegionMetaImpl, RegionMetadata};
use storage::write_batch::WriteBatch;
use store_api::storage::{
AlterRequest, Chunk, ChunkReader, CloseOptions, CreateOptions, EngineContext, FlushContext,
GetRequest, GetResponse, OpenOptions, ReadContext, Region, RegionDescriptor, RegionId,
ScanRequest, ScanResponse, SchemaRef, Snapshot, StorageEngine, WriteContext, WriteResponse,
AlterRequest, Chunk, ChunkReader, CloseOptions, CompactContext, CreateOptions, EngineContext,
FlushContext, GetRequest, GetResponse, OpenOptions, ReadContext, Region, RegionDescriptor,
RegionId, ScanRequest, ScanResponse, SchemaRef, Snapshot, StorageEngine, WriteContext,
WriteResponse,
};
pub type Result<T> = std::result::Result<T, MockError>;
@@ -204,6 +205,10 @@ impl Region for MockRegion {
async fn flush(&self, _ctx: &FlushContext) -> Result<()> {
unimplemented!()
}
async fn compact(&self, _ctx: &CompactContext) -> std::result::Result<(), Self::Error> {
unimplemented!()
}
}
impl MockRegionInner {