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

@@ -20,14 +20,14 @@ use common_telemetry::{debug, error, info, timer};
use itertools::Itertools;
use snafu::ResultExt;
use store_api::logstore::LogStore;
use store_api::storage::RegionId;
use store_api::storage::{CompactContext, RegionId};
use crate::compaction::writer::build_sst_reader;
use crate::error;
use crate::error::Result;
use crate::manifest::action::RegionEdit;
use crate::manifest::region::RegionManifest;
use crate::region::{CompactContext, RegionWriterRef, SharedDataRef, WriterCompactRequest};
use crate::region::{RegionWriterRef, SharedDataRef, WriterCompactRequest};
use crate::schema::RegionSchemaRef;
use crate::sst::{
AccessLayerRef, FileHandle, FileId, FileMeta, Level, Source, SstInfo, WriteOptions,

View File

@@ -32,8 +32,8 @@ use store_api::manifest::{
self, Manifest, ManifestLogStorage, ManifestVersion, MetaActionIterator,
};
use store_api::storage::{
AlterRequest, CloseContext, CompactionStrategy, FlushContext, FlushReason, OpenOptions,
ReadContext, Region, RegionId, SequenceNumber, WriteContext, WriteResponse,
AlterRequest, CloseContext, CompactContext, CompactionStrategy, FlushContext, FlushReason,
OpenOptions, ReadContext, Region, RegionId, SequenceNumber, WriteContext, WriteResponse,
};
use crate::compaction::{
@@ -150,6 +150,10 @@ impl<S: LogStore> Region for RegionImpl<S> {
async fn flush(&self, ctx: &FlushContext) -> Result<()> {
self.inner.flush(ctx).await
}
async fn compact(&self, ctx: &CompactContext) -> std::result::Result<(), Self::Error> {
self.inner.compact(ctx).await
}
}
/// Storage related config for region.
@@ -174,18 +178,6 @@ pub struct StoreConfig<S: LogStore> {
pub type RecoveredMetadata = (SequenceNumber, (ManifestVersion, RawRegionMetadata));
pub type RecoveredMetadataMap = BTreeMap<SequenceNumber, (ManifestVersion, RawRegionMetadata)>;
#[derive(Debug)]
pub struct CompactContext {
/// Whether to wait the compaction result.
pub wait: bool,
}
impl Default for CompactContext {
fn default() -> CompactContext {
CompactContext { wait: true }
}
}
impl<S: LogStore> RegionImpl<S> {
/// Create a new region and also persist the region metadata to manifest.
///
@@ -557,7 +549,7 @@ impl<S: LogStore> RegionImpl<S> {
}
/// Compact the region manually.
pub async fn compact(&self, ctx: CompactContext) -> Result<()> {
pub async fn compact(&self, ctx: &CompactContext) -> Result<()> {
self.inner.compact(ctx).await
}
@@ -765,7 +757,7 @@ impl<S: LogStore> RegionInner<S> {
}
/// Compact the region manually.
async fn compact(&self, compact_ctx: CompactContext) -> Result<()> {
async fn compact(&self, compact_ctx: &CompactContext) -> Result<()> {
self.writer
.compact(WriterCompactRequest {
shared_data: self.shared.clone(),
@@ -773,7 +765,7 @@ impl<S: LogStore> RegionInner<S> {
manifest: self.manifest.clone(),
wal: self.wal.clone(),
region_writer: self.writer.clone(),
compact_ctx,
compact_ctx: *compact_ctx,
})
.await
}

View File

@@ -223,7 +223,7 @@ impl CompactionTester {
// Trigger compaction and wait until it is done.
self.base()
.region
.compact(CompactContext::default())
.compact(&CompactContext::default())
.await
.unwrap();
}