-
Notifications
You must be signed in to change notification settings - Fork 135
[WIP] Add codec for encoding region for transaction client #162
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
Conversation
src/pd/client.rs
Outdated
pd: Arc<PdClient> | ||
} | ||
|
||
impl<PdC: PdClient + Send + Sync + 'static> PdClient for PdCodecClient<PdC> { |
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.
TODO: write tests
You can check the commands and outputs of CI. Note you need to use latest nightly channel to build. error[E0432]: unresolved import `crate::kv::codec::bytes`
--> tikv-client-common/src/kv/codec.rs:134:9
|
134 | use crate::kv::codec::bytes; Removing that line and Also you need to sign-off your commit. |
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.
Thanks for the PR! The rest of it looks great.
src/pd/client.rs
Outdated
@@ -266,6 +267,58 @@ impl<KvC: KvConnect + Send + Sync + 'static, Cl> PdRpcClient<KvC, Cl> { | |||
} | |||
} | |||
|
|||
/// This client wraps a PdClient and encodes/decodes keys and regions according to | |||
/// TiKV transaction codec. | |||
pub struct PdCodecClient<PdClient = PdRpcClient> { |
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 don't think we need a separate client for this, you can just add the encoding to the existing client.
tikv-client-common/src/kv/codec.rs
Outdated
use std::{io::Write, ptr}; | ||
|
||
const ENC_GROUP_SIZE: usize = 8; | ||
const ENC_MARKER: u8 = b'\xff'; |
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.
const ENC_MARKER: u8 = b'\xff'; | |
const ENC_MARKER: u8 = 0xff'; |
tikv-client-common/src/kv/key.rs
Outdated
@@ -101,6 +102,14 @@ impl Key { | |||
Bound::Excluded(self) | |||
} | |||
} | |||
|
|||
#[inline] | |||
pub fn as_encoded(&self) -> Key { |
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 think we should use the type system to differentiate between an encoded and unencoded key by adding an EncodedKey
type
tikv-client-common/src/kv/key.rs
Outdated
pub fn as_encoded(&self) -> Key { | ||
let len = codec::max_encoded_bytes_size(self.0.len()); | ||
let mut encoded = Vec::with_capacity(len); | ||
encoded.encode_bytes(self.into(), false).unwrap(); |
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.
encoded.encode_bytes(self.into(), false).unwrap(); | |
encoded.encode_bytes(self.0, false).unwrap(); |
@nrc: thanks for the quick review! Just to clarify the overarching point so I don't go down the wrong rabbit hole:
Thoughts on naming |
I don't think you need a Key trait - the idea is to prevent using an encoded key where a raw key is required and vice versa, a Key trait would circumvent that.
AIUI, encoded keys are only used with PD and we use raw keys with TiKV.
I don't think it makes sense, whether a key is encoded is orthogonal to which API it is used with. |
I made some changes:
|
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.
None
and Some(empty)
can both represent upper unbounded. I didn't comprehensively consider this change. Related to #174
@sticnarf PTAL |
07693f4
to
44c582c
Compare
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.
LGTM
Hi @georgeteo, we need you to sign off your commits to merge the PR. About the DCO check: https://github.com/probot/dco#how-it-works |
Signed-off-by: George Teo <george.c.teo@gmail.com>
Signed-off-by: George Teo <george.c.teo@gmail.com>
Signed-off-by: George Teo <george.c.teo@gmail.com>
Signed-off-by: George Teo <george.c.teo@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: longfangsong <longfangsong@icloud.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
…ehavior with TiKV Signed-off-by: ekexium <ekexium@gmail.com>
…rors Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: George Teo <george.c.teo@gmail.com>
Signed-off-by: George Teo <george.c.teo@gmail.com>
b709ed1
to
fed12b4
Compare
Signed-off-by: ekexium <ekexium@gmail.com>
In this github issue, it appears that transaction client does not encode/decode keys when querying PD.
This PR:
PdCodecClient
that wraps/decoratesPdClient
encodeskey
and decodesstart_key
andend_key
in region meta before delegating to underlyingPdClient
.PdClient
inTransactionClient
with the one that encodes/decodes keysReference Go client.
Caveat: I'm new to Rust so general Rust tips would be appreciated!
Signed-off-by: George Teo george.c.teo@gmail.com