log number of open files when panic

This commit is contained in:
Haoran Yi 2022-11-23 09:46:24 -06:00 committed by HaoranYi
parent ca8372efc1
commit 703511c3e8
4 changed files with 86 additions and 7 deletions

16
Cargo.lock generated
View File

@ -3541,6 +3541,21 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "procfs"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfb6451c91904606a1abe93e83a8ec851f45827fa84273f256ade45dc095818"
dependencies = [
"bitflags",
"byteorder",
"chrono",
"flate2",
"hex",
"lazy_static",
"rustix",
]
[[package]]
name = "proptest"
version = "1.0.0"
@ -4901,6 +4916,7 @@ dependencies = [
"log",
"memmap2",
"modular-bitfield",
"procfs",
"rand 0.7.3",
"rayon",
"solana-logger 1.15.0",

View File

@ -14,6 +14,7 @@ edition = "2021"
log = { version = "0.4.17" }
memmap2 = "0.5.3"
modular-bitfield = "0.11.2"
procfs = "0.14.1"
rand = "0.7.0"
solana-measure = { path = "../measure", version = "=1.15.0" }
solana-sdk = { path = "../sdk", version = "=1.15.0" }

View File

@ -1,6 +1,7 @@
use {
crate::{bucket_stats::BucketStats, MaxSearch},
memmap2::MmapMut,
procfs::process::{Limit, Process},
rand::{thread_rng, Rng},
solana_measure::measure::Measure,
std::{
@ -262,6 +263,14 @@ impl BucketStorage {
}
}
fn get_number_of_open_files_and_limit() -> Option<(usize, Limit)> {
let proc = Process::myself().ok()?;
let max_open_files_limit = proc.limits().unwrap().max_open_files;
let num_open_files = proc.fd_count().unwrap();
Some((num_open_files, max_open_files_limit))
}
fn new_map(
drives: &[PathBuf],
cell_size: usize,
@ -280,12 +289,24 @@ impl BucketStorage {
.create(true)
.open(file.clone())
.map_err(|e| {
panic!(
"Unable to create data file {} in current dir({:?}): {:?}",
file.display(),
std::env::current_dir(),
e
);
if let Some((num_open_files, max_open_files_limit)) = Self::get_number_of_open_files_and_limit() {
panic!(
"Unable to create data file {} in current dir({:?}): {:?}, current number of open files: {}, max limit of open files: {:?}",
file.display(),
std::env::current_dir(),
e,
num_open_files,
max_open_files_limit,
);
}
else {
panic!(
"Unable to create data file {} in current dir({:?}): {:?}",
file.display(),
std::env::current_dir(),
e,
);
}
})
.unwrap();
@ -381,7 +402,7 @@ impl BucketStorage {
#[cfg(test)]
mod test {
use {super::*, tempfile::tempdir};
use {super::*, procfs::process::LimitValue, tempfile::tempdir};
#[test]
fn test_bucket_storage() {
@ -412,5 +433,24 @@ mod test {
storage.free(ix, uid);
assert!(storage.is_free(ix));
assert_eq!(storage.uid(ix), None);
// test get_number_of_open_files_and_limit
if let Some((num_open_files, max_open_files_limit)) =
BucketStorage::get_number_of_open_files_and_limit()
{
assert!(num_open_files > 0);
match max_open_files_limit.soft_limit {
LimitValue::Unlimited => {}
LimitValue::Value(x) => assert!(x > 0),
}
match max_open_files_limit.hard_limit {
LimitValue::Unlimited => {}
LimitValue::Value(x) => assert!(x > 0),
}
println!("{:?}", num_open_files);
println!("{:?}", max_open_files_limit);
}
}
}

View File

@ -1801,6 +1801,12 @@ dependencies = [
"libc",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "histogram"
version = "0.6.9"
@ -3259,6 +3265,21 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "procfs"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfb6451c91904606a1abe93e83a8ec851f45827fa84273f256ade45dc095818"
dependencies = [
"bitflags",
"byteorder 1.4.3",
"chrono",
"flate2",
"hex",
"lazy_static",
"rustix",
]
[[package]]
name = "prost"
version = "0.9.0"
@ -4336,6 +4357,7 @@ dependencies = [
"log",
"memmap2",
"modular-bitfield",
"procfs",
"rand 0.7.3",
"solana-measure",
"solana-sdk 1.15.0",