additional tracing spans / log cleanup.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
8296e0ed67
commit
eb5556e74e
2 changed files with 12 additions and 7 deletions
|
@ -30,6 +30,7 @@ pub struct Engine {
|
||||||
pub(crate) type Db = DBWithThreadMode<MultiThreaded>;
|
pub(crate) type Db = DBWithThreadMode<MultiThreaded>;
|
||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
|
#[tracing::instrument(skip_all)]
|
||||||
pub(crate) fn open(server: &Arc<Server>) -> Result<Arc<Self>> {
|
pub(crate) fn open(server: &Arc<Server>) -> Result<Arc<Self>> {
|
||||||
let config = &server.config;
|
let config = &server.config;
|
||||||
let cache_capacity_bytes = config.db_cache_capacity_mb * 1024.0 * 1024.0;
|
let cache_capacity_bytes = config.db_cache_capacity_mb * 1024.0 * 1024.0;
|
||||||
|
@ -51,7 +52,7 @@ impl Engine {
|
||||||
if config.rocksdb_repair {
|
if config.rocksdb_repair {
|
||||||
warn!("Starting database repair. This may take a long time...");
|
warn!("Starting database repair. This may take a long time...");
|
||||||
if let Err(e) = Db::repair(&db_opts, &config.database_path) {
|
if let Err(e) = Db::repair(&db_opts, &config.database_path) {
|
||||||
error!("Repair failed: {:?}", e);
|
error!("Repair failed: {e:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,9 +77,9 @@ impl Engine {
|
||||||
|
|
||||||
let db = res.or_else(or_else)?;
|
let db = res.or_else(or_else)?;
|
||||||
info!(
|
info!(
|
||||||
"Opened database at sequence number {} in {:?}",
|
sequence = %db.latest_sequence_number(),
|
||||||
db.latest_sequence_number(),
|
time = ?load_time.elapsed(),
|
||||||
load_time.elapsed()
|
"Opened database."
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(Arc::new(Self {
|
Ok(Arc::new(Self {
|
||||||
|
@ -93,15 +94,16 @@ impl Engine {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
pub(crate) fn open_cf(&self, name: &str) -> Result<Arc<BoundColumnFamily<'_>>> {
|
pub(crate) fn open_cf(&self, name: &str) -> Result<Arc<BoundColumnFamily<'_>>> {
|
||||||
let mut cfs = self.cfs.lock().expect("locked");
|
let mut cfs = self.cfs.lock().expect("locked");
|
||||||
if !cfs.contains(name) {
|
if !cfs.contains(name) {
|
||||||
debug!("Creating new column family in database: {}", name);
|
debug!("Creating new column family in database: {name}");
|
||||||
|
|
||||||
let mut col_cache = self.col_cache.write().expect("locked");
|
let mut col_cache = self.col_cache.write().expect("locked");
|
||||||
let opts = cf_options(&self.server.config, name, self.opts.clone(), &mut col_cache);
|
let opts = cf_options(&self.server.config, name, self.opts.clone(), &mut col_cache);
|
||||||
if let Err(e) = self.db.create_cf(name, &opts) {
|
if let Err(e) = self.db.create_cf(name, &opts) {
|
||||||
error!("Failed to create new column family: {e}");
|
error!(?name, "Failed to create new column family: {e}");
|
||||||
return or_else(e);
|
return or_else(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,18 +150,20 @@ impl Engine {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
for (name, cache) in &*self.col_cache.read().expect("locked") {
|
for (name, cache) in &*self.col_cache.read().expect("locked") {
|
||||||
writeln!(res, "{} cache: {:.2} MiB", name, mibs(u64::try_from(cache.get_usage())?))?;
|
writeln!(res, "{name} cache: {:.2} MiB", mibs(u64::try_from(cache.get_usage())?))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self), level = "debug")]
|
||||||
pub fn cleanup(&self) -> Result<()> {
|
pub fn cleanup(&self) -> Result<()> {
|
||||||
debug!("Running flush_opt");
|
debug!("Running flush_opt");
|
||||||
let flushoptions = rocksdb::FlushOptions::default();
|
let flushoptions = rocksdb::FlushOptions::default();
|
||||||
result(DBCommon::flush_opt(&self.db, &flushoptions))
|
result(DBCommon::flush_opt(&self.db, &flushoptions))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn backup(&self) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn backup(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let config = &self.server.config;
|
let config = &self.server.config;
|
||||||
let path = config.database_backup_path.as_ref();
|
let path = config.database_backup_path.as_ref();
|
||||||
|
|
|
@ -8,6 +8,7 @@ pub type Maps = BTreeMap<String, Arc<Map>>;
|
||||||
|
|
||||||
pub(crate) fn open(db: &Arc<Engine>) -> Result<Maps> { open_list(db, MAPS) }
|
pub(crate) fn open(db: &Arc<Engine>) -> Result<Maps> { open_list(db, MAPS) }
|
||||||
|
|
||||||
|
#[tracing::instrument(skip_all, level = "debug")]
|
||||||
pub(crate) fn open_list(db: &Arc<Engine>, maps: &[&str]) -> Result<Maps> {
|
pub(crate) fn open_list(db: &Arc<Engine>, maps: &[&str]) -> Result<Maps> {
|
||||||
Ok(maps
|
Ok(maps
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue