use default buffer size for index, use BLOB_DATA_SIZE for data buffer (#1693)

This commit is contained in:
Rob Walker 2018-11-02 21:52:57 -07:00 committed by GitHub
parent e7cbbd8d45
commit 95f9488a70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 8 deletions

View File

@ -77,10 +77,6 @@ pub struct LedgerWindow {
pub const LEDGER_DATA_FILE: &str = "data"; pub const LEDGER_DATA_FILE: &str = "data";
const LEDGER_INDEX_FILE: &str = "index"; const LEDGER_INDEX_FILE: &str = "index";
const LEDGER_BUF_COUNT: usize = 32 * 1024;
const LEDGER_DATA_BUF_SIZE: usize = LEDGER_BUF_COUNT * BLOB_DATA_SIZE;
const LEDGER_INDEX_BUF_SIZE: usize = LEDGER_BUF_COUNT * SIZEOF_U64 as usize;
// use a CONST because there's a cast, and we don't want "sizeof::<u64> as u64"... // use a CONST because there's a cast, and we don't want "sizeof::<u64> as u64"...
const SIZEOF_U64: u64 = size_of::<u64>() as u64; const SIZEOF_U64: u64 = size_of::<u64>() as u64;
@ -116,9 +112,9 @@ impl LedgerWindow {
let ledger_path = Path::new(&ledger_path); let ledger_path = Path::new(&ledger_path);
let index = File::open(ledger_path.join(LEDGER_INDEX_FILE))?; let index = File::open(ledger_path.join(LEDGER_INDEX_FILE))?;
let index = BufReader::with_capacity(LEDGER_INDEX_BUF_SIZE, index); let index = BufReader::new(index);
let data = File::open(ledger_path.join(LEDGER_DATA_FILE))?; let data = File::open(ledger_path.join(LEDGER_DATA_FILE))?;
let data = BufReader::with_capacity(LEDGER_DATA_BUF_SIZE, data); let data = BufReader::with_capacity(BLOB_DATA_SIZE, data);
Ok(LedgerWindow { index, data }) Ok(LedgerWindow { index, data })
} }
@ -188,10 +184,10 @@ pub fn verify_ledger(ledger_path: &str) -> io::Result<()> {
format!("index is not a multiple of {} bytes long", SIZEOF_U64), format!("index is not a multiple of {} bytes long", SIZEOF_U64),
))?; ))?;
} }
let mut index = BufReader::with_capacity(LEDGER_INDEX_BUF_SIZE, index); let mut index = BufReader::new(index);
let data = File::open(ledger_path.join(LEDGER_DATA_FILE))?; let data = File::open(ledger_path.join(LEDGER_DATA_FILE))?;
let mut data = BufReader::with_capacity(LEDGER_DATA_BUF_SIZE, data); let mut data = BufReader::with_capacity(BLOB_DATA_SIZE, data);
let mut last_data_offset = 0; let mut last_data_offset = 0;
let mut index_offset = 0; let mut index_offset = 0;