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