Skip to content

Commit 1cfe350

Browse files
committed
adapt read hot only
1 parent 51c1d62 commit 1cfe350

File tree

7 files changed

+899
-10
lines changed

7 files changed

+899
-10
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,8 @@ private ObTableQuery buildObTableQuery(ObHTableFilter filter, final Scan scan) {
18841884
HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE));
18851885
obTableQuery.setObKVParams(buildOBKVParams(scan));
18861886
obTableQuery.setScanRangeColumns("K", "Q", "T");
1887+
byte[] hotOnly = scan.getAttribute(HBASE_HTABLE_QUERY_HOT_ONLY);
1888+
obTableQuery.setHotOnly(hotOnly != null && Arrays.equals(hotOnly, "true".getBytes()));
18871889
return obTableQuery;
18881890
}
18891891

@@ -1910,6 +1912,8 @@ private ObTableQuery buildObTableQuery(final Get get, Collection<byte[]> columnQ
19101912
}
19111913
obTableQuery.setObKVParams(buildOBKVParams(get));
19121914
obTableQuery.setScanRangeColumns("K", "Q", "T");
1915+
byte[] hotOnly = get.getAttribute(HBASE_HTABLE_QUERY_HOT_ONLY);
1916+
obTableQuery.setHotOnly(hotOnly != null && Arrays.equals(hotOnly, "true".getBytes()));
19131917
return obTableQuery;
19141918
}
19151919

src/main/java/com/alipay/oceanbase/hbase/constants/OHConstants.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
public final class OHConstants {
2424

2525
/**
26-
* ocenbase hbase root server http url
26+
* oceanbase hbase root server http url
2727
*/
2828
public static final String HBASE_OCEANBASE_PARAM_URL = "hbase.oceanbase.paramURL";
2929

3030
/**
31-
* ocenbase hbase connect server username
31+
* oceanbase hbase connect server username
3232
*/
3333
public static final String HBASE_OCEANBASE_FULL_USER_NAME = "hbase.oceanbase.fullUserName";
3434

3535
/**
36-
* ocenbase hbase connect server password
36+
* oceanbase hbase connect server password
3737
*/
3838
public static final String HBASE_OCEANBASE_PASSWORD = "hbase.oceanbase.password";
3939

@@ -48,39 +48,39 @@ public final class OHConstants {
4848
public static final String HBASE_OCEANBASE_SYS_PASSWORD = "hbase.oceanbase.sysPassword";
4949

5050
/**
51-
* ocenbase hbase connect server password
51+
* oceanbase hbase connect server password
5252
*/
5353
public static final String HBASE_OCEANBASE_BATCH_EXECUTOR = "hbase.oceanbase.batch.executor";
5454

5555
/**
56-
* ocenbase hbase connect server ODP address
56+
* oceanbase hbase connect server ODP address
5757
*/
5858
public static final String HBASE_OCEANBASE_ODP_ADDR = "hbase.oceanbase.odpAddr";
5959

6060
/**
61-
* ocenbase hbase connect server ODP port
61+
* oceanbase hbase connect server ODP port
6262
*/
6363
public static final String HBASE_OCEANBASE_ODP_PORT = "hbase.oceanbase.odpPort";
6464

6565
/**
66-
* ocenbase hbase connect server ODP mode
66+
* oceanbase hbase connect server ODP mode
6767
*/
6868
public static final String HBASE_OCEANBASE_ODP_MODE = "hbase.oceanbase.odpMode";
6969

7070
/**
71-
* ocenbase hbase connect server database
71+
* oceanbase hbase connect server database
7272
*/
7373
public static final String HBASE_OCEANBASE_DATABASE = "hbase.oceanbase.database";
7474

7575
/**
76-
* ocenbase hbase model rowkey column is consist of following column
76+
* oceanbase hbase model rowkey column is consist of following column
7777
* K, Q, T hbase value
7878
*/
7979
public static final String[] ROW_KEY_COLUMNS = new String[] { "K",
8080
"Q", "T" };
8181

8282
/**
83-
* ocenbase hbase model value column is consist of following column
83+
* oceanbase hbase model value column is consist of following column
8484
* V hbase value
8585
*/
8686
public static final String[] V_COLUMNS = new String[] { "V" };
@@ -124,6 +124,11 @@ public final class OHConstants {
124124
*/
125125
public static final String DEFAULT_HBASE_HTABLE_TEST_LOAD_SUFFIX = "_t";
126126

127+
/**
128+
* use to specify whether to query only the data in hot storage when performing a query.
129+
*/
130+
public static final String HBASE_HTABLE_QUERY_HOT_ONLY = "hbase.htable.query.hot_only";
131+
127132
/*-------------------------------------------------------------------------------------------------------------*/
128133

129134
/**
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*-
2+
* #%L
3+
* OBKV HBase Client Framework
4+
* %%
5+
* Copyright (C) 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
18+
package com.alipay.oceanbase.hbase.secondary;
19+
20+
import com.alipay.oceanbase.hbase.OHTableClient;
21+
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
22+
import org.apache.hadoop.hbase.Cell;
23+
import org.apache.hadoop.hbase.client.*;
24+
import org.apache.hadoop.hbase.filter.BinaryComparator;
25+
import org.apache.hadoop.hbase.filter.CompareFilter;
26+
import org.apache.hadoop.hbase.filter.ValueFilter;
27+
import org.junit.*;
28+
29+
import java.util.*;
30+
31+
import static com.alipay.oceanbase.hbase.constants.OHConstants.HBASE_HTABLE_QUERY_HOT_ONLY;
32+
import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
33+
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
34+
import static com.alipay.oceanbase.hbase.util.TableTemplateManager.*;
35+
import static org.apache.hadoop.hbase.util.Bytes.toBytes;
36+
37+
38+
public class OHTableShareStorageSeriesTest {
39+
private static List<String> tableNames = new LinkedList<String>();
40+
private static Map<String, List<String>> group2tableNames = new LinkedHashMap<>();
41+
42+
43+
@BeforeClass
44+
public static void before() throws Exception {
45+
openDistributedExecute();
46+
for (TableType type : NORMAL_SERIES_PARTITIONED_TABLES) {
47+
createTables(type, tableNames, group2tableNames, true);
48+
}
49+
for (TableType type : NORMAL_SERIES_PARTITIONED_TABLES) {
50+
alterTables(type, tableNames, group2tableNames, true);
51+
}
52+
}
53+
54+
@AfterClass
55+
public static void finish() throws Exception {
56+
closeDistributedExecute();
57+
}
58+
59+
@Before
60+
public void prepareCase() throws Exception {
61+
truncateTables(tableNames, group2tableNames);
62+
}
63+
64+
65+
public static void testGetImpl(String tableName) throws Exception {
66+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
67+
hTable.init();
68+
69+
// 0. prepare data - 100 key
70+
long recordCount = 100;
71+
String family = getColumnFamilyName(tableName);
72+
String key = "Key";
73+
String column = "Column";
74+
String value = "Value";
75+
long curTs = System.currentTimeMillis();
76+
for (int i = 0; i < recordCount; i++) {
77+
Put put = new Put(toBytes(key + i));
78+
put.add(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value + i));
79+
hTable.put(put);
80+
}
81+
82+
// 1. get, expect less than 100 key
83+
long getCount = 0;
84+
for (int i = 0; i < recordCount; i++) {
85+
Get get = new Get((key + i).getBytes());
86+
get.setAttribute(HBASE_HTABLE_QUERY_HOT_ONLY, "true".getBytes());
87+
get.addColumn(family.getBytes(), (column + i).getBytes());
88+
Result r = hTable.get(get);
89+
Cell cells[] = r.rawCells();
90+
getCount += cells.length;
91+
}
92+
Assert.assertTrue(getCount < recordCount);
93+
94+
hTable.close();
95+
}
96+
97+
public static void testScanImpl(String tableName) throws Exception {
98+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
99+
hTable.init();
100+
101+
// 0. prepare data - 100 key
102+
long recordCount = 100;
103+
String family = getColumnFamilyName(tableName);
104+
String key = "Key";
105+
String column = "Column";
106+
String value = "Value";
107+
long curTs = System.currentTimeMillis();
108+
for (int i = 0; i < recordCount; i++) {
109+
Put put = new Put(toBytes(key + i));
110+
put.add(family.getBytes(), (column).getBytes(), curTs, toBytes(value + i));
111+
hTable.put(put);
112+
}
113+
114+
// 1. scan not specify column
115+
{
116+
Scan scan = new Scan(key.getBytes(), (key+recordCount).getBytes());
117+
scan.addFamily(family.getBytes());
118+
ResultScanner scanner = hTable.getScanner(scan);
119+
int count = 0;
120+
for (Result result : scanner) {
121+
for (Cell cell : result.rawCells()) {
122+
count++;
123+
}
124+
}
125+
Assert.assertTrue(count < recordCount);
126+
}
127+
128+
// 2. scan specify column
129+
{
130+
Scan scan = new Scan(key.getBytes(), (key+recordCount).getBytes());
131+
scan.addColumn(family.getBytes(), column.getBytes());
132+
ResultScanner scanner = hTable.getScanner(scan);
133+
int count = 0;
134+
for (Result result : scanner) {
135+
for (Cell cell : result.rawCells()) {
136+
count++;
137+
}
138+
}
139+
Assert.assertTrue(count < recordCount);
140+
}
141+
142+
// 3. scan specify versions
143+
{
144+
Scan scan = new Scan(key.getBytes(), (key+recordCount).getBytes());
145+
scan.setMaxVersions(2);
146+
scan.addColumn(family.getBytes(), column.getBytes());
147+
ResultScanner scanner = hTable.getScanner(scan);
148+
int count = 0;
149+
for (Result result : scanner) {
150+
for (Cell cell : result.rawCells()) {
151+
count++;
152+
}
153+
}
154+
Assert.assertTrue(count < recordCount);
155+
}
156+
157+
// 4. scan specify time range
158+
{
159+
Scan scan = new Scan(key.getBytes(), (key+recordCount).getBytes());
160+
scan.setMaxVersions(2);
161+
scan.setTimeStamp(curTs);
162+
scan.addColumn(family.getBytes(), column.getBytes());
163+
ResultScanner scanner = hTable.getScanner(scan);
164+
int count = 0;
165+
for (Result result : scanner) {
166+
for (Cell cell : result.rawCells()) {
167+
count++;
168+
}
169+
}
170+
Assert.assertTrue(count < recordCount);
171+
}
172+
173+
hTable.close();
174+
}
175+
176+
@Test
177+
public void testGet() throws Throwable {
178+
FOR_EACH(tableNames, OHTableShareStorageSeriesTest::testGetImpl);
179+
}
180+
181+
182+
@Test
183+
public void testScan() throws Throwable {
184+
FOR_EACH(tableNames, OHTableShareStorageSeriesTest::testScanImpl);
185+
}
186+
187+
}

0 commit comments

Comments
 (0)