feat: Log messages during database initialization (#2180)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
pull/24376/head
Andrew Lamb 2021-08-04 07:04:41 -04:00 committed by GitHub
parent 2727ccfbe3
commit 7a18087044
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 8 deletions

View File

@ -146,10 +146,13 @@ async fn initialize_database(
) -> Result<()> { ) -> Result<()> {
// Reserve name before expensive IO (e.g. loading the preserved catalog) // Reserve name before expensive IO (e.g. loading the preserved catalog)
let mut handle = config let mut handle = config
.create_db(db_name) .create_db(db_name.clone())
.map_err(Box::new) .map_err(Box::new)
.context(InitDbError)?; .context(InitDbError)?;
info!(db_name=%db_name, wipe_on_error, skip_replay_and_seek_instead, location=?root,
"Database initialization started");
match try_advance_database_init_process_until_complete( match try_advance_database_init_process_until_complete(
&mut handle, &mut handle,
&root, &root,
@ -159,35 +162,42 @@ async fn initialize_database(
.await .await
{ {
Ok(true) => { Ok(true) => {
info!(db_name=%db_name, "Database initialization completed");
// finished init and keep DB // finished init and keep DB
handle.commit(); handle.commit();
Ok(()) Ok(())
} }
Ok(false) => { Ok(false) => {
info!(db_name=%db_name, "Database initialization finished, but not keeping db");
// finished but do not keep DB // finished but do not keep DB
handle.abort(); handle.abort();
Ok(()) Ok(())
} }
Err(e) => { Err(e) => {
// encountered some error, still commit intermediate result // encountered some error, still commit intermediate result
error!(error=?e, db_name=%db_name, "Database initialization failed");
handle.commit(); handle.commit();
Err(e) Err(e)
} }
} }
} }
async fn load_database_rules(store: Arc<ObjectStore>, path: Path) -> Result<Option<DatabaseRules>> { async fn load_database_rules(
store: Arc<ObjectStore>,
path: &Path,
) -> Result<Option<DatabaseRules>> {
let serialized_rules = loop { let serialized_rules = loop {
match get_database_config_bytes(&path, &store).await { match get_database_config_bytes(path, &store).await {
Ok(data) => break data, Ok(data) => break data,
Err(e) => { Err(e) => {
if let Error::NoDatabaseConfigError { location } = &e { if let Error::NoDatabaseConfigError { location } = &e {
warn!(?location, "{}", e); warn!(?location, "{}", e);
return Ok(None); return Ok(None);
} }
error!( warn!(location=?path, e=?e,
"error getting database config {:?} from object store: {}", "error getting database config from object store, retrying"
path, e
); );
tokio::time::sleep(tokio::time::Duration::from_secs(STORE_ERROR_PAUSE_SECONDS)) tokio::time::sleep(tokio::time::Duration::from_secs(STORE_ERROR_PAUSE_SECONDS))
.await; .await;
@ -295,7 +305,7 @@ async fn try_advance_database_init_process(
DatabaseStateCode::Known => { DatabaseStateCode::Known => {
// known => load DB rules // known => load DB rules
let path = object_store_path_for_database_config(root, &handle.db_name()); let path = object_store_path_for_database_config(root, &handle.db_name());
match load_database_rules(handle.object_store(), path).await? { match load_database_rules(handle.object_store(), &path).await? {
Some(rules) => { Some(rules) => {
handle handle
.advance_rules_loaded(rules) .advance_rules_loaded(rules)
@ -307,6 +317,7 @@ async fn try_advance_database_init_process(
} }
None => { None => {
// no rules file present, advice to forget his DB // no rules file present, advice to forget his DB
info!(location=?path, "Can not find rules file");
Ok(InitProgress::Forget) Ok(InitProgress::Forget)
} }
} }
@ -332,8 +343,8 @@ async fn try_advance_database_init_process(
.context(CreateWriteBuffer { .context(CreateWriteBuffer {
config: rules.write_buffer_connection.clone(), config: rules.write_buffer_connection.clone(),
})?; })?;
info!(write_buffer_enabled=?write_buffer.is_some(), db_name=rules.db_name(), "write buffer config");
info!(write_buffer_enabled=?write_buffer.is_some(), db_name=rules.db_name(), "write buffer configured");
handle handle
.advance_replay(preserved_catalog, catalog, replay_plan, write_buffer) .advance_replay(preserved_catalog, catalog, replay_plan, write_buffer)
.map_err(Box::new) .map_err(Box::new)