diff --git a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDesc.java b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDesc.java index 13ec605c..9b06c0ed 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDesc.java +++ b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDesc.java @@ -216,7 +216,7 @@ public Long getPartId(Object... rowKey) { } public int getBoundsIdx(Object... rowKey) { - if (rowKey.length != rowKeyElement.size()) { + if (rowKey.length < rowKeyElement.size()) { throw new IllegalArgumentException("row key is consist of " + rowKeyElement + "but found" + Arrays.toString(rowKey)); } diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java index 4055f140..2294ed5a 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java @@ -127,17 +127,10 @@ public BatchOperationResult executeWithNormalBatchOp() throws Exception { throw new IllegalArgumentException("table name is null"); } TableBatchOps batchOps = client.batch(tableName); - boolean hasSetRowkeyElement = false; for (Object operation : operations) { if (operation instanceof Mutation) { Mutation mutation = (Mutation) operation; - if (!hasSetRowkeyElement && mutation.getRowKeyNames() != null) { - List rowKeyNames = mutation.getRowKeyNames(); - ((ObTableClient) client).addRowKeyElement(tableName, - rowKeyNames.toArray(new String[0])); - hasSetRowkeyElement = true; - } ObTableOperationType type = mutation.getOperationType(); switch (type) { case GET: @@ -200,17 +193,11 @@ public BatchOperationResult executeWithLSBatchOp() throws Exception { ObTableClientLSBatchOpsImpl batchOps; if (client instanceof ObTableClient) { batchOps = new ObTableClientLSBatchOpsImpl(tableName, (ObTableClient) client); - boolean hasSetRowkeyElement = false; for (Object operation : operations) { if (operation instanceof CheckAndInsUp) { CheckAndInsUp checkAndInsUp = (CheckAndInsUp) operation; batchOps.addOperation(checkAndInsUp); List rowKeyNames = checkAndInsUp.getInsUp().getRowKeyNames(); - if (!hasSetRowkeyElement && rowKeyNames != null) { - ((ObTableClient) client).addRowKeyElement(tableName, - rowKeyNames.toArray(new String[0])); - hasSetRowkeyElement = true; - } } else { throw new IllegalArgumentException( "The operations in batch must be all checkAndInsUp or all non-checkAndInsUp"); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Mutation.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Mutation.java index c774781e..2d3a470d 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Mutation.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Mutation.java @@ -179,12 +179,6 @@ public T setRowKey(Row rowKey) { this.rowKey = Keys.toArray(); this.rowKeyNames = columnNames; - // set row key in table - if (null != tableName) { - ((ObTableClient) client) - .addRowKeyElement(tableName, columnNames.toArray(new String[0])); - } - // renew scan range of QueryAndMutate if (null != query) { query.addScanRange(this.rowKey, this.rowKey); @@ -217,12 +211,6 @@ protected T setRowKeyOnly(Row rowKey) { this.rowKey = Keys.toArray(); this.rowKeyNames = columnNames; - // set row key in table - if (null != tableName) { - ((ObTableClient) client) - .addRowKeyElement(tableName, columnNames.toArray(new String[0])); - } - hasSetRowKey = true; return (T) this; } @@ -251,12 +239,6 @@ public T setRowKey(ColumnValue... rowKey) { this.rowKey = Keys.toArray(); this.rowKeyNames = columnNames; - // set row key in table - if (null != tableName) { - ((ObTableClient) client) - .addRowKeyElement(tableName, columnNames.toArray(new String[0])); - } - // renew scan range of QueryAndMutate if (null != query) { query.addScanRange(this.rowKey, this.rowKey); @@ -290,12 +272,6 @@ public T setRowKeyOnly(ColumnValue... rowKey) { this.rowKey = Keys.toArray(); this.rowKeyNames = columnNames; - // set row key in table - if (null != tableName) { - ((ObTableClient) client) - .addRowKeyElement(tableName, columnNames.toArray(new String[0])); - } - hasSetRowKey = true; return (T) this; } @@ -358,13 +334,7 @@ public T setScanRangeColumns(String... columnNames) throws Exception { query.setScanRangeColumns(columnNames); // set row key in table - if (null != tableName && null != client) { - if (!((ObTableClient) client).isOdpMode()) { - // TODO: adapt OCP - // OCP must conclude all rowkey now - ((ObTableClient) client).addRowKeyElement(tableName, columnNames); - } - } else { + if (null == tableName || null == client) { throw new ObTableException("invalid table name: " + tableName + ", or invalid client: " + client + " while setting scan range columns"); } diff --git a/src/test/java/com/alipay/oceanbase/rpc/ObTableCheckAndInsUpTest.java b/src/test/java/com/alipay/oceanbase/rpc/ObTableCheckAndInsUpTest.java index 9226b03e..efdedda4 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/ObTableCheckAndInsUpTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/ObTableCheckAndInsUpTest.java @@ -53,6 +53,8 @@ public void setup() throws Exception { final ObTableClient obTableClient = ObTableClientTestUtil.newTestClient(); obTableClient.init(); this.client = obTableClient; + client.addRowKeyElement(TABLE_NAME, new String[] {"c1"}); + } private boolean isVersionSupported() { @@ -230,6 +232,7 @@ public void testBatchWithReverseRowKwyColumn() throws Exception { String testTable = "test_mutation_column_reverse"; try { + client.addRowKeyElement(testTable, new String[] {"c2"}); // 1. check exists match: insup (c2, c1, c3, c4) (5, 'c2_v0', c3_v0, 100) if not exists c3 is not null; InsertOrUpdate insertOrUpdate1 = new InsertOrUpdate(); insertOrUpdate1.setRowKey(row(colVal("c2", 5L), colVal("c1", "c2_v0"))); diff --git a/src/test/java/com/alipay/oceanbase/rpc/ObTableClientCheckAndInsertTest.java b/src/test/java/com/alipay/oceanbase/rpc/ObTableClientCheckAndInsertTest.java index 374717b7..62a06c47 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/ObTableClientCheckAndInsertTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/ObTableClientCheckAndInsertTest.java @@ -68,7 +68,7 @@ public void testCheckAndInsert() throws Exception { } final String TABLE_NAME = "test_mutation"; - + ((ObTableClient) client).addRowKeyElement(TABLE_NAME, new String[] {"c1"}); TableQuery tableQuery = client.query(TABLE_NAME); tableQuery.addScanRange(new Object[] { 0L, "\0" }, new Object[] { 200L, "\254" }); tableQuery.select("c1", "c2", "c3", "c4"); diff --git a/src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java b/src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java index 581ecc18..92a821d9 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java @@ -1652,6 +1652,7 @@ public void testQueryFilterLimit() throws Exception { @Test public void testMutation() throws Exception { System.setProperty("ob_table_min_rslist_refresh_interval_millis", "1"); + ((ObTableClient) client).addRowKeyElement("test_mutation", new String[] {"c1"}); TableQuery tableQuery = client.query("test_mutation"); tableQuery.addScanRange(new Object[] { 0L, "\0" }, new Object[] { 200L, "\254" }); @@ -1908,6 +1909,7 @@ public void testMutation() throws Exception { @Test public void testPut() throws Exception { System.setProperty("ob_table_min_rslist_refresh_interval_millis", "1"); + ((ObTableClient) client).addRowKeyElement("test_mutation", new String[] {"c1"}); try { // put MutationResult insertOrUpdateResult = client.put("test_mutation") @@ -1941,7 +1943,7 @@ public void testPut() throws Exception { @Test public void testBatchMutation() throws Exception { System.setProperty("ob_table_min_rslist_refresh_interval_millis", "1"); - + ((ObTableClient) client).addRowKeyElement("test_mutation", new String[] {"c1"}); TableQuery tableQuery = client.query("test_mutation"); tableQuery.addScanRange(new Object[] { 0L, "\0" }, new Object[] { 200L, "\254" }); tableQuery.select("c1", "c2", "c3", "c4"); @@ -2221,6 +2223,7 @@ public void testMultiThreadBatchOperation() throws Exception { public void testAtomicBatchMutation() throws Exception { try { // atomic batch operation can not span partitions + ((ObTableClient) client).addRowKeyElement("test_mutation", new String[] {"c1"}); BatchOperation batchOperation = client.batchOperation("test_mutation"); Insert insert_0 = insert().setRowKey(row(colVal("c1", 100L), colVal("c2", "row_0"))) .addMutateColVal(colVal("c3", new byte[] { 1 })) @@ -2333,6 +2336,8 @@ public void testBatchInsertJudge() throws Exception { try { cleanTable("cse_index_1"); + ((ObTableClient) client).addRowKeyElement("cse_index_1", new String[] {"measurement"}); + // prepare data with insert Insert insert_0 = insert().setRowKey( row(colVal("measurement", "measurement1"), colVal("tag_key", "tag_key1"), diff --git a/src/test/java/com/alipay/oceanbase/rpc/ObTableGlobalIndexTest.java b/src/test/java/com/alipay/oceanbase/rpc/ObTableGlobalIndexTest.java index 5176bc2d..c6fe7771 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/ObTableGlobalIndexTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/ObTableGlobalIndexTest.java @@ -539,6 +539,7 @@ public void test_ttl_query_with_global_index() throws Exception { String prefixKey = "test"; long[] keyIds = { 1L, 2L }; try { + ((ObTableClient) client).addRowKeyElement(tableName, new String[] {"c1"}); // 1. insert records with null expired_ts for (long id : keyIds) { client.insert(tableName).setRowKey(colVal(rowKey1, prefixKey), colVal(rowKey2, id))