@@ -24,24 +24,42 @@ use tikv_client_store::{KvClient, KvConnect, Store, TikvConnect};
24
24
const CQ_COUNT : usize = 1 ;
25
25
const CLIENT_PREFIX : & str = "tikv-client" ;
26
26
27
+ // The PdClient handles all the encoding stuff.
28
+ //
29
+ // Raw APIs does not require encoding/decoding at all.
30
+ // All keys in all places (client, PD, TiKV) are in the same encoding (here called "raw format").
31
+ //
32
+ // Transactional APIs are a bit complicated.
33
+ // We need encode and decode keys when we communicate with PD, but not with TiKV.
34
+ // We encode keys before sending requests to PD, and decode keys in the response from PD.
35
+ // That's all we need to do with encoding.
36
+ //
37
+ // client -encoded-> PD, PD -encoded-> client
38
+ // client -raw-> TiKV, TiKV -raw-> client
39
+ //
40
+ // The reason for the behavior is that in transaction mode, TiKV encode keys for MVCC.
41
+ // In raw mode, TiKV doesn't encode them.
42
+ // TiKV tells PD using its internal representation, whatever the encoding is.
43
+ // So if we use transactional APIs, keys in PD are encoded and PD does not know about the encoding stuff.
44
+ //
27
45
pub trait PdClient : Send + Sync + ' static {
28
46
type KvClient : KvClient + Send + Sync + ' static ;
29
47
30
- // raw region
48
+ // In transactional API, ` region` is decoded (keys in raw format).
31
49
fn map_region_to_store (
32
50
self : Arc < Self > ,
33
51
region : Region ,
34
52
) -> BoxFuture < ' static , Result < Store < Self :: KvClient > > > ;
35
53
36
- // raw region for raw key
54
+ // In transactional API, the key and returned region are both decoded (keys in raw format).
37
55
fn region_for_key ( & self , key : & Key ) -> BoxFuture < ' static , Result < Region > > ;
38
56
39
- // raw region for id
57
+ // In transactional API, the returned region is decoded (keys in raw format)
40
58
fn region_for_id ( & self , id : RegionId ) -> BoxFuture < ' static , Result < Region > > ;
41
59
42
60
fn get_timestamp ( self : Arc < Self > ) -> BoxFuture < ' static , Result < Timestamp > > ;
43
61
44
- // store for raw key
62
+ // In transactional API, ` key` is in raw format
45
63
fn store_for_key (
46
64
self : Arc < Self > ,
47
65
key : & Key ,
0 commit comments