Skip to content

Commit

Permalink
Merge pull request #627 from tursodatabase/log-when-dirty
Browse files Browse the repository at this point in the history
collect more data about dirty startups
  • Loading branch information
MarinPostma authored Nov 15, 2023
2 parents eafb6c7 + efa02d2 commit e988268
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libsql-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::sync::{Arc, Weak};
use crate::auth::Auth;
use crate::connection::{Connection, MakeConnection};
use crate::error::Error;
use crate::metrics::DIRTY_STARTUP;
use crate::migration::maybe_migrate;
use crate::net::Accept;
use crate::rpc::proxy::rpc::proxy_server::Proxy;
Expand Down Expand Up @@ -247,6 +248,10 @@ fn sentinel_file_path(path: &Path) -> PathBuf {
fn init_sentinel_file(path: &Path) -> anyhow::Result<bool> {
let path = sentinel_file_path(path);
if path.try_exists()? {
DIRTY_STARTUP.increment(1);
tracing::warn!(
"sentinel file found: sqld was not shutdown gracefully, namespaces will be recovered."
);
return Ok(true);
}

Expand Down Expand Up @@ -450,6 +455,7 @@ where
join_set.shutdown().await;
// clean shutdown, remove sentinel file
std::fs::remove_file(sentinel_file_path(&self.path))?;
tracing::info!("sqld was shutdown gracefully. Bye!");
}
Some(res) = join_set.join_next() => {
res??;
Expand Down
8 changes: 8 additions & 0 deletions libsql-server/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ pub static LEGACY_HTTP_CALL: Lazy<Counter> = Lazy::new(|| {
describe_counter!(NAME, "number of calls to the legacy HTTP API");
register_counter!(NAME)
});
pub static DIRTY_STARTUP: Lazy<Counter> = Lazy::new(|| {
const NAME: &str = "libsql_server_dirty_startup";
describe_counter!(
NAME,
"how many times an instance started with a dirty state"
);
register_counter!(NAME)
});

0 comments on commit e988268

Please sign in to comment.