Skip to content

init db and table, check health #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tankyleo
Copy link

@tankyleo tankyleo commented Aug 15, 2025

Soft-push, seems to be working !

for now check health is just used internally to test the database on startup.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Aug 15, 2025

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tankyleo tankyleo requested a review from tnull August 15, 2025 07:42
Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Took a first look and left some higher-level comments. Have yet to review the actual database statements and operations.

@@ -10,6 +10,7 @@ chrono = "0.4.38"
tokio-postgres = { version = "0.7.12", features = ["with-chrono-0_4"] }
bb8-postgres = "0.7"
bytes = "1.4.0"
tokio = { version = "1.38.0", default-features = false }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need the time feature?

Copy link
Author

Choose a reason for hiding this comment

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

Yes !

@@ -46,17 +62,103 @@ pub struct PostgresBackendImpl {
pool: Pool<PostgresConnectionManager<NoTls>>,
}

async fn initialize_vss_database(postgres_endpoint: &str, db_name: &str) -> Result<(), Error> {
let postgres_dsn = format!("{}/{}", postgres_endpoint, "postgres");
let (client, connection) = tokio_postgres::connect(&postgres_dsn, NoTls).await
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, do we want to expose a way for the user to configure their connection, e.g. to enable TLS?

Copy link
Author

Choose a reason for hiding this comment

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

Yes certainly, though may be out of scope for this PR.

Copy link
Author

@tankyleo tankyleo Aug 15, 2025

Choose a reason for hiding this comment

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

Filed issue #56

let postgres_dsn = format!("{}/{}", postgres_endpoint, "postgres");
let (client, connection) = tokio_postgres::connect(&postgres_dsn, NoTls).await
.map_err(|e| Error::new(ErrorKind::Other, format!("Connection error: {}", e)))?;
// Connection must be driven on separate task, will be dropped on client dropped
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does it need to be driven on separate task? Should we still keep track of this connection handle somewhere? Rather than just printing once and giving up, should we handle the error and/or add a loop to retry the connection?

Copy link
Author

Choose a reason for hiding this comment

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

Why does it need to be driven on a separate task?

From the docs:

A connection to a PostgreSQL database.

This is one half of what is returned when a new connection is established. It performs the actual IO with the server, and should generally be spawned off onto an executor to run in the background.

Connection implements Future, and only resolves when the connection is closed, either because a fatal error has occurred, or because its associated Client has dropped and all outstanding work has completed.

Is that satisfactory to you ?

Should we still keep track of this connection handle somewhere?

The connection future will only resolve when I drop the client, so not sure what I would do with the associated JoinHandle ?

Rather than just printing once and giving up, should we handle the error and/or add a loop to retry the connection?

Since this is part of the startup sequence, I was leaning towards having very little error handling, and failing fast and early. This lets the user know that something is not right.

Then once we are running, do all that we can to keep the show going.

std::process::exit(1);
}
let init_db = args.contains(&String::from("--init-db"));
Copy link
Contributor

Choose a reason for hiding this comment

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

If you cast to slice directly, why allocate a String first?

Copy link
Author

Choose a reason for hiding this comment

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

contains on a Vec<String> wants a &String specifically.

But we can replace this with args.iter().any(|arg| arg == "--init-db")

@tankyleo
Copy link
Author

A possible todo I thought of: right now our TABLE_CHECK_STMT SELECT 1 FROM vss_db WHERE false merely checks whether a vss_db table exists in the database. We could have a deeper check of all the columns in the table etc...

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.

3 participants