Skip to content

adapt read hot only #209

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

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
4 changes: 4 additions & 0 deletions src/main/java/com/alipay/oceanbase/hbase/OHTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,8 @@ private ObTableQuery buildObTableQuery(ObHTableFilter filter, final Scan scan) {
HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE));
obTableQuery.setObKVParams(buildOBKVParams(scan));
obTableQuery.setScanRangeColumns("K", "Q", "T");
byte[] hotOnly = scan.getAttribute(HBASE_HTABLE_QUERY_HOT_ONLY);
obTableQuery.setHotOnly(hotOnly != null && Arrays.equals(hotOnly, "true".getBytes()));
return obTableQuery;
}

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

Expand Down
25 changes: 15 additions & 10 deletions src/main/java/com/alipay/oceanbase/hbase/constants/OHConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
public final class OHConstants {

/**
* ocenbase hbase root server http url
* oceanbase hbase root server http url
*/
public static final String HBASE_OCEANBASE_PARAM_URL = "hbase.oceanbase.paramURL";

/**
* ocenbase hbase connect server username
* oceanbase hbase connect server username
*/
public static final String HBASE_OCEANBASE_FULL_USER_NAME = "hbase.oceanbase.fullUserName";

/**
* ocenbase hbase connect server password
* oceanbase hbase connect server password
*/
public static final String HBASE_OCEANBASE_PASSWORD = "hbase.oceanbase.password";

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

/**
* ocenbase hbase connect server password
* oceanbase hbase connect server password
*/
public static final String HBASE_OCEANBASE_BATCH_EXECUTOR = "hbase.oceanbase.batch.executor";

/**
* ocenbase hbase connect server ODP address
* oceanbase hbase connect server ODP address
*/
public static final String HBASE_OCEANBASE_ODP_ADDR = "hbase.oceanbase.odpAddr";

/**
* ocenbase hbase connect server ODP port
* oceanbase hbase connect server ODP port
*/
public static final String HBASE_OCEANBASE_ODP_PORT = "hbase.oceanbase.odpPort";

/**
* ocenbase hbase connect server ODP mode
* oceanbase hbase connect server ODP mode
*/
public static final String HBASE_OCEANBASE_ODP_MODE = "hbase.oceanbase.odpMode";

/**
* ocenbase hbase connect server database
* oceanbase hbase connect server database
*/
public static final String HBASE_OCEANBASE_DATABASE = "hbase.oceanbase.database";

/**
* ocenbase hbase model rowkey column is consist of following column
* oceanbase hbase model rowkey column is consist of following column
* K, Q, T hbase value
*/
public static final String[] ROW_KEY_COLUMNS = new String[] { "K",
"Q", "T" };

/**
* ocenbase hbase model value column is consist of following column
* oceanbase hbase model value column is consist of following column
* V hbase value
*/
public static final String[] V_COLUMNS = new String[] { "V" };
Expand Down Expand Up @@ -124,6 +124,11 @@ public final class OHConstants {
*/
public static final String DEFAULT_HBASE_HTABLE_TEST_LOAD_SUFFIX = "_t";

/**
* use to specify whether to query only the data in hot storage when performing a query.
*/
public static final String HBASE_HTABLE_QUERY_HOT_ONLY = "hbase.htable.query.hot_only";

/*-------------------------------------------------------------------------------------------------------------*/

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*-
* #%L
* OBKV HBase Client Framework
* %%
* Copyright (C) 2025 OceanBase Group
* %%
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* #L%
*/

package com.alipay.oceanbase.hbase.secondary;

import com.alipay.oceanbase.hbase.OHTableClient;
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.filter.BinaryComparator;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.filter.ValueFilter;
import org.junit.*;

import java.util.*;

import static com.alipay.oceanbase.hbase.constants.OHConstants.HBASE_HTABLE_QUERY_HOT_ONLY;
import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
import static com.alipay.oceanbase.hbase.util.TableTemplateManager.*;
import static org.apache.hadoop.hbase.util.Bytes.toBytes;


public class OHTableShareStorageSeriesTest {
private static List<String> tableNames = new LinkedList<String>();
private static Map<String, List<String>> group2tableNames = new LinkedHashMap<>();


@BeforeClass
public static void before() throws Exception {
openDistributedExecute();
for (TableType type : NORMAL_SERIES_PARTITIONED_TABLES) {
createTables(type, tableNames, group2tableNames, true);
}
for (TableType type : NORMAL_SERIES_PARTITIONED_TABLES) {
alterTables(type, tableNames, group2tableNames, true);
}
}

@AfterClass
public static void finish() throws Exception {
closeDistributedExecute();
}

@Before
public void prepareCase() throws Exception {
truncateTables(tableNames, group2tableNames);
}


public static void testGetImpl(String tableName) throws Exception {
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
hTable.init();

// 0. prepare data - 100 key
long recordCount = 100;
String family = getColumnFamilyName(tableName);
String key = "Key";
String column = "Column";
String value = "Value";
long curTs = System.currentTimeMillis();
for (int i = 0; i < recordCount; i++) {
Put put = new Put(toBytes(key + i));
put.add(family.getBytes(), (column + i).getBytes(), curTs, toBytes(value + i));
hTable.put(put);
}

// 1. get, expect less than 100 key
long getCount = 0;
for (int i = 0; i < recordCount; i++) {
Get get = new Get((key + i).getBytes());
get.setAttribute(HBASE_HTABLE_QUERY_HOT_ONLY, "true".getBytes());
get.addColumn(family.getBytes(), (column + i).getBytes());
Result r = hTable.get(get);
Cell cells[] = r.rawCells();
getCount += cells.length;
}
Assert.assertTrue(getCount < recordCount);

hTable.close();
}

public static void testScanImpl(String tableName) throws Exception {
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
hTable.init();

// 0. prepare data - 100 key
long recordCount = 100;
String family = getColumnFamilyName(tableName);
String key = "Key";
String column = "Column";
String value = "Value";
long curTs = System.currentTimeMillis();
for (int i = 0; i < recordCount; i++) {
Put put = new Put(toBytes(key + i));
put.add(family.getBytes(), (column).getBytes(), curTs, toBytes(value + i));
hTable.put(put);
}

// 1. scan not specify column
{
Scan scan = new Scan(key.getBytes(), (key+recordCount).getBytes());
scan.addFamily(family.getBytes());
ResultScanner scanner = hTable.getScanner(scan);
int count = 0;
for (Result result : scanner) {
for (Cell cell : result.rawCells()) {
count++;
}
}
Assert.assertTrue(count < recordCount);
}

// 2. scan specify column
{
Scan scan = new Scan(key.getBytes(), (key+recordCount).getBytes());
scan.addColumn(family.getBytes(), column.getBytes());
ResultScanner scanner = hTable.getScanner(scan);
int count = 0;
for (Result result : scanner) {
for (Cell cell : result.rawCells()) {
count++;
}
}
Assert.assertTrue(count < recordCount);
}

// 3. scan specify versions
{
Scan scan = new Scan(key.getBytes(), (key+recordCount).getBytes());
scan.setMaxVersions(2);
scan.addColumn(family.getBytes(), column.getBytes());
ResultScanner scanner = hTable.getScanner(scan);
int count = 0;
for (Result result : scanner) {
for (Cell cell : result.rawCells()) {
count++;
}
}
Assert.assertTrue(count < recordCount);
}

// 4. scan specify time range
{
Scan scan = new Scan(key.getBytes(), (key+recordCount).getBytes());
scan.setMaxVersions(2);
scan.setTimeStamp(curTs);
scan.addColumn(family.getBytes(), column.getBytes());
ResultScanner scanner = hTable.getScanner(scan);
int count = 0;
for (Result result : scanner) {
for (Cell cell : result.rawCells()) {
count++;
}
}
Assert.assertTrue(count < recordCount);
}

hTable.close();
}

@Test
public void testGet() throws Throwable {
FOR_EACH(tableNames, OHTableShareStorageSeriesTest::testGetImpl);
}


@Test
public void testScan() throws Throwable {
FOR_EACH(tableNames, OHTableShareStorageSeriesTest::testScanImpl);
}

}
Loading