append_vec::remaining_bytes (#24531)
This commit is contained in:
parent
15e30add26
commit
b1c89cf6d4
|
@ -289,6 +289,11 @@ impl AppendVec {
|
||||||
self.current_len.store(0, Ordering::Release);
|
self.current_len.store(0, Ordering::Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// how many more bytes can be stored in this append vec
|
||||||
|
pub fn remaining_bytes(&self) -> u64 {
|
||||||
|
(self.capacity()).saturating_sub(self.len() as u64)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
self.current_len.load(Ordering::Acquire)
|
self.current_len.load(Ordering::Acquire)
|
||||||
}
|
}
|
||||||
|
@ -734,6 +739,21 @@ pub mod tests {
|
||||||
assert_eq!(av.get_account_test(index).unwrap(), account);
|
assert_eq!(av.get_account_test(index).unwrap(), account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_remaining_bytes() {
|
||||||
|
let path = get_append_vec_path("test_append");
|
||||||
|
let sz = 1024 * 1024;
|
||||||
|
let sz64 = sz as u64;
|
||||||
|
let av = AppendVec::new(&path.path, true, sz);
|
||||||
|
assert_eq!(av.capacity(), sz64);
|
||||||
|
assert_eq!(av.remaining_bytes(), sz64);
|
||||||
|
let account = create_test_account(0);
|
||||||
|
let acct_size = 136;
|
||||||
|
av.append_account_test(&account).unwrap();
|
||||||
|
assert_eq!(av.capacity(), sz64);
|
||||||
|
assert_eq!(av.remaining_bytes(), sz64 - acct_size);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_append_vec_data() {
|
fn test_append_vec_data() {
|
||||||
let path = get_append_vec_path("test_append_data");
|
let path = get_append_vec_path("test_append_data");
|
||||||
|
|
Loading…
Reference in New Issue