Skip to content

Commit b17ba7b

Browse files
authored
HBASE-24205 - Avoid metric collection for flushes and compactions (#1918)
* HBASE-24205 - Avoid metric collection for flushes and compactions * Use the existing matcher.isUserScan() to decide the scan type * Added a comment saying when we track the metrics
1 parent 510aad3 commit b17ba7b

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,30 @@ public StoreScanner(ScanInfo scanInfo, ScanType scanType,
342342
seekAllScanner(scanInfo, scanners);
343343
}
344344

345+
// Used to instantiate a scanner for user scan in test
346+
@VisibleForTesting
347+
StoreScanner(Scan scan, ScanInfo scanInfo, NavigableSet<byte[]> columns,
348+
List<? extends KeyValueScanner> scanners, ScanType scanType) throws IOException {
349+
// 0 is passed as readpoint because the test bypasses Store
350+
this(null, scan, scanInfo, columns != null ? columns.size() : 0, 0L, scan.getCacheBlocks(),
351+
scanType);
352+
if (scanType == ScanType.USER_SCAN) {
353+
this.matcher =
354+
UserScanQueryMatcher.create(scan, scanInfo, columns, oldestUnexpiredTS, now, null);
355+
} else {
356+
this.matcher = CompactionScanQueryMatcher.create(scanInfo, scanType, Long.MAX_VALUE,
357+
HConstants.OLDEST_TIMESTAMP, oldestUnexpiredTS, now, null, null, null);
358+
}
359+
seekAllScanner(scanInfo, scanners);
360+
}
361+
345362
// Used to instantiate a scanner for user scan in test
346363
@VisibleForTesting
347364
StoreScanner(Scan scan, ScanInfo scanInfo, NavigableSet<byte[]> columns,
348365
List<? extends KeyValueScanner> scanners) throws IOException {
349366
// 0 is passed as readpoint because the test bypasses Store
350-
this(null, scan, scanInfo, columns != null ? columns.size() : 0, 0L,
351-
scan.getCacheBlocks(), ScanType.USER_SCAN);
367+
this(null, scan, scanInfo, columns != null ? columns.size() : 0, 0L, scan.getCacheBlocks(),
368+
ScanType.USER_SCAN);
352369
this.matcher =
353370
UserScanQueryMatcher.create(scan, scanInfo, columns, oldestUnexpiredTS, now, null);
354371
seekAllScanner(scanInfo, scanners);
@@ -569,7 +586,8 @@ public boolean next(List<Cell> outResult, ScannerContext scannerContext) throws
569586

570587
int count = 0;
571588
long totalBytesRead = 0;
572-
boolean onlyFromMemstore = true;
589+
// track the cells for metrics only if it is a user read request.
590+
boolean onlyFromMemstore = matcher.isUserScan();
573591
try {
574592
LOOP: do {
575593
// Update and check the time limit based on the configured value of cellsPerTimeoutCheck
@@ -747,7 +765,7 @@ public boolean next(List<Cell> outResult, ScannerContext scannerContext) throws
747765
return scannerContext.setScannerState(NextState.NO_MORE_VALUES).hasMoreValues();
748766
} finally {
749767
// increment only if we have some result
750-
if (count > 0) {
768+
if (count > 0 && matcher.isUserScan()) {
751769
// if true increment memstore metrics, if not the mixed one
752770
updateMetricsStore(onlyFromMemstore);
753771
}

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,27 @@ public void testScanSameTimestamp() throws IOException {
588588
}
589589
}
590590

591+
@Test
592+
public void testNonUserScan() throws IOException {
593+
// returns only 1 of these 2 even though same timestamp
594+
KeyValue[] kvs = new KeyValue[] { create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"),
595+
create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), };
596+
List<KeyValueScanner> scanners = Arrays.asList(
597+
new KeyValueScanner[] { new KeyValueScanFixture(CellComparator.getInstance(), kvs) });
598+
599+
Scan scanSpec = new Scan().withStartRow(Bytes.toBytes("R1"));
600+
// this only uses maxVersions (default=1) and TimeRange (default=all)
601+
try (StoreScanner scan =
602+
new StoreScanner(scanSpec, scanInfo, null, scanners, ScanType.COMPACT_RETAIN_DELETES)) {
603+
List<Cell> results = new ArrayList<>();
604+
assertEquals(true, scan.next(results));
605+
assertEquals(1, results.size());
606+
// the type is not a user scan. so it won't account for the memstore reads
607+
assertEquals(0, scan.memstoreOnlyReads);
608+
assertEquals(kvs[0], results.get(0));
609+
}
610+
}
611+
591612
/*
592613
* Test test shows exactly how the matcher's return codes confuses the StoreScanner
593614
* and prevent it from doing the right thing. Seeking once, then nexting twice

0 commit comments

Comments
 (0)