Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rocksdb: Compaction guard: split SST by region boundaries (tikv#8115)
Signed-off-by: Yi Wu <yiwu@pingcap.com>
- Loading branch information
1 parent
1f2b76f
commit 4784818
Showing
19 changed files
with
581 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
use std::ffi::CString; | ||
|
||
pub struct RocksSstPartitionerFactory<F: engine_traits::SstPartitionerFactory>(pub F); | ||
|
||
impl<F: engine_traits::SstPartitionerFactory> rocksdb::SstPartitionerFactory | ||
for RocksSstPartitionerFactory<F> | ||
{ | ||
type Partitioner = RocksSstPartitioner<F::Partitioner>; | ||
|
||
fn name(&self) -> &CString { | ||
self.0.name() | ||
} | ||
|
||
fn create_partitioner( | ||
&self, | ||
context: &rocksdb::SstPartitionerContext, | ||
) -> Option<Self::Partitioner> { | ||
let ctx = engine_traits::SstPartitionerContext { | ||
is_full_compaction: context.is_full_compaction, | ||
is_manual_compaction: context.is_manual_compaction, | ||
output_level: context.output_level, | ||
smallest_key: context.smallest_key, | ||
largest_key: context.largest_key, | ||
}; | ||
self.0 | ||
.create_partitioner(&ctx) | ||
.map(|p| RocksSstPartitioner(p)) | ||
} | ||
} | ||
|
||
pub struct RocksSstPartitioner<P: engine_traits::SstPartitioner>(P); | ||
|
||
impl<P: engine_traits::SstPartitioner> rocksdb::SstPartitioner for RocksSstPartitioner<P> { | ||
fn should_partition( | ||
&self, | ||
request: &rocksdb::SstPartitionerRequest, | ||
) -> rocksdb::SstPartitionerResult { | ||
let req = engine_traits::SstPartitionerRequest { | ||
prev_user_key: request.prev_user_key, | ||
current_user_key: request.current_user_key, | ||
current_output_file_size: request.current_output_file_size, | ||
}; | ||
match self.0.should_partition(&req) { | ||
engine_traits::SstPartitionerResult::NotRequired => { | ||
rocksdb::SstPartitionerResult::NotRequired | ||
} | ||
engine_traits::SstPartitionerResult::Required => { | ||
rocksdb::SstPartitionerResult::Required | ||
} | ||
} | ||
} | ||
|
||
fn can_do_trivial_move(&self, smallest_key: &[u8], largest_key: &[u8]) -> bool { | ||
self.0.can_do_trivial_move(smallest_key, largest_key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
use std::ffi::CString; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct SstPartitionerRequest<'a> { | ||
pub prev_user_key: &'a [u8], | ||
pub current_user_key: &'a [u8], | ||
pub current_output_file_size: u64, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub enum SstPartitionerResult { | ||
NotRequired, | ||
Required, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct SstPartitionerContext<'a> { | ||
pub is_full_compaction: bool, | ||
pub is_manual_compaction: bool, | ||
pub output_level: i32, | ||
pub smallest_key: &'a [u8], | ||
pub largest_key: &'a [u8], | ||
} | ||
|
||
pub trait SstPartitioner { | ||
fn should_partition(&self, req: &SstPartitionerRequest) -> SstPartitionerResult; | ||
fn can_do_trivial_move(&self, smallest_key: &[u8], largest_key: &[u8]) -> bool; | ||
} | ||
|
||
pub trait SstPartitionerFactory: Sync + Send { | ||
// Lifetime of the partitioner can be changed to be bounded by the factory's lifetime once | ||
// generic associated types is supported. | ||
// https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md | ||
type Partitioner: SstPartitioner + 'static; | ||
|
||
fn name(&self) -> &CString; | ||
fn create_partitioner(&self, context: &SstPartitionerContext) -> Option<Self::Partitioner>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.