Reserve key space id encoding in backup convert#12759
Reserve key space id encoding in backup convert#12759ti-chi-bot merged 14 commits intotikv:masterfrom
Conversation
|
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. DetailsReviewer can indicate their review by submitting an approval review. |
Signed-off-by: haojinming <jinming.hao@pingcap.com>
6e2a944 to
3154629
Compare
Signed-off-by: haojinming <jinming.hao@pingcap.com>
components/api_version/src/api_v1.rs
Outdated
| let (mut user_key, _) = ApiV2::decode_raw_key(&Key::from_encoded_slice(key), true)?; | ||
| user_key.remove(0); // remove first byte `RAW_KEY_PREFIX` | ||
| Ok(Self::encode_raw_key_owned(user_key, None)) | ||
| Err(EngineError::Other(box_err!("unsupported conversion"))) |
There was a problem hiding this comment.
| Err(EngineError::Other(box_err!("unsupported conversion"))) | |
| Err(box_err!("unsupported conversion")) |
The same to other three similar.
There was a problem hiding this comment.
Maybe just panic ? The conversion from V2 to V1/V1TTL should be rejected by TiKV-BR, and when receive backup request. Other than the moment to convert key version.
There was a problem hiding this comment.
done, mark apiv2->apiv1 as unreachable
components/api_version/src/api_v2.rs
Outdated
| let mut apiv2_key = Vec::with_capacity(ApiV2::get_encode_len(key.len() + 2)); | ||
| apiv2_key.push(RAW_KEY_PREFIX); | ||
| let mut tmp_buf = [0; MAX_VARINT64_LENGTH]; | ||
| let written = NumberCodec::encode_var_u64(&mut tmp_buf, DEFAULT_KEY_SPACE_ID); |
There was a problem hiding this comment.
Suggest to try making written be constant. Or just write a 0 and verify it's always equal to var_u64 in unit test.
There was a problem hiding this comment.
Let's make key space fixed.
components/api_version/src/api_v2.rs
Outdated
| } | ||
|
|
||
| pub fn add_prefix(key: &[u8]) -> Vec<u8> { | ||
| let mut apiv2_key = Vec::with_capacity(ApiV2::get_encode_len(key.len() + 2)); |
There was a problem hiding this comment.
Reserve capacity after encoded keyspace id is got and avoid hard coding the length.
| // the file range need be encoded as v2 format. | ||
| // And range in response keep in v1 format. | ||
| let (start, end) = codec.convert_key_range_to_dst_version( | ||
| let ret = codec.convert_key_range_to_dst_version( |
There was a problem hiding this comment.
Reject V2 -> V1/V1TTL earlier, e.g. KeyValueCodec::check_backup_api_version.
Signed-off-by: haojinming <jinming.hao@pingcap.com>
Signed-off-by: haojinming <jinming.hao@pingcap.com>
Signed-off-by: haojinming <jinming.hao@pingcap.com>
Signed-off-by: haojinming <jinming.hao@pingcap.com>
|
/run-build |
|
/run-test |
components/api_version/src/api_v1.rs
Outdated
| user_key.remove(0); // remove first byte `RAW_KEY_PREFIX` | ||
| Ok(Self::encode_raw_key_owned(user_key, None)) | ||
| } | ||
| ApiVersion::V2 => unreachable!(), // reject apiv2 -> apiv1 conversion |
There was a problem hiding this comment.
It will panic TiKV if the arm matches. What about returning an error?
There was a problem hiding this comment.
backup process do check the apiversion in
tikv/components/backup/src/utils.rs
Lines 127 to 133 in ba391ff
tikv/components/backup/src/endpoint.rs
Lines 213 to 216 in ba391ff
There was a problem hiding this comment.
Agree should return error instead of just panicking.
There was a problem hiding this comment.
@overvenus @BusyJay error handling is added, PTAL~ thanks.
components/api_version/src/api_v2.rs
Outdated
| start_key.insert(0, RAW_KEY_PREFIX); | ||
| start_key = ApiV2::add_prefix(&start_key); | ||
| if end_key.is_empty() { | ||
| end_key.insert(0, RAW_KEY_PREFIX_END); |
There was a problem hiding this comment.
The EMPTY end key should be mapped to r001?.
There was a problem hiding this comment.
Another question, when do we need this function while executing backup and restore.
There was a problem hiding this comment.
This is a conversion scenario, no key space exists in apiv1, so I think we need set 'r' + 1 as the whole end. Anyway, 'r' + 1 and r001 both works here. @pingyu How do you think?
There was a problem hiding this comment.
This function is needed when return backup response, range in BackupResponse.File need to be the apiv2 format if convert from apiv1/v1ttl to apiv2.
There was a problem hiding this comment.
En... I suggest r001 . It is a reasonble range start & end for default key space. Although both are ok here.
There was a problem hiding this comment.
After consideration, i think use r001 as the end is better. r001 as end can avoid some useless download and ingest during restore if target tikv cluster is not empty. I have changed the end as r001. PTAL~ @iosmanthus @pingyu
Signed-off-by: haojinming <jinming.hao@pingcap.com>
Signed-off-by: haojinming <jinming.hao@pingcap.com>
Signed-off-by: haojinming <jinming.hao@pingcap.com>
Signed-off-by: haojinming <jinming.hao@pingcap.com>
Signed-off-by: haojinming <jinming.hao@pingcap.com>
Signed-off-by: haojinming <jinming.hao@pingcap.com>
Signed-off-by: haojinming <jinming.hao@pingcap.com>
| pub const TXN_KEY_PREFIX: u8 = b'x'; | ||
| pub const TIDB_META_KEY_PREFIX: u8 = b'm'; | ||
| pub const TIDB_TABLE_KEY_PREFIX: u8 = b't'; | ||
| pub const DEFAULT_KEY_SPACE_ID: [u8; 3] = [0, 0, 0]; // reserve 3 bytes for key space id. |
There was a problem hiding this comment.
Why? I thought it should be just one byte?
There was a problem hiding this comment.
We plan to use 3 bytes fixed length to encode key space id, support more than 16 million key space. And we does not use var int encoding incase there are some issues we may miss.
|
/merge |
|
@iosmanthus: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests You only need to trigger If you have any questions about the PR merge process, please refer to pr process. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
|
This pull request has been accepted and is ready to merge. DetailsCommit hash: 16796b8 |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
|
cherry pick to release-6.1 in PR #12776 |
) close tikv#12758, ref tikv#12759 Signed-off-by: ti-srebot <ti-srebot@pingcap.com> Co-authored-by: haojinming <jinming.hao@pingcap.com> Signed-off-by: joccau <zak.zhao@pingcap.com>
Signed-off-by: haojinming jinming.hao@pingcap.com
What is changed and how it works?
Issue Number: Close #12758
What's Changed:
Add encoding of key space id in apiv2 key when backup convert.
Related changes
Check List
Tests
Side effects
Release note