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
4 changes: 2 additions & 2 deletions src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2258,8 +2258,8 @@ public ObPayload execute(final ObHbaseRequest request) throws Exception {
String realTableName = request.getCfRows().get(0).getRealTableName();
int keyIdx = request.getCfRows().get(0).getKeyIndex(0);
row.add("K", request.getKeys().get(keyIdx).getValue());
row.add("Q", request.getCfRows().get(0).getCells().get(0).getQ().getValue());
row.add("T", request.getCfRows().get(0).getCells().get(0).getT().getValue());
row.add("Q", request.getCfRows().get(0).getFirstCellQualifierValue());
row.add("T", request.getCfRows().get(0).getFirstCellTimestampValue());
return execute(realTableName,
new OperationExecuteCallback<ObPayload>(row, null) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
import com.alipay.oceanbase.rpc.exception.*;
import com.alipay.oceanbase.rpc.protocol.packet.ObCompressType;
import com.alipay.oceanbase.rpc.protocol.payload.*;
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.OHOperationType;
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.ObTableEntityType;
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.ObTableLSOpRequest;
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.ObTableLSOpResult;
import com.alipay.oceanbase.rpc.protocol.payload.impl.login.ObTableLoginRequest;
import com.alipay.oceanbase.rpc.util.ObPureCrc32C;
import com.alipay.oceanbase.rpc.util.TableClientLoggerFactory;
import com.alipay.oceanbase.rpc.util.TraceUtil;
import com.alipay.remoting.*;
Expand Down Expand Up @@ -102,17 +105,6 @@ public ObPayload invokeSync(final ObTableConnection conn, final ObPayload reques
throw new FeatureNotSupportedException(errMessage);
}
ByteBuf buf = response.getPacketContentBuf();
// verify checksum
long expected_checksum = response.getHeader().getChecksum();
byte[] content = new byte[buf.readableBytes()];
buf.getBytes(buf.readerIndex(), content);
if (ObPureCrc32C.calculate(content) != expected_checksum) {
String errMessage = TraceUtil.formatTraceMessage(conn, request,
"get response with checksum error: " + response.getMessage());
ExceptionUtil.throwObTableTransportException(errMessage,
TransportCodes.BOLT_CHECKSUM_ERR);
return null;
}

// decode ResultCode for response packet
boolean isRoutingWrong = false;
Expand Down Expand Up @@ -165,6 +157,14 @@ public ObPayload invokeSync(final ObTableConnection conn, final ObPayload reques
"receive unexpected command code: " + response.getCmdCode().value());
throw new ObTableUnexpectedException(errMessage, resultCode.getRcode());
}
if (payload instanceof ObTableLSOpResult && request instanceof ObTableLSOpRequest) {
ObTableLSOpRequest lsRequest = (ObTableLSOpRequest) request;
OHOperationType hbaseOpType = lsRequest.getHbaseOpType();
boolean eligibleHBaseBatchGet = lsRequest.getEntityType() == ObTableEntityType.HKV
&& (hbaseOpType == OHOperationType.GET_LIST
|| hbaseOpType == OHOperationType.BATCH);
((ObTableLSOpResult) payload).setDecodeHBaseKqtv(eligibleHBaseBatchGet);
}
try {
payload.decode(buf);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public class ObObj implements ObSimplePayload {
private static long MAX_OBJECT_VALUE = -2L;
private static long MIN_OBJECT_VALUE = -3L;

/** Cached meta for HBase Put V2 hot path (Q/V rowkey bytes or slice view). */
private static final ObObjMeta HBASE_PUT_VARCHAR_META = ObObjType.ObVarcharType
.getDefaultObjMeta();
/** Cached meta for HBase Put V2 timestamp / TTL (signed int64). */
private static final ObObjMeta HBASE_PUT_INT64_META = ObObjType.ObInt64Type
.getDefaultObjMeta();

static {
MAX_OBJECT = new ObObj(ObObjType.ObExtendType.getDefaultObjMeta(), MAX_OBJECT_VALUE);
MIN_OBJECT = new ObObj(ObObjType.ObExtendType.getDefaultObjMeta(), MIN_OBJECT_VALUE);
Expand Down Expand Up @@ -166,6 +173,20 @@ public static ObObj getInstance(Object value) {
}
}

/**
* HBase Put V2 Q/V/rowkey: skip {@link ObObjType#defaultObjMeta(Object)} dispatch.
*/
public static ObObj hbasePutVarchar(Object value) {
return new ObObj(HBASE_PUT_VARCHAR_META, value);
}

/**
* HBase Put V2 timestamp / cell TTL: skip meta lookup; value autoboxes once to Long.
*/
public static ObObj hbasePutInt64(long value) {
return new ObObj(HBASE_PUT_INT64_META, value);
}

/*
* Get max.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,9 @@ public Comparable parseToComparable(Object o, ObCollationType ct)
*/
@Override
public byte[] encode(Object obj) {
if (obj instanceof byte[]) {
if (obj instanceof ObBytesString) {
return Serialization.encodeBytesString((ObBytesString) obj);
} else if (obj instanceof byte[]) {
ObBytesString bytesString = new ObBytesString((byte[]) obj);
return Serialization.encodeBytesString(bytesString);
} else if (obj instanceof ObVString) {
Expand All @@ -1282,7 +1284,9 @@ public byte[] encode(Object obj) {

@Override
public void encode(ObByteBuf buf, Object obj) {
if (obj instanceof byte[]) {
if (obj instanceof ObBytesString) {
Serialization.encodeBytesString(buf, (ObBytesString) obj);
} else if (obj instanceof byte[]) {
ObBytesString bytesString = new ObBytesString((byte[]) obj);
Serialization.encodeBytesString(buf, bytesString);
} else if (obj instanceof ObVString) {
Expand Down Expand Up @@ -1976,15 +1980,27 @@ public Date parseToComparable(Object o, ObCollationType ct)
*/

private int value;
private static Map<Integer, ObObjType> map = new HashMap<Integer, ObObjType>();
// Object types encoded as i8 use the array fast path; extended type ids use the map.
private static final ObObjType[] VALUE_LOOKUP = new ObObjType[128];
private static final Map<Integer, ObObjType> EXTENDED_VALUE_LOOKUP = new HashMap<Integer, ObObjType>();

ObObjType(int value) {
this.value = value;
}

static {
for (ObObjType type : ObObjType.values()) {
map.put(type.value, type);
int value = type.value;
if (value < 0) {
throw new IllegalStateException("ObObjType value must not be negative: " + value);
} else if (value < VALUE_LOOKUP.length) {
if (VALUE_LOOKUP[value] != null) {
throw new IllegalStateException("duplicate ObObjType value: " + value);
}
VALUE_LOOKUP[value] = type;
} else if (EXTENDED_VALUE_LOOKUP.put(value, type) != null) {
throw new IllegalStateException("duplicate ObObjType value: " + value);
}
}
}

Expand Down Expand Up @@ -2016,6 +2032,8 @@ public static ObObjType valueOfType(Object object) {
return ObVarcharType;
} else if (object instanceof byte[]) {
return ObVarcharType;
} else if (object instanceof ObBytesString) {
return ObVarcharType;
} else if (object instanceof ObVString) {
return ObVarcharType;
} else if (object instanceof Double) {
Expand All @@ -2039,7 +2057,11 @@ public static ObObjType valueOfType(Object object) {
* Value of.
*/
public static ObObjType valueOf(int value) {
return map.get(value);
if (value < 0) {
return null;
}
return value < VALUE_LOOKUP.length ? VALUE_LOOKUP[value] : EXTENDED_VALUE_LOOKUP
.get(value);
}

/*
Expand Down Expand Up @@ -2113,7 +2135,9 @@ public Object decodeText(ByteBuf buf, ObCollationType type) {
* Get text encoded size.
*/
public static int getTextEncodedSize(Object obj) {
if (obj instanceof byte[]) {
if (obj instanceof ObBytesString) {
return Serialization.getNeedBytes((ObBytesString) obj);
} else if (obj instanceof byte[]) {
ObBytesString bytesString = new ObBytesString((byte[]) obj);
return Serialization.getNeedBytes(bytesString);
} else if (obj instanceof ObVString) {
Expand All @@ -2130,7 +2154,7 @@ public static byte[] parseTextToBytes(ObObjType obObjType, Object object,
ObCollationType collationType) {
if (collationType == ObCollationType.CS_TYPE_BINARY) {
if (object instanceof ObBytesString) {
return ((ObBytesString) object).bytes;
return materializeBytesString((ObBytesString) object);
}

if (object instanceof byte[]) {
Expand All @@ -2150,7 +2174,8 @@ public static byte[] parseTextToBytes(ObObjType obObjType, Object object,
return ((String) object).getBytes();
}
if (object instanceof ObBytesString) {
return (Serialization.decodeVString(((ObBytesString) object).bytes)).getBytes();
return Serialization.decodeVString(materializeBytesString((ObBytesString) object))
.getBytes();
}

if (object instanceof byte[]) {
Expand Down Expand Up @@ -2201,7 +2226,7 @@ public static Comparable parseTextToComparable(ObObjType obObjType, Object objec
return (String) object;
}
if (object instanceof ObBytesString) {
return Serialization.decodeVString(((ObBytesString) object).bytes);
return Serialization.decodeVString(materializeBytesString((ObBytesString) object));
}

if (object instanceof byte[]) {
Expand All @@ -2224,6 +2249,14 @@ public static Comparable parseTextToComparable(ObObjType obObjType, Object objec
+ object);
}

private static byte[] materializeBytesString(ObBytesString bytesString) {
if (bytesString.offset == 0 && bytesString.length() == bytesString.bytes.length) {
return bytesString.bytes;
}
return Arrays.copyOfRange(bytesString.bytes, bytesString.offset,
bytesString.offset + bytesString.length());
}

/*
* Parse timestamp.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ public void decode(ByteBuf buf, ObObj obj) {
ObTableInvalidType(26) {
};

private static final int LOOKUP_SIZE = 128;
private int value;
// mapping from value to enum
private static Map<Integer, ObTableObjType> valueMap = new HashMap<Integer, ObTableObjType>();
// Keep current low ids on the fast path; reserve a map for future ids outside the array.
private static final ObTableObjType[] VALUE_LOOKUP = new ObTableObjType[LOOKUP_SIZE];
private static final Map<Integer, ObTableObjType> OVERFLOW_VALUE_LOOKUP = new HashMap<>();
// mapping from ObTableObjType to ObObjType
private static Map<ObTableObjType, ObObjType> tableObjTypeMap = new HashMap<>();

Expand All @@ -214,7 +216,21 @@ public void decode(ByteBuf buf, ObObj obj) {

static {
for (ObTableObjType type : ObTableObjType.values()) {
valueMap.put(type.value, type);
registerLookup(type.value, type);
}
}

private static void registerLookup(int value, ObTableObjType type) {
if (value < 0) {
throw new IllegalStateException("Invalid table object type id: " + value);
}
if (value < VALUE_LOOKUP.length) {
if (VALUE_LOOKUP[value] != null) {
throw new IllegalStateException("Duplicate table object type id: " + value);
}
VALUE_LOOKUP[value] = type;
} else if (OVERFLOW_VALUE_LOOKUP.put(value, type) != null) {
throw new IllegalStateException("Duplicate table object type id: " + value);
}
}

Expand Down Expand Up @@ -298,7 +314,11 @@ public static ObObjType getObjType(ObTableObjType tableObjType) {
* Value of.
*/
public static ObTableObjType valueOf(int value) {
return valueMap.get(value);
if (value < 0) {
return null;
}
return value < VALUE_LOOKUP.length ? VALUE_LOOKUP[value]
: OVERFLOW_VALUE_LOOKUP.get(value);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static ObTableObjType decodeTableObjType(ByteBuf buf) {
if (buf == null) {
throw new IllegalArgumentException("cannot get ObTableObjType, buf is null");
}
byte type = Serialization.decodeI8(buf);
int type = Serialization.decodeI8(buf) & 0xFF;
ObTableObjType objType = ObTableObjType.valueOf(type);
if (objType == null) {
throw new IllegalArgumentException("cannot get table object type from value, type: " + type);
Expand Down
Loading
Loading