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
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ public int getBoundsIdx(Object... rowKey) {
ObPartitionKey searchKey = ObPartitionKey.getInstance(orderedCompareColumns,
comparableElement);

int pos = upperBound(this.bounds, new ObComparableKV<ObPartitionKey, Long>(searchKey, (long) -1));
int pos = upperBound(this.bounds, new ObComparableKV<ObPartitionKey, Long>(searchKey,
(long) -1));
if (pos >= this.bounds.size()) {
throw new ArrayIndexOutOfBoundsException("Table has no partition for value in " + this.getPartExpr());
throw new ArrayIndexOutOfBoundsException("Table has no partition for value in "
+ this.getPartExpr());
} else {
return pos;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

package com.alipay.oceanbase.rpc.protocol.payload.impl.execute;

import java.util.HashMap;
import java.util.Map;
import java.util.*;

public enum ObTableOperationType {

Expand All @@ -32,7 +31,20 @@ public enum ObTableOperationType {
CHECK_AND_INSERT_UP(10), INVALID(11);

private int value;
private static Map<Integer, ObTableOperationType> map = new HashMap<Integer, ObTableOperationType>();
private static Map<Integer, ObTableOperationType> map = new HashMap<Integer, ObTableOperationType>();
private static final List<Boolean> needEncodeQuery = Arrays.asList(false, // GET
false, // INSERT
false, // DEL
false, // UPDATE
false, // INSERT_OR_UPDATE
false, // REPLACE
false, // INCREMENT
false, // APPEND
false, // SCAN
false, // TTL
true, // CHECK_AND_INSERT_UP
false // INVALID
);

ObTableOperationType(int value) {
this.value = value;
Expand Down Expand Up @@ -71,4 +83,8 @@ public byte getByteValue() {
public boolean isReadonly() {
return this.value == GET.value;
}

public static boolean needEncodeQuery(ObTableOperationType type) {
return needEncodeQuery.get(type.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ public byte[] encode() {
idx += len;

// 3. encode single op query
len = (int) query.getPayloadSize();
System.arraycopy(query.encode(), 0, bytes, idx, len);
idx += len;
if (ObTableOperationType.needEncodeQuery(singleOpType)) {
len = (int) query.getPayloadSize();
System.arraycopy(query.encode(), 0, bytes, idx, len);
idx += len;
}

// 4. encode entities
len = Serialization.getNeedBytes(entities.size());
Expand All @@ -80,7 +82,9 @@ public Object decode(ByteBuf buf) {

this.singleOpType = ObTableOperationType.valueOf(Serialization.decodeI8(buf.readByte()));
this.singleOpFlag.setValue(Serialization.decodeVi64(buf));
this.query.decode(buf);
if (ObTableOperationType.needEncodeQuery(this.singleOpType)) {
this.query.decode(buf);
}
int len = (int) Serialization.decodeVi64(buf);
for (int i = 0; i < len; i++) {
ObTableSingleOpEntity entity = new ObTableSingleOpEntity();
Expand All @@ -96,10 +100,11 @@ public Object decode(ByteBuf buf) {
*/
@Override
public long getPayloadContentSize() {

long payloadContentSize = Serialization.getNeedBytes(singleOpType.getByteValue());
payloadContentSize += Serialization.getNeedBytes(singleOpFlag.getValue());
payloadContentSize += query.getPayloadSize();
if (ObTableOperationType.needEncodeQuery(singleOpType)) {
payloadContentSize += query.getPayloadSize();
}
payloadContentSize += Serialization.getNeedBytes(entities.size());
for (ObTableSingleOpEntity entity : entities) {
payloadContentSize += entity.getPayloadSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public void testNotInAnyPartition() throws Exception {
// 1651334400000L -> 2022-05-01 00:00:00 (GMT +8)
Date date = new Date(1651334400000L);
long affectedRows = obTableClient.insert(testTable, new Object[] { date, date },
new String[] { "c2" }, new Object[] {"value"});
new String[] { "c2" }, new Object[] { "value" });
Assert.assertTrue("Insert should fail since no partition could be inserted", false);
} catch (IndexOutOfBoundsException e) {
// do nothing
Expand Down