Skip to content

Commit 79927b6

Browse files
authored
Merge pull request #155 from oceanbase/fix_checkandmutate_dif_row
Compatbile to original hbase checkandmutate different row operations
2 parents d4e53e4 + 0481e83 commit 79927b6

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,8 +1324,6 @@ private boolean checkAndMutation(byte[] row, byte[] family, byte[] qualifier,
13241324
RowMutations rowMutations) throws Exception {
13251325
checkArgument(row != null, "row is null");
13261326
checkArgument(isNotBlank(Bytes.toString(family)), "family is blank");
1327-
checkArgument(Bytes.equals(row, rowMutations.getRow()),
1328-
"mutation row is not equal check row");
13291327
checkArgument(!rowMutations.getMutations().isEmpty(), "mutation is empty");
13301328
List<Mutation> mutations = rowMutations.getMutations();
13311329
// only one family operation is allowed

src/test/java/com/alipay/oceanbase/hbase/HTableTestBase.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4761,7 +4761,7 @@ public void testDeleteIllegal() throws IOException {
47614761

47624762
@Test
47634763
public void testCheckAndMutationIllegal() throws IOException {
4764-
// check and mute 只支持一行操作
4764+
// checkAndPut 只支持一行操作
47654765
try {
47664766
Put put = new Put("key_7".getBytes());
47674767
put.add("family1".getBytes(), "column1_1".getBytes(), "value2".getBytes());
@@ -4772,20 +4772,6 @@ public void testCheckAndMutationIllegal() throws IOException {
47724772
Assert.assertTrue(e.getMessage().contains("doesn't match the original one"));
47734773
}
47744774

4775-
// check and mute 只支持一行操作
4776-
try {
4777-
RowMutations mutations = new RowMutations("key_7".getBytes());
4778-
Put put = new Put("key_7".getBytes());
4779-
put.add("family1".getBytes(), "column1_1".getBytes(), "value2".getBytes());
4780-
mutations.add(put);
4781-
boolean ret = hTable.checkAndMutate("key_8".getBytes(), "family1".getBytes(),
4782-
"column1_1".getBytes(), CompareFilter.CompareOp.EQUAL, "value1".getBytes(),
4783-
mutations);
4784-
fail();
4785-
} catch (IOException e) {
4786-
Assert.assertTrue(e.getMessage().contains("mutation row is not equal check row error"));
4787-
}
4788-
47894775
try {
47904776
Put put = new Put("key_8".getBytes());
47914777
put.add("family2".getBytes(), "column1_1".getBytes(), "value2".getBytes());
@@ -4942,6 +4928,7 @@ public void testCheckAndDelete() throws IOException {
49424928
public void testCheckAndMutate() throws IOException {
49434929
// Mutate 只支持操作一行数据
49444930
String key = "checkAndMutateKey";
4931+
String key1 = "checkAndMutateKey1";
49454932
String column1 = "checkAndMutateColumn";
49464933
String column2 = "checkAndMutateColumn2";
49474934
String value1 = "value1";
@@ -5080,6 +5067,36 @@ public void testCheckAndMutate() throws IOException {
50805067
get.setMaxVersions(Integer.MAX_VALUE);
50815068
r = hTable.get(get);
50825069
Assert.assertEquals(10, r.raw().length);
5070+
5071+
// test different row operations
5072+
put1 = new Put(key1.getBytes());
5073+
put1.add(family.getBytes(), column1.getBytes(), t, value1.getBytes());
5074+
put1.add(family.getBytes(), column2.getBytes(), t, value2.getBytes());
5075+
5076+
put2 = new Put(key1.getBytes());
5077+
put2.add(family.getBytes(), column1.getBytes(), t + 3, value2.getBytes());
5078+
put2.add(family.getBytes(), column2.getBytes(), t + 3, value1.getBytes());
5079+
5080+
put3 = new Put(key1.getBytes());
5081+
put3.add(family.getBytes(), column1.getBytes(), t + 5, value1.getBytes());
5082+
put3.add(family.getBytes(), column2.getBytes(), t + 5, value2.getBytes());
5083+
5084+
rowMutations = new RowMutations(key1.getBytes());
5085+
rowMutations.add(put1);
5086+
rowMutations.add(put2);
5087+
rowMutations.add(put3);
5088+
// check specific row in server and execute different row operations
5089+
assertTrue(hTable.checkAndMutate(key.getBytes(), family.getBytes(), column1.getBytes(),
5090+
CompareFilter.CompareOp.EQUAL, value1.getBytes(), rowMutations));
5091+
5092+
assertTrue(hTable.checkAndMutate(key.getBytes(), family.getBytes(), column2.getBytes(),
5093+
CompareFilter.CompareOp.GREATER, value1.getBytes(), rowMutations));
5094+
5095+
assertFalse(hTable.checkAndMutate(key.getBytes(), family.getBytes(), column1.getBytes(),
5096+
CompareFilter.CompareOp.LESS, value1.getBytes(), rowMutations));
5097+
5098+
assertFalse(hTable.checkAndMutate(key.getBytes(), family.getBytes(), column2.getBytes(),
5099+
CompareFilter.CompareOp.GREATER, value2.getBytes(), rowMutations));
50835100
}
50845101

50855102
@Test
@@ -5189,7 +5206,7 @@ public void testCellTTL() throws Exception {
51895206
try {
51905207
tryPut(hTable, errorPut);
51915208
} catch (Exception e) {
5192-
assertTrue(e.getCause().getCause().toString().contains("Unknown column 'TTL'"));
5209+
assertTrue(e.getCause().toString().contains("Unknown column 'TTL'"));
51935210
}
51945211
// test put and get
51955212
tryPut(hTable, put1);

0 commit comments

Comments
 (0)