mirror of https://github.com/tikv/client-java.git
parent
9ce52d3401
commit
aacbb8c849
|
@ -23,15 +23,15 @@ import org.tikv.kvproto.Metapb;
|
|||
import org.tikv.kvproto.Metapb.Region;
|
||||
|
||||
public class RequestKeyV2Codec implements RequestKeyCodec {
|
||||
protected static final ByteString RAW_KEY_PREFIX = ByteString.copyFromUtf8("r");
|
||||
protected static final ByteString RAW_END_KEY =
|
||||
ByteString.copyFrom(new byte[] {(byte) (RAW_KEY_PREFIX.toByteArray()[0] + 1)});
|
||||
|
||||
protected static final ByteString TXN_KEY_PREFIX = ByteString.copyFromUtf8("x");
|
||||
protected static final ByteString TXN_END_KEY =
|
||||
ByteString.copyFrom(new byte[] {(byte) (TXN_KEY_PREFIX.toByteArray()[0] + 1)});
|
||||
protected static final ByteString RAW_DEFAULT_PREFIX =
|
||||
ByteString.copyFrom(new byte[] {'r', 0, 0, 0});
|
||||
protected static final ByteString RAW_DEFAULT_END =
|
||||
ByteString.copyFrom(new byte[] {'r', 0, 0, 1});
|
||||
protected static final ByteString TXN_DEFAULT_PREFIX =
|
||||
ByteString.copyFrom(new byte[] {'x', 0, 0, 0});
|
||||
protected static final ByteString TXN_DEFAULT_END =
|
||||
ByteString.copyFrom(new byte[] {'x', 0, 0, 1});
|
||||
protected ByteString keyPrefix;
|
||||
|
||||
protected ByteString infiniteEndKey;
|
||||
|
||||
@Override
|
||||
|
@ -49,7 +49,7 @@ public class RequestKeyV2Codec implements RequestKeyCodec {
|
|||
throw new IllegalArgumentException("key corrupted, wrong prefix");
|
||||
}
|
||||
|
||||
return key.substring(1);
|
||||
return key.substring(keyPrefix.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,7 @@ public class RequestKeyV2RawCodec extends RequestKeyV2Codec {
|
|||
public RequestKeyV2RawCodec() {
|
||||
super();
|
||||
|
||||
this.keyPrefix = RAW_KEY_PREFIX;
|
||||
this.infiniteEndKey = RAW_END_KEY;
|
||||
this.keyPrefix = RAW_DEFAULT_PREFIX;
|
||||
this.infiniteEndKey = RAW_DEFAULT_END;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class RequestKeyV2TxnCodec extends RequestKeyV2Codec {
|
|||
public RequestKeyV2TxnCodec() {
|
||||
super();
|
||||
|
||||
this.keyPrefix = TXN_KEY_PREFIX;
|
||||
this.infiniteEndKey = TXN_END_KEY;
|
||||
this.keyPrefix = TXN_DEFAULT_PREFIX;
|
||||
this.infiniteEndKey = TXN_DEFAULT_END;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,9 +164,10 @@ public class RequestKeyCodecTest {
|
|||
end = ByteString.EMPTY;
|
||||
range = v2.encodeRange(start, end);
|
||||
assertEquals(v2.encodeKey(start), range.first);
|
||||
assertArrayEquals(
|
||||
new byte[] {(byte) (v2.encodeKey(ByteString.EMPTY).byteAt(0) + 1)},
|
||||
range.second.toByteArray());
|
||||
|
||||
byte[] max = v2.encodeKey(ByteString.EMPTY).toByteArray();
|
||||
max[max.length - 1] += 1;
|
||||
assertArrayEquals(max, range.second.toByteArray());
|
||||
|
||||
region =
|
||||
Region.newBuilder()
|
||||
|
|
Loading…
Reference in New Issue