Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: support split table #2378

Merged
merged 54 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c0b3a92
*: support split table
overvenus Oct 12, 2017
6a3fff6
config: add region_split_table configuration
overvenus Oct 12, 2017
7208788
Merge branch 'master' into ov/split-table
overvenus Oct 12, 2017
b6a3863
Address comments
overvenus Oct 12, 2017
390d992
Add Checker interface for decoupling coprocessor and split_check
overvenus Oct 13, 2017
2ecd065
Move splitting table configuration from raftstore to coprocessor
overvenus Oct 13, 2017
17ff50f
Add skip_check
overvenus Oct 17, 2017
be78927
Add coprocessor section
overvenus Oct 17, 2017
859b036
rename skip_check to prev_check and find_gap to find_split_key
overvenus Oct 17, 2017
34d7639
Merge branch 'master' into ov/split-table
overvenus Oct 17, 2017
e15219e
Address comments
overvenus Oct 17, 2017
221fd20
move Checker to coprocessor
overvenus Oct 19, 2017
7a95a53
Split table as long as first_key and last_key are not in the same table
overvenus Oct 19, 2017
bcd874a
Try to compute split key at before_check
overvenus Oct 20, 2017
7a0f44c
Add more tests for TableCheckerObserver
overvenus Oct 21, 2017
1b2c466
Hide split check observer
overvenus Oct 23, 2017
3a6013d
Merge branch 'master' into ov/split-table
overvenus Oct 23, 2017
048d751
Address comments
overvenus Oct 24, 2017
81ee366
Add comments
overvenus Oct 24, 2017
9d0576a
built
overvenus Oct 25, 2017
809e3f0
Move size check to coprocessor
overvenus Oct 26, 2017
5d37e2e
Skip region split size in coprocessor config
overvenus Oct 26, 2017
8d4404b
Clean up
overvenus Oct 26, 2017
c379b7a
Move split config from raftstore to coprocessor
overvenus Oct 26, 2017
f78175f
rename some methods
overvenus Oct 26, 2017
a975491
Address comments
overvenus Oct 26, 2017
57641ea
Clean up
overvenus Oct 27, 2017
362c46f
Address comments
overvenus Oct 27, 2017
0594bed
Add some comments
overvenus Oct 30, 2017
01eb0a1
Address comments
overvenus Oct 30, 2017
8c6d6be
Remove TableCheckObserver
overvenus Oct 31, 2017
341b9c0
Merge branch 'master' into split-table-part1
overvenus Oct 31, 2017
9a54c40
Address comments
overvenus Oct 31, 2017
9129dae
Revert "Remove TableCheckObserver"
overvenus Oct 31, 2017
9c89574
Remove `actual_` and skip if region is inside a table
overvenus Oct 31, 2017
ac89022
Address comments
overvenus Oct 31, 2017
52211d4
Address comments
overvenus Oct 31, 2017
1ed761e
Address comments
overvenus Oct 31, 2017
ac48aef
Address comments
overvenus Nov 1, 2017
19afb85
Set logger ASAP
overvenus Nov 1, 2017
70f2651
Merge branch 'master' into split-table-part1
overvenus Nov 1, 2017
057cd44
Merge branch 'split-table-part1' of github.com:overvenus/tikv into ov…
overvenus Nov 2, 2017
7a35bc2
Merge branch 'master' into ov/split-table
overvenus Nov 2, 2017
50cd4c4
Make split key a valid encoded key
overvenus Nov 2, 2017
c877f25
Add missing configuration
overvenus Nov 6, 2017
c9c84b4
Skip key validation
overvenus Nov 6, 2017
1a7a4e5
Address comments
overvenus Nov 6, 2017
ed0216d
Remove gen_table_prefix
overvenus Nov 6, 2017
ec4f170
Add a test for SplitObserver
overvenus Nov 6, 2017
2582c70
Use region start key instead actual start key
overvenus Nov 6, 2017
4a7802e
Address comments
overvenus Nov 6, 2017
0a12b11
Address comments
overvenus Nov 7, 2017
14f86ec
Address comments
overvenus Nov 7, 2017
a2e1701
Merge branch 'master' into ov/split-table
overvenus Nov 7, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions etc/config-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
# consistency-check-interval = 0

[coprocessor]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer you can send a PR for this at first.

# When it is true, it will try to split a region with table prefix if
# that region crosses tables.
# split-region-on-table = false
# When the region's size exceeds region-max-size, we will split the region
# into two which the left region's size will be region-split-size or a little
# bit smaller.
Expand Down
25 changes: 25 additions & 0 deletions src/coprocessor/codec/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub const RECORD_PREFIX_SEP: &'static [u8] = b"_r";
pub const INDEX_PREFIX_SEP: &'static [u8] = b"_i";
pub const SEP_LEN: usize = 2;
pub const TABLE_PREFIX_LEN: usize = 1;
pub const TABLE_PREFIX_KEY_LEN: usize = TABLE_PREFIX_LEN + ID_LEN;


trait TableEncoder: NumberEncoder {
Expand All @@ -53,6 +54,19 @@ trait TableEncoder: NumberEncoder {

impl<T: Write> TableEncoder for T {}

/// Extract table prefix from table record or index.
// It is useful in tests.
pub fn extract_table_prefix(key: &[u8]) -> Result<&[u8]> {
if !key.starts_with(TABLE_PREFIX) || key.len() < TABLE_PREFIX_KEY_LEN {
Err(invalid_type!(
"record key or index key expected, but got {:?}",
key
))
} else {
Ok(&key[..TABLE_PREFIX_KEY_LEN])
}
}

pub fn flatten(data: Datum) -> Result<Datum> {
match data {
Datum::Dur(d) => Ok(Datum::I64(d.to_nanos())),
Expand Down Expand Up @@ -570,4 +584,15 @@ mod test {
assert!(res.0.is_empty());
assert!(res.1.is_none());
}

#[test]
fn test_extract_table_prefix() {
extract_table_prefix(&[]).unwrap_err();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use table-driven test here.

extract_table_prefix(b"a\x80\x00\x00\x00\x00\x00\x00\x01").unwrap_err();
extract_table_prefix(b"t\x80\x00\x00\x00\x00\x00\x01").unwrap_err();
assert_eq!(
extract_table_prefix(b"t\x80\x00\x00\x00\x00\x00\x00\x01").unwrap(),
extract_table_prefix(b"t\x80\x00\x00\x00\x00\x00\x00\x01_r\xff\xff").unwrap()
);
}
}
5 changes: 5 additions & 0 deletions src/raftstore/coprocessor/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ use super::Result;
#[serde(default)]
#[serde(rename_all = "kebab-case")]
pub struct Config {
/// When it is true, it will try to split a region with table prefix if
/// that region crosses tables.
pub split_region_on_table: bool,

/// When region [a, b) size meets region_max_size, it will be split
/// into two region into [a, c), [c, b). And the size of [a, c) will
/// be region_split_size (or a little bit smaller).
Expand All @@ -32,6 +36,7 @@ impl Default for Config {
fn default() -> Config {
let split_size = ReadableSize::mb(SPLIT_SIZE_MB);
Config {
split_region_on_table: false,
region_split_size: split_size,
region_max_size: split_size / 2 * 3,
}
Expand Down
6 changes: 6 additions & 0 deletions src/raftstore/coprocessor/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ impl CoprocessorHost {
SIZE_CHECK_OBSERVER_PRIORITY,
Box::new(split_size_check_observer),
);
if cfg.split_region_on_table {
registry.register_observer(
TABLE_CHECK_OBSERVER_PRIORITY,
Box::new(TableCheckObserver::default()),
);
}
CoprocessorHost { registry: registry }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we guarantee the table observer can be run before size observer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the priority of table observer is higher[0] than size observer.

[0] higher means less.

}

Expand Down
4 changes: 2 additions & 2 deletions src/raftstore/coprocessor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub use self::config::Config;
pub use self::region_snapshot::{RegionIterator, RegionSnapshot};
pub use self::dispatcher::{CoprocessorHost, Registry};
pub use self::error::{Error, Result};
pub use self::split_check::{SizeCheckObserver, Status as SplitCheckStatus,
SIZE_CHECK_OBSERVER_PRIORITY};
pub use self::split_check::{SizeCheckObserver, Status as SplitCheckStatus, TableCheckObserver,
SIZE_CHECK_OBSERVER_PRIORITY, TABLE_CHECK_OBSERVER_PRIORITY};

/// Coprocessor is used to provide a convient way to inject code to
/// KV processing.
Expand Down
10 changes: 9 additions & 1 deletion src/raftstore/coprocessor/split_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod table;
mod size;

use self::size::SizeStatus;
use self::table::TableStatus;

pub use self::size::SizeCheckObserver;
pub const SIZE_CHECK_OBSERVER_PRIORITY: u32 = 200;
pub use self::table::TableCheckObserver;
// TableCheckObserver has higher priority than TableCheckObserver.
// Note that higher means less.
pub const TABLE_CHECK_OBSERVER_PRIORITY: u32 = SIZE_CHECK_OBSERVER_PRIORITY - 1;

#[derive(Default)]
pub struct Status {
// For TableCheckObserver
table: Option<TableStatus>,
// For SizeCheckObserver
size: Option<SizeStatus>,
}

impl Status {
pub fn skip(&self) -> bool {
self.size.is_none()
self.table.is_none() && self.size.is_none()
}
}
Loading