Skip to content

Commit 2dbc8d0

Browse files
committed
fix incrment invalid value throws different exception from original hbase
1 parent cf09ce6 commit 2dbc8d0

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.alipay.oceanbase.rpc.mutation.result.BatchOperationResult;
3333
import com.alipay.oceanbase.rpc.mutation.result.MutationResult;
3434
import com.alipay.oceanbase.rpc.protocol.payload.ObPayload;
35+
import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes;
3536
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
3637
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObRowKey;
3738
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.*;
@@ -1429,7 +1430,13 @@ public Result increment(Increment increment) throws IOException {
14291430
return new Result(keyValues);
14301431
} catch (Exception e) {
14311432
logger.error(LCD.convert("01-00007"), tableNameString, e);
1432-
throw new IOException("increment table " + tableNameString + " error.", e);
1433+
if (e instanceof ObTableException &&
1434+
((ObTableException) e).getErrorCode() == ResultCodes.OB_KV_HBASE_INCR_FIELD_IS_NOT_LONG.errorCode) {
1435+
String errMsg = OHBaseFuncUtils.generateIncrFieldErrMsg(e.getMessage());
1436+
throw new DoNotRetryIOException(errMsg, e);
1437+
} else {
1438+
throw new IOException("increment table " + tableNameString + " error.", e);
1439+
}
14331440
}
14341441
}
14351442

@@ -1473,7 +1480,13 @@ public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, lo
14731480
return Bytes.toLong((byte[]) queryResult.getPropertiesRows().get(0).get(3).getValue());
14741481
} catch (Exception e) {
14751482
logger.error(LCD.convert("01-00007"), tableNameString, e);
1476-
throw new IOException("increment table " + tableNameString + " error.", e);
1483+
if (e instanceof ObTableException
1484+
&& ((ObTableException) e).getErrorCode() == ResultCodes.OB_KV_HBASE_INCR_FIELD_IS_NOT_LONG.errorCode) {
1485+
String errMsg = OHBaseFuncUtils.generateIncrFieldErrMsg(e.getMessage());
1486+
throw new DoNotRetryIOException(errMsg, e);
1487+
} else {
1488+
throw new IOException("increment table " + tableNameString + " error.", e);
1489+
}
14771490
}
14781491
}
14791492

src/main/java/com/alipay/oceanbase/hbase/util/OHBaseFuncUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import java.util.Arrays;
2323

24+
import static java.lang.String.format;
25+
2426
@InterfaceAudience.Private
2527
public class OHBaseFuncUtils {
2628
public static byte[][] extractFamilyFromQualifier(byte[] qualifier) throws Exception {
@@ -38,4 +40,13 @@ public static byte[][] extractFamilyFromQualifier(byte[] qualifier) throws Excep
3840
byte[] newQualifier = Arrays.copyOfRange(qualifier, familyLen + 1, qualifier.length);
3941
return new byte[][] { family, newQualifier };
4042
}
43+
44+
public static String generateIncrFieldErrMsg(String errMsg) {
45+
// [-10516][OB_KV_HBASE_INCR_FIELD_IS_NOT_LONG][When invoking the Increment interface, only HBase cells with a length of 8 can be converted to int64_t. the current length of the HBase cell is '4'.][ip:port][trace_id]
46+
int start = errMsg.indexOf('\'');
47+
int stop = errMsg.lastIndexOf('\'');
48+
String errByte = errMsg.substring(start + 1, stop);
49+
errMsg = format("Field is not a long, it's %s bytes wide", errByte);
50+
return errMsg;
51+
}
4152
}

0 commit comments

Comments
 (0)