Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/java/org/tikv/common/apiversion/RequestKeyV2Codec.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
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
Expand All @@ -49,7 +49,7 @@ public ByteString decodeKey(ByteString key) {
throw new IllegalArgumentException("key corrupted, wrong prefix");
}

return key.substring(1);
return key.substring(keyPrefix.size());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ void testV2Codec(RequestKeyV2Codec v2) {
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()
Expand Down