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) { private long getTotalUmcompressedBytes(List<HStoreFile> files) {
return files.stream().filter(f -> f != null && f.getReader() != null) return files.stream().filter(f -> f != null).mapToLong(f -> {
.mapToLong(f -> f.getReader().getTotalUncompressedBytes()).sum(); StoreFileReader reader = f.getReader();
if (reader == null) {
return 0;
} else {
return reader.getTotalUncompressedBytes();
}
}).sum();
} }
private long getStorefilesSize(Collection<HStoreFile> files, Predicate<HStoreFile> predicate) { private long getStorefilesSize(Collection<HStoreFile> files, Predicate<HStoreFile> predicate) {
return files.stream().filter(f -> f != null && f.getReader() != null).filter(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) { private long getStoreFileFieldSize(ToLongFunction<StoreFileReader> f) {
return this.storeEngine.getStoreFileManager().getStorefiles().stream().filter(sf -> { return this.storeEngine.getStoreFileManager().getStorefiles().stream()
if (sf.getReader() == null) { .map(HStoreFile::getReader).filter(reader -> {
LOG.warn("StoreFile {} has a null Reader", sf); if (reader == null) {
return false; return false;
} else { } else {
return true; return true;
} }
}).map(HStoreFile::getReader).mapToLong(f).sum(); }).mapToLong(f).sum();
} }
@Override @Override