code cleanup, storage_size() was Option<u64>, now Result<u64> (#7424)

This commit is contained in:
Sunny Gleason 2019-12-12 14:55:30 -05:00 committed by GitHub
parent dbb8267b09
commit 83218c479a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 9 deletions

View File

@ -66,7 +66,7 @@ impl LedgerCleanupService {
let disk_utilization_post = blocktree.storage_size();
if let (Some(disk_utilization_pre), Some(disk_utilization_post)) =
if let (Ok(disk_utilization_pre), Ok(disk_utilization_post)) =
(disk_utilization_pre, disk_utilization_post)
{
datapoint_debug!(

View File

@ -1499,9 +1499,7 @@ impl Blocktree {
self.last_root()
}
// return the approximate size in bytes of the storage directory, or `None` if an error occurs
// while reading the directory (directory not found, file deleted, etc)
pub fn storage_size(&self) -> Option<u64> {
pub fn storage_size(&self) -> Result<u64> {
self.db.storage_size()
}
}

View File

@ -1,7 +1,7 @@
use crate::blocktree_meta;
use bincode::{deserialize, serialize};
use byteorder::{BigEndian, ByteOrder};
use fs_extra::dir::get_size;
use fs_extra;
use log::*;
pub use rocksdb::Direction as IteratorDirection;
use rocksdb::{
@ -43,6 +43,7 @@ pub enum BlocktreeError {
SlotNotRooted,
IO(#[from] std::io::Error),
Serialize(#[from] Box<bincode::ErrorKind>),
FsExtraError(#[from] fs_extra::error::Error),
}
pub(crate) type Result<T> = std::result::Result<T, BlocktreeError>;
@ -580,10 +581,8 @@ impl Database {
self.backend.write(batch.write_batch)
}
// return the approximate size in bytes of the storage directory, or `None` if an error occurs
// while reading the directory (directory not found, file deleted, etc)
pub fn storage_size(&self) -> Option<u64> {
get_size(&self.path).ok()
pub fn storage_size(&self) -> Result<u64> {
Ok(fs_extra::dir::get_size(&self.path)?)
}
}