Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove addRowkeyElement in mutation op #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> rowKeyNames = mutation.getRowKeyNames();
((ObTableClient) client).addRowKeyElement(tableName,
rowKeyNames.toArray(new String[0]));
hasSetRowkeyElement = true;
}
ObTableOperationType type = mutation.getOperationType();
switch (type) {
case GET:
Expand Down Expand Up @@ -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<String> 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");
Expand Down
32 changes: 1 addition & 31 deletions src/main/java/com/alipay/oceanbase/rpc/mutation/Mutation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 }))
Expand Down Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading