HDFS-12524. Ozone: Record number of keys scanned and hinted for getRangeKVs call. Contributed by Weiwei Yang.
This commit is contained in:
parent
712bd70ac7
commit
d303b7f40f
|
@ -353,11 +353,23 @@ public class LevelDBStore implements MetadataStore {
|
|||
if (dbIter != null) {
|
||||
dbIter.close();
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
long timeConsumed = end - start;
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Time consumed for getRangeKVs() is {},"
|
||||
+ " result length is {}.", timeConsumed, result.size());
|
||||
if (filters != null) {
|
||||
for (MetadataKeyFilters.MetadataKeyFilter filter : filters) {
|
||||
int scanned = filter.getKeysScannedNum();
|
||||
int hinted = filter.getKeysHintedNum();
|
||||
if (scanned > 0 || hinted > 0) {
|
||||
LOG.debug(
|
||||
"getRangeKVs ({}) numOfKeysScanned={}, numOfKeysHinted={}",
|
||||
filter.getClass().getSimpleName(), filter.getKeysScannedNum(),
|
||||
filter.getKeysHintedNum());
|
||||
}
|
||||
}
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
long timeConsumed = end - start;
|
||||
LOG.debug("Time consumed for getRangeKVs() is {}ms,"
|
||||
+ " result length is {}.", timeConsumed, result.size());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -38,6 +38,14 @@ public class MetadataKeyFilters {
|
|||
* @return true if a certain condition satisfied, return false otherwise.
|
||||
*/
|
||||
boolean filterKey(byte[] preKey, byte[] currentKey, byte[] nextKey);
|
||||
|
||||
default int getKeysScannedNum() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
default int getKeysHintedNum() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,19 +55,37 @@ public class MetadataKeyFilters {
|
|||
public static class KeyPrefixFilter implements MetadataKeyFilter {
|
||||
|
||||
private String keyPrefix = null;
|
||||
private int keysScanned = 0;
|
||||
private int keysHinted = 0;
|
||||
|
||||
public KeyPrefixFilter(String keyPrefix) {
|
||||
this.keyPrefix = keyPrefix;
|
||||
}
|
||||
|
||||
@Override public boolean filterKey(byte[] preKey, byte[] currentKey,
|
||||
@Override
|
||||
public boolean filterKey(byte[] preKey, byte[] currentKey,
|
||||
byte[] nextKey) {
|
||||
keysScanned++;
|
||||
if (Strings.isNullOrEmpty(keyPrefix)) {
|
||||
return true;
|
||||
} else {
|
||||
return currentKey != null &&
|
||||
DFSUtil.bytes2String(currentKey).startsWith(keyPrefix);
|
||||
if (currentKey != null &&
|
||||
DFSUtil.bytes2String(currentKey).startsWith(keyPrefix)) {
|
||||
keysHinted++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getKeysScannedNum() {
|
||||
return keysScanned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getKeysHintedNum() {
|
||||
return keysHinted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,11 +201,22 @@ public class RocksDBStore implements MetadataStore {
|
|||
long end = System.currentTimeMillis();
|
||||
long timeConsumed = end - start;
|
||||
if (LOG.isDebugEnabled()) {
|
||||
if (filters != null) {
|
||||
for (MetadataKeyFilters.MetadataKeyFilter filter : filters) {
|
||||
int scanned = filter.getKeysScannedNum();
|
||||
int hinted = filter.getKeysHintedNum();
|
||||
if (scanned > 0 || hinted > 0) {
|
||||
LOG.debug(
|
||||
"getRangeKVs ({}) numOfKeysScanned={}, numOfKeysHinted={}",
|
||||
filter.getClass().getSimpleName(), filter.getKeysScannedNum(),
|
||||
filter.getKeysHintedNum());
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG.debug("Time consumed for getRangeKVs() is {}ms,"
|
||||
+ " result length is {}.", timeConsumed, result.size());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -265,6 +265,8 @@ public class TestMetadataStore {
|
|||
Assert.assertTrue(result.stream().allMatch(entry ->
|
||||
new String(entry.getKey()).startsWith("b")
|
||||
));
|
||||
Assert.assertEquals(20, filter1.getKeysScannedNum());
|
||||
Assert.assertEquals(10, filter1.getKeysHintedNum());
|
||||
result = store.getRangeKVs(null, 3, filter1);
|
||||
Assert.assertEquals(3, result.size());
|
||||
result = store.getRangeKVs(getBytes("b3"), 1, filter1);
|
||||
|
|
Loading…
Reference in New Issue