diff --git a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java index aba956b7..c4d25fc5 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java +++ b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java @@ -160,6 +160,11 @@ public class OHTable implements Table { */ private int maxKeyValueSize; + /** + * whether to enable put optimization path + */ + private boolean enablePutOptimization; + // i.e., doPut checks the writebuffer every X Puts. /** @@ -460,6 +465,8 @@ private void finishSetUp() { (this.operationTimeout != HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT)); this.maxKeyValueSize = this.configuration.getInt(MAX_KEYVALUE_SIZE_KEY, MAX_KEYVALUE_SIZE_DEFAULT); + this.enablePutOptimization = this.configuration.getBoolean(HBASE_HTABLE_USE_PUT_OPTIMIZATION, + HBASE_HTABLE_USE_PUT_OPTIMIZATION_DEFAULT); } public static OHConnectionConfiguration setUserDefinedNamespace(String tableNameString, @@ -793,7 +800,7 @@ private void innerBatchImpl(final List actions, final Object[] re } catch (Exception e) { throw new IOException(tableNameString + " table occurred unexpected error." , e); } - } else if (OHBaseFuncUtils.isAllPut(opType, actions) && OHBaseFuncUtils.isHBasePutPefSupport(obTableClient)) { + } else if (OHBaseFuncUtils.isAllPut(opType, actions) && OHBaseFuncUtils.isHBasePutPefSupport(obTableClient, enablePutOptimization)) { // only support Put now ObHbaseRequest request = buildHbaseRequest(actions, opType); try { @@ -1357,7 +1364,7 @@ private void doPut(List puts, OHOperationType opType) throws IOException { validatePut(put); checkFamilyViolation(put.getFamilyCellMap().keySet(), true); } - if (OHBaseFuncUtils.isHBasePutPefSupport(obTableClient)) { + if (OHBaseFuncUtils.isHBasePutPefSupport(obTableClient, enablePutOptimization)) { flushCommitsV2(puts, opType); } else { flushCommits(puts, opType); diff --git a/src/main/java/com/alipay/oceanbase/hbase/constants/OHConstants.java b/src/main/java/com/alipay/oceanbase/hbase/constants/OHConstants.java index eb9123a5..1dc6ec04 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/constants/OHConstants.java +++ b/src/main/java/com/alipay/oceanbase/hbase/constants/OHConstants.java @@ -160,6 +160,13 @@ public final class OHConstants { * Default is false (disabled). */ public static final String HBASE_HTABLE_AUTO_FILL_TIMESTAMP_IN_CLIENT = "hbase.htable.auto.fill.timestamp.in.client"; + + /** + * use to specify whether to enable put optimization path. + * Default is true (enabled). + */ + public static final String HBASE_HTABLE_USE_PUT_OPTIMIZATION = "hbase.htable.use.put.optimization"; + /*-------------------------------------------------------------------------------------------------------------*/ /** @@ -191,4 +198,6 @@ public final class OHConstants { public static final int DEFAULT_SOCKET_TIMEOUT = 20000; // 20 seconds + public static final boolean HBASE_HTABLE_USE_PUT_OPTIMIZATION_DEFAULT = true; + } 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 bda8e9a8..eee513db 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/util/OHBaseFuncUtils.java +++ b/src/main/java/com/alipay/oceanbase/hbase/util/OHBaseFuncUtils.java @@ -52,7 +52,12 @@ public static byte[][] extractFamilyFromQualifier(byte[] qualifier) throws Excep return new byte[][] { family, newQualifier }; } - public static boolean isHBasePutPefSupport(ObTableClient tableClient) { + public static boolean isHBasePutPefSupport(ObTableClient tableClient, boolean enablePutOptimization) { + // If client-side optimization is disabled, return false directly + if (!enablePutOptimization) { + return false; + } + if (tableClient.isOdpMode()) { // server version support and distributed capacity is enabled and odp version support return ObGlobal.isHBasePutPerfSupport() diff --git a/src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableFillTimestampInClientTest.java b/src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableFillTimestampInClientTest.java index 9ccbf78a..8c1bf9d7 100644 --- a/src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableFillTimestampInClientTest.java +++ b/src/test/java/com/alipay/oceanbase/hbase/secondary/OHTableFillTimestampInClientTest.java @@ -53,11 +53,6 @@ public static void finish() throws Exception { dropTable(); } - @Before - public void prepareCase() throws Exception { - truncateTable(); - } - /** * Create dynamic partition table for testing */