HBASE-23159 HStore#getStorefilesSize may throw NPE

This commit is contained in:
Lijin Bin 2019-10-12 19:44:42 -07:00 committed by stack
parent 56e0652aff
commit 6f6d331f9f
1 changed files with 24 additions and 11 deletions

View File

@ -2135,24 +2135,37 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat
}
private long getTotalUmcompressedBytes(List<HStoreFile> files) {
return files.stream().filter(f -> f != null && f.getReader() != null)
.mapToLong(f -> f.getReader().getTotalUncompressedBytes()).sum();
return files.stream().filter(f -> f != null).mapToLong(f -> {
StoreFileReader reader = f.getReader();
if (reader == null) {
return 0;
} else {
return reader.getTotalUncompressedBytes();
}
}).sum();
}
private long getStorefilesSize(Collection<HStoreFile> files, Predicate<HStoreFile> predicate) {
return files.stream().filter(f -> f != null && f.getReader() != null).filter(predicate)
.mapToLong(f -> f.getReader().length()).sum();
.mapToLong(f -> {
StoreFileReader reader = f.getReader();
if (reader == null) {
return 0;
} else {
return reader.length();
}
}).sum();
}
private long getStoreFileFieldSize(ToLongFunction<StoreFileReader> f) {
return this.storeEngine.getStoreFileManager().getStorefiles().stream().filter(sf -> {
if (sf.getReader() == null) {
LOG.warn("StoreFile {} has a null Reader", sf);
return false;
} else {
return true;
}
}).map(HStoreFile::getReader).mapToLong(f).sum();
return this.storeEngine.getStoreFileManager().getStorefiles().stream()
.map(HStoreFile::getReader).filter(reader -> {
if (reader == null) {
return false;
} else {
return true;
}
}).mapToLong(f).sum();
}
@Override