From 7621ba3abd5779bcf9fd7d88a3910c38678b78a3 Mon Sep 17 00:00:00 2001 From: JackShi148 Date: Fri, 28 Mar 2025 16:16:13 +0800 Subject: [PATCH] fix incrment invalid value throws different exception from original hbase --- .../com/alipay/oceanbase/hbase/OHTable.java | 17 +++++++++++++++-- .../oceanbase/hbase/util/OHBaseFuncUtils.java | 11 +++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java index 2aecad25..f00a65b0 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java +++ b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java @@ -32,6 +32,7 @@ import com.alipay.oceanbase.rpc.mutation.result.BatchOperationResult; import com.alipay.oceanbase.rpc.mutation.result.MutationResult; import com.alipay.oceanbase.rpc.protocol.payload.ObPayload; +import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes; import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj; import com.alipay.oceanbase.rpc.protocol.payload.impl.ObRowKey; import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.*; @@ -1531,7 +1532,13 @@ public Result increment(Increment increment) throws IOException { return Result.create(keyValues); } catch (Exception e) { logger.error(LCD.convert("01-00007"), tableNameString, e); - throw new IOException("increment table " + tableNameString + " error.", e); + if (e instanceof ObTableException && + ((ObTableException) e).getErrorCode() == ResultCodes.OB_KV_HBASE_INCR_FIELD_IS_NOT_LONG.errorCode) { + String errMsg = OHBaseFuncUtils.generateIncrFieldErrMsg(e.getMessage()); + throw new DoNotRetryIOException(errMsg, e); + } else { + throw new IOException("increment table " + tableNameString + " error.", e); + } } } @@ -1575,7 +1582,13 @@ public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, lo return Bytes.toLong((byte[]) queryResult.getPropertiesRows().get(0).get(3).getValue()); } catch (Exception e) { logger.error(LCD.convert("01-00007"), tableNameString, e); - throw new IOException("increment table " + tableNameString + " error.", e); + if (e instanceof ObTableException + && ((ObTableException) e).getErrorCode() == ResultCodes.OB_KV_HBASE_INCR_FIELD_IS_NOT_LONG.errorCode) { + String errMsg = OHBaseFuncUtils.generateIncrFieldErrMsg(e.getMessage()); + throw new DoNotRetryIOException(errMsg, e); + } else { + throw new IOException("increment table " + tableNameString + " error.", e); + } } } diff --git a/src/main/java/com/alipay/oceanbase/hbase/util/OHBaseFuncUtils.java b/src/main/java/com/alipay/oceanbase/hbase/util/OHBaseFuncUtils.java index 9932f554..b9fe0069 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/util/OHBaseFuncUtils.java +++ b/src/main/java/com/alipay/oceanbase/hbase/util/OHBaseFuncUtils.java @@ -21,6 +21,8 @@ import java.util.Arrays; +import static java.lang.String.format; + @InterfaceAudience.Private public class OHBaseFuncUtils { public static byte[][] extractFamilyFromQualifier(byte[] qualifier) throws Exception { @@ -42,4 +44,13 @@ public static byte[][] extractFamilyFromQualifier(byte[] qualifier) throws Excep byte[] newQualifier = Arrays.copyOfRange(qualifier, familyLen + 1, qualifier.length); return new byte[][] { family, newQualifier }; } + + public static String generateIncrFieldErrMsg(String errMsg) { + // [-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] + int start = errMsg.indexOf('\''); + int stop = errMsg.lastIndexOf('\''); + String errByte = errMsg.substring(start + 1, stop); + errMsg = format("Field is not a long, it's %s bytes wide", errByte); + return errMsg; + } }