Skip to content

internal/db: Set database status based on initialization state#319

Merged
roosterfish merged 1 commit into
canonical:v3from
bschimke95:bschimke95/initial-db-state
Jan 24, 2025
Merged

internal/db: Set database status based on initialization state#319
roosterfish merged 1 commit into
canonical:v3from
bschimke95:bschimke95/initial-db-state

Conversation

@bschimke95
Copy link
Copy Markdown
Contributor

@bschimke95 bschimke95 commented Jan 22, 2025

Previously, the initial dqlite database status was always set to "DatabaseNotReady", regardless of whether the node was already bootstrapped or joined. As a result, any REST API call during microcluster startup would incorrectly return a 503 error with "Database not yet initialized", even if the node was already bootstrapped and simply restarting.

This commit refactors the handling of the database initialization state:

  • Use the database status to determine if a cluster is
    bootstrapped/joined or uninitialized
  • Sets the initial database status based on whether the database is already initialized.

With this change:

  • Bootstrapped nodes now return "Database still starting" during startup.
  • Non-bootstrapped nodes return "Database not yet initialized".

This provides more accurate status reporting and improves API responses during service restarts.

@bschimke95 bschimke95 force-pushed the bschimke95/initial-db-state branch 2 times, most recently from 29cec27 to 5a99e42 Compare January 22, 2025 11:45
Copy link
Copy Markdown
Contributor

@roosterfish roosterfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. A few minor nits for consistency.

To be more precise with the effect of this change, basically every API request to the Unix socket endpoints (as well as core and extension) will return the "not initialized" error until StartAPI->StartWithCluster->Join is called which will set the DB's status to "starting" for a very short period of time and then switches to its final running state.

Comment thread internal/daemon/daemon.go Outdated
Comment thread internal/db/dqlite.go Outdated
@bschimke95 bschimke95 force-pushed the bschimke95/initial-db-state branch from a4cc78d to 0961800 Compare January 23, 2025 07:26
Copy link
Copy Markdown
Contributor

@roosterfish roosterfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more minor comments, the change itself looks great.

Comment thread internal/db/dqlite.go Outdated
Comment thread internal/daemon/daemon.go Outdated
Previously, the initial dqlite database status was always set to "DatabaseNotReady",
regardless of whether the node was already bootstrapped or joined.
As a result, any REST API call during microcluster startup would incorrectly return a 503 error
with "Database not yet initialized", even if the node was already bootstrapped and simply restarting.

This commit refactors the handling of the database initialization state:

* Use the database status to determine if a cluster is
  bootstrapped/joined or uninitialized
* Sets the initial database status based on whether the database is already initialized.

With this change:

* Bootstrapped nodes now return "Database still starting" during startup.
* Non-bootstrapped nodes return "Database not yet initialized".

This provides more accurate status reporting and improves API responses during service restarts.

Signed-off-by: Benjamin Schimke <benjamin.schimke@canonical.com>
@bschimke95 bschimke95 force-pushed the bschimke95/initial-db-state branch from 0961800 to ccaa40d Compare January 24, 2025 10:22
Copy link
Copy Markdown
Contributor

@roosterfish roosterfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@roosterfish roosterfish merged commit def4810 into canonical:v3 Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants