HDFS-12524. Ozone: Record number of keys scanned and hinted for getRangeKVs call. Contributed by Weiwei Yang.

This commit is contained in:
Weiwei Yang 2017-09-26 19:22:18 +08:00 committed by Owen O'Malley
parent 712bd70ac7
commit d303b7f40f
4 changed files with 59 additions and 8 deletions

View File

@ -353,11 +353,23 @@ public class LevelDBStore implements MetadataStore {
if (dbIter != null) { if (dbIter != null) {
dbIter.close(); dbIter.close();
} }
long end = System.currentTimeMillis();
long timeConsumed = end - start;
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Time consumed for getRangeKVs() is {}," if (filters != null) {
+ " result length is {}.", timeConsumed, result.size()); 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; return result;

View File

@ -38,6 +38,14 @@ public class MetadataKeyFilters {
* @return true if a certain condition satisfied, return false otherwise. * @return true if a certain condition satisfied, return false otherwise.
*/ */
boolean filterKey(byte[] preKey, byte[] currentKey, byte[] nextKey); 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 { public static class KeyPrefixFilter implements MetadataKeyFilter {
private String keyPrefix = null; private String keyPrefix = null;
private int keysScanned = 0;
private int keysHinted = 0;
public KeyPrefixFilter(String keyPrefix) { public KeyPrefixFilter(String keyPrefix) {
this.keyPrefix = keyPrefix; this.keyPrefix = keyPrefix;
} }
@Override public boolean filterKey(byte[] preKey, byte[] currentKey, @Override
public boolean filterKey(byte[] preKey, byte[] currentKey,
byte[] nextKey) { byte[] nextKey) {
keysScanned++;
if (Strings.isNullOrEmpty(keyPrefix)) { if (Strings.isNullOrEmpty(keyPrefix)) {
return true; return true;
} else { } else {
return currentKey != null && if (currentKey != null &&
DFSUtil.bytes2String(currentKey).startsWith(keyPrefix); DFSUtil.bytes2String(currentKey).startsWith(keyPrefix)) {
keysHinted++;
return true;
}
return false;
} }
} }
@Override
public int getKeysScannedNum() {
return keysScanned;
}
@Override
public int getKeysHintedNum() {
return keysHinted;
}
} }
} }

View File

@ -201,11 +201,22 @@ public class RocksDBStore implements MetadataStore {
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
long timeConsumed = end - start; long timeConsumed = end - start;
if (LOG.isDebugEnabled()) { 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," LOG.debug("Time consumed for getRangeKVs() is {}ms,"
+ " result length is {}.", timeConsumed, result.size()); + " result length is {}.", timeConsumed, result.size());
} }
} }
return result; return result;
} }

View File

@ -265,6 +265,8 @@ public class TestMetadataStore {
Assert.assertTrue(result.stream().allMatch(entry -> Assert.assertTrue(result.stream().allMatch(entry ->
new String(entry.getKey()).startsWith("b") new String(entry.getKey()).startsWith("b")
)); ));
Assert.assertEquals(20, filter1.getKeysScannedNum());
Assert.assertEquals(10, filter1.getKeysHintedNum());
result = store.getRangeKVs(null, 3, filter1); result = store.getRangeKVs(null, 3, filter1);
Assert.assertEquals(3, result.size()); Assert.assertEquals(3, result.size());
result = store.getRangeKVs(getBytes("b3"), 1, filter1); result = store.getRangeKVs(getBytes("b3"), 1, filter1);