dev-work-8103 commented on code in PR #7593:
URL: https://github.com/apache/hbase/pull/7593#discussion_r2678404005
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCustomCellTieredCompactor.java:
##########
@@ -74,6 +77,9 @@ public void tearDown() throws Exception {
@Test
public void testCustomCellTieredCompactor() throws Exception {
+
utility.getConfiguration().setInt("hbase.hfile.compaction.discharger.interval",
10);
+ utility.startMiniCluster();
+
Review Comment:
To handle different configurations across test methods, I've adopted the
pattern used in TestColumnFamilyDescriptorDefaultVersions.
1. The setUp() method initializes HBaseTestingUtil and starts the mini
cluster with the default CustomCellTieringValueProvider configuration.
2. testCustomCellTieredCompactor() executes using this default configuration.
3. testCustomCellTieredCompactorWithRowKeyDateTieringValue() shuts down the
mini cluster, reconfigures it with RowKeyDateTieringValueProvider, and restarts
before executing its test logic.
4. The tearDown() method ensures proper cleanup after each test.
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/compactions/TestCustomCellTieredCompactor.java:
##########
@@ -145,4 +151,268 @@ public void testCustomCellTieredCompactor() throws
Exception {
}
});
}
+
+ @Test
+ public void
testCustomCellTieredCompactorWithRowKeyDateTieringValueProviderWithGlobalConf()
+ throws Exception {
+ utility.getConfiguration().set(TIERING_VALUE_PROVIDER,
+ RowKeyDateTieringValueProvider.class.getName());
+
utility.getConfiguration().set(RowKeyDateTieringValueProvider.TIERING_KEY_DATE_PATTERN,
+ "(\\d{17})$");
+
utility.getConfiguration().set(RowKeyDateTieringValueProvider.TIERING_KEY_DATE_FORMAT,
+ "yyyyMMddHHmmssSSS");
+ utility.startMiniCluster();
+
+ ColumnFamilyDescriptorBuilder clmBuilder =
ColumnFamilyDescriptorBuilder.newBuilder(FAMILY);
+ clmBuilder.setValue("hbase.hstore.engine.class",
CustomTieredStoreEngine.class.getName());
+
+ TableName tableName = TableName.valueOf("testCustomCellTieredCompactor");
+ TableDescriptorBuilder tblBuilder =
TableDescriptorBuilder.newBuilder(tableName);
+ tblBuilder.setColumnFamily(clmBuilder.build());
+ utility.getAdmin().createTable(tblBuilder.build());
+ utility.waitTableAvailable(tableName);
+
+ Connection connection = utility.getConnection();
+ Table table = connection.getTable(tableName);
+ long recordTime = System.currentTimeMillis();
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+
+ // Write data with date embedded in row key
+ for (int i = 0; i < 6; i++) {
+ List<Put> puts = new ArrayList<>(2);
+
+ // Old data - embed old date in row key (11 years ago)
+ String oldDate = sdf.format(new Date(recordTime - (11L * 366L * 24L *
60L * 60L * 1000L)));
+ String oldRowKey = "row_" + i + "_" + oldDate;
+ Put put = new Put(Bytes.toBytes(oldRowKey));
+ put.addColumn(FAMILY, Bytes.toBytes("val"), Bytes.toBytes("v" + i));
+ puts.add(put);
+
+ // Recent data - embed current date in row key
+ String recentDate = sdf.format(new Date(recordTime));
+ String recentRowKey = "row_" + (i + 1000) + "_" + recentDate;
+ put = new Put(Bytes.toBytes(recentRowKey));
+ put.addColumn(FAMILY, Bytes.toBytes("val"), Bytes.toBytes("v" + (i +
1000)));
+ puts.add(put);
+
+ table.put(puts);
+ utility.flush(tableName);
+ }
+ table.close();
+
+ long firstCompactionTime = System.currentTimeMillis();
+ utility.getAdmin().majorCompact(tableName);
+ Waiter.waitFor(utility.getConfiguration(), 5000,
+ () ->
utility.getMiniHBaseCluster().getMaster().getLastMajorCompactionTimestamp(tableName)
+ > firstCompactionTime);
+
+ long numHFiles = utility.getNumHFiles(tableName, FAMILY);
+ assertEquals(1, numHFiles);
+
+
utility.getMiniHBaseCluster().getRegions(tableName).get(0).getStore(FAMILY).getStorefiles()
+ .forEach(file -> {
+ byte[] rangeBytes = file.getMetadataValue(CUSTOM_TIERING_TIME_RANGE);
+ assertNotNull(rangeBytes);
+ try {
+ TimeRangeTracker timeRangeTracker =
TimeRangeTracker.parseFrom(rangeBytes);
+ assertEquals((recordTime - (11L * 366L * 24L * 60L * 60L * 1000L)),
+ timeRangeTracker.getMin());
+ assertEquals(recordTime, timeRangeTracker.getMax());
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ });
+
+ long secondCompactionTime = System.currentTimeMillis();
+ utility.getAdmin().majorCompact(tableName);
+ Waiter.waitFor(utility.getConfiguration(), 5000,
+ () ->
utility.getMiniHBaseCluster().getMaster().getLastMajorCompactionTimestamp(tableName)
+ > secondCompactionTime);
+
+ numHFiles = utility.getNumHFiles(tableName, FAMILY);
+ assertEquals(2, numHFiles);
+
+
utility.getMiniHBaseCluster().getRegions(tableName).get(0).getStore(FAMILY).getStorefiles()
+ .forEach(file -> {
+ byte[] rangeBytes = file.getMetadataValue(CUSTOM_TIERING_TIME_RANGE);
+ assertNotNull(rangeBytes);
+ try {
+ TimeRangeTracker timeRangeTracker =
TimeRangeTracker.parseFrom(rangeBytes);
+ assertEquals(timeRangeTracker.getMin(), timeRangeTracker.getMax());
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ });
+ }
Review Comment:
Sure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]