disk bucket: factor out allocate_bucket (#32920)

This commit is contained in:
Jeff Washington (jwash) 2023-08-22 14:21:07 -07:00 committed by GitHub
parent cd96d5b6c3
commit 3b5e35e819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 5 deletions

View File

@ -82,18 +82,24 @@ impl<T: Clone + Copy> BucketApi<T> {
} }
} }
fn get_write_bucket(&self) -> RwLockWriteGuard<Option<Bucket<T>>> { /// allocate new bucket if not allocated yet
let mut bucket = self.bucket.write().unwrap(); fn allocate_bucket(&self, bucket: &mut RwLockWriteGuard<Option<Bucket<T>>>) {
if bucket.is_none() { if bucket.is_none() {
*bucket = Some(Bucket::new( **bucket = Some(Bucket::new(
Arc::clone(&self.drives), Arc::clone(&self.drives),
self.max_search, self.max_search,
Arc::clone(&self.stats), Arc::clone(&self.stats),
Arc::clone(&self.count), Arc::clone(&self.count),
)); ));
}
}
fn get_write_bucket(&self) -> RwLockWriteGuard<Option<Bucket<T>>> {
let mut bucket = self.bucket.write().unwrap();
if let Some(bucket) = bucket.as_mut() {
bucket.handle_delayed_grows();
} else { } else {
let write = bucket.as_mut().unwrap(); self.allocate_bucket(&mut bucket);
write.handle_delayed_grows();
} }
bucket bucket
} }