-
Notifications
You must be signed in to change notification settings - Fork 117
[to #555] enable api v2 #575
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
Changes from 1 commit
1c97d49
0d485f2
f45d583
8ff27f2
7bb666b
790ffd2
c5e502e
8a11a88
ec2d127
9b0363c
f9f4cfe
e5ff7e0
3e63dc4
e44dee7
04fa138
66d07c4
153ec6f
6771d13
b7c54f8
72eb371
8443588
62879c6
edbb9f5
8b22d77
34a81a0
a72a6cf
de87cbb
6d43080
ef71788
d252888
fec799c
0a64f84
cedc40d
afd5858
7c02154
0e0bd46
1db88aa
629d4fa
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 |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| import org.slf4j.LoggerFactory; | ||
| import org.tikv.common.AbstractGRPCClient; | ||
| import org.tikv.common.TiConfiguration; | ||
| import org.tikv.common.TiConfiguration.KVMode; | ||
| import org.tikv.common.exception.GrpcException; | ||
| import org.tikv.common.log.SlowLog; | ||
| import org.tikv.common.log.SlowLogSpan; | ||
|
|
@@ -155,6 +156,42 @@ public boolean onStoreUnreachable(BackOffer backOffer) { | |
| return false; | ||
| } | ||
|
|
||
| public ByteString buildRequestKey(ByteString key) { | ||
| switch (conf.getApiVersion()) { | ||
|
Member
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 get the cluster version and tikv configuration from PD? so that we don't need to add one more config in the java client and the java client can automatically adjust the encode/decode methods according to the cluster it is connected to.
Member
Author
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. By design, the client should not read the TiKV configuration from PD or themself. Because:
|
||
| case V1: | ||
| return key; | ||
| case V2: | ||
| if (conf.getKvMode() == KVMode.RAW) { | ||
| return ByteString.copyFromUtf8(TiConfiguration.API_V2_RAW_PREFIX).concat(key); | ||
| } else if (conf.getKvMode() == KVMode.TXN) { | ||
| return ByteString.copyFromUtf8(TiConfiguration.API_V2_TXN_PREFIX).concat(key); | ||
| } | ||
| default: | ||
| throw new IllegalArgumentException("unknown api version or kv mode"); | ||
| } | ||
| } | ||
|
|
||
| public ByteString unwrapResponseKey(ByteString key) { | ||
| switch (conf.getApiVersion()) { | ||
| case V1: | ||
| return key; | ||
| case V2: | ||
| if (conf.getKvMode() == KVMode.RAW) { | ||
| if (!key.startsWith(ByteString.copyFromUtf8(TiConfiguration.API_V2_RAW_PREFIX))) { | ||
| throw new IllegalArgumentException("key corrupted, wrong prefix"); | ||
| } | ||
| return key.substring(1); | ||
| } else if (conf.getKvMode() == KVMode.TXN) { | ||
| if (!key.startsWith(ByteString.copyFromUtf8(TiConfiguration.API_V2_TXN_PREFIX))) { | ||
| throw new IllegalArgumentException("key corrupted, wrong prefix"); | ||
| } | ||
| return key.substring(1); | ||
| } | ||
| default: | ||
| throw new IllegalArgumentException("unknown api version or kv mode"); | ||
| } | ||
| } | ||
|
|
||
| private Kvrpcpb.Context addTraceId(Kvrpcpb.Context context, SlowLog slowLog) { | ||
| if (slowLog.getThresholdMS() < 0) { | ||
| // disable tikv tracing | ||
|
|
||
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.
there is a redundant semicolon.