gvprathyusha6 commented on code in PR #7823:
URL: https://github.com/apache/hbase/pull/7823#discussion_r2895723143
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHMobStore.java:
##########
@@ -446,6 +449,103 @@ public void testResolve() throws Exception {
Assert.assertEquals(Bytes.toString(value2),
Bytes.toString(CellUtil.cloneValue(resultCell3)));
}
+ @Test
+ public void testMobStoreScannerGetFilesRead() throws IOException {
+ doTestMobStoreScannerGetFilesRead(false);
+ }
+
+ @Test
+ public void testReversedMobStoreScannerGetFilesRead() throws IOException {
+ doTestMobStoreScannerGetFilesRead(true);
+ }
+
+ /**
+ * Utility method for getFilesRead tests on MOB store scanners. Uses values
above mob threshold so
+ * DefaultMobStoreFlusher creates the mob file and refs.
+ */
+ private void doTestMobStoreScannerGetFilesRead(boolean reversed) throws
IOException {
+ // Setup: conf, root dir, and MOB store init (mob threshold causes large
values to go to MOB).
+ final Configuration conf = HBaseConfiguration.create();
+ Path basedir = new Path(DIR + name.getMethodName());
+ CommonFSUtils.setRootDir(conf, basedir);
+ init(name.getMethodName(), conf, false);
+
+ // Add values above MOB threshold and flush so DefaultMobStoreFlusher
creates mob file and refs.
+ byte[] valueAboveThreshold = Bytes.toBytes("value"); // threshold in setup
is 3 bytes
+ this.store.add(new KeyValue(row, family, qf1, 1, valueAboveThreshold),
null);
+ this.store.add(new KeyValue(row, family, qf2, 1, valueAboveThreshold),
null);
+ this.store.add(new KeyValue(row2, family, qf3, 1, valueAboveThreshold),
null);
+ flush(1);
+
+ // Collect expected paths: store files (refs) plus actual MOB files under
mob family path.
+ FileSystem storeFs = store.getFileSystem();
+ Set<Path> expectedFilePaths = new HashSet<>();
+ for (HStoreFile storeFile : this.store.getStorefiles()) {
+ expectedFilePaths.add(storeFs.makeQualified(storeFile.getPath()));
+ }
+ Path mobFamilyPath =
+ MobUtils.getMobFamilyPath(conf, TableName.valueOf(table),
Bytes.toString(family));
+ if (storeFs.exists(mobFamilyPath)) {
+ FileStatus[] mobFiles = storeFs.listStatus(mobFamilyPath);
+ for (FileStatus f : mobFiles) {
+ if (!f.isDirectory()) {
+ expectedFilePaths.add(storeFs.makeQualified(f.getPath()));
+ }
+ }
+ }
+ Assert.assertTrue("Should have at least one store file and one mob file",
+ expectedFilePaths.size() >= 2);
+
+ // Build scan (optionally reversed) and target columns; get store scanner
and verify type.
+ Scan scan = new Scan();
+ if (reversed) {
+ scan.setReversed(true);
+ }
+ scan.addColumn(family, qf1);
+ scan.addColumn(family, qf2);
+ scan.addColumn(family, qf3);
+ NavigableSet<byte[]> targetCols = new
ConcurrentSkipListSet<>(Bytes.BYTES_COMPARATOR);
+ targetCols.add(qf1);
+ targetCols.add(qf2);
+ targetCols.add(qf3);
+
+ KeyValueScanner kvScanner = store.getScanner(scan, targetCols, 0);
+ if (reversed) {
+ Assert.assertTrue("Store scanner should be ReversedMobStoreScanner",
+ kvScanner instanceof ReversedMobStoreScanner);
+ } else {
+ Assert.assertTrue("Store scanner should be MobStoreScanner",
+ kvScanner instanceof MobStoreScanner);
+ }
+
+ // Before close: getFilesRead must be empty; then drain scanner to resolve
MOB refs.
+ try {
+ Set<Path> filesReadBeforeClose = kvScanner.getFilesRead();
+ Assert.assertTrue("Should return empty set before closing",
filesReadBeforeClose.isEmpty());
+ Assert.assertEquals("Should have 0 files before closing", 0,
filesReadBeforeClose.size());
+
+ List<Cell> results = new ArrayList<>();
+ InternalScanner storeScanner = (InternalScanner) kvScanner;
Review Comment:
can you use StoreScanner instead?
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java:
##########
@@ -1093,4 +1107,201 @@ public void close() {
assertFalse(memStoreScanner.closed);
}
}
+
+ @Test
+ public void testGetFilesRead() throws Exception {
+ // Setup: test util, conf, fs, cache, region fs, and HFile context.
+ HBaseTestingUtil testUtil = new HBaseTestingUtil();
+ Configuration conf = testUtil.getConfiguration();
+ Path testDir = testUtil.getDataTestDir(name.getMethodName() +
"_directory");
+ FileSystem fs = testDir.getFileSystem(conf);
+ CacheConfig cacheConf = new CacheConfig(conf);
+ final String TEST_FAMILY = "cf";
+
+ final RegionInfo hri =
+
RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
+ HRegionFileSystem regionFs =
HRegionFileSystem.createRegionOnFileSystem(conf, fs,
+ new Path(testDir, hri.getTable().getNameAsString()), hri);
+ HFileContext meta = new HFileContextBuilder().withBlockSize(8 *
1024).build();
Review Comment:
nit: variable name can be hfileContext
--
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]