-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
*: support split table #2378
Changes from 52 commits
c0b3a92
6a3fff6
7208788
b6a3863
390d992
2ecd065
17ff50f
be78927
859b036
34d7639
e15219e
221fd20
7a95a53
bcd874a
7a0f44c
1b2c466
3a6013d
048d751
81ee366
9d0576a
809e3f0
5d37e2e
8d4404b
c379b7a
f78175f
a975491
57641ea
362c46f
0594bed
01eb0a1
8c6d6be
341b9c0
9a54c40
9129dae
9c89574
ac89022
52211d4
1ed761e
ac48aef
19afb85
70f2651
057cd44
7a35bc2
50cd4c4
c877f25
c9c84b4
1a7a4e5
ed0216d
ec4f170
2582c70
4a7802e
0a12b11
14f86ec
a2e1701
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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())), | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we guarantee the table observer can be run before size observer? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
|
There was a problem hiding this comment.
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.