Skip to content
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

Need to initialize a fresh ClickHouse database without restarting Oximeter #6826

Open
plotnick opened this issue Oct 10, 2024 · 5 comments · May be fixed by #6903
Open

Need to initialize a fresh ClickHouse database without restarting Oximeter #6826

plotnick opened this issue Oct 10, 2024 · 5 comments · May be fixed by #6903
Assignees
Milestone

Comments

@plotnick
Copy link
Contributor

With #6800, we can now expunge a running ClickHouse zone and the reconfigurator will replace it. With #6745, qorb can automatically look up and connect to that new zone, but insertions still fail because the oximeter database does not yet exist:

21:19:19.250Z WARN oximeter (oximeter-agent): failed to insert some results into metric DB: Error interacting with telemetry database: Query failed: Code: 81. DB::Exception: Database oximeter does not exist. (UNKNOWN_DATABASE) (version 23.8.7.1)

I don't know if a client can initialize a non-existent database in ClickHouse. If it can, we may be able to solve this on the client side; if not, we'll need some server-side initialization scheme. See also this comment, where this issue came up previously.

@plotnick
Copy link
Contributor Author

Update: ClickHouse can indeed add new databases from the client, and indeed we already do so when initializing the Oximeter client. The question now is how and at what level to detect an unitialized database; i.e., entirely in the client, or in cooperation with qorb.

@jgallagher
Copy link
Contributor

It looks like this happens here on main:

// Determine the version of the database.
//
// There are three cases
//
// - The database exists and is at the expected version. Continue in
// this case.
//
// - The database exists and is at a lower-than-expected version. We
// fail back to the caller here, which will retry indefinitely until the
// DB has been updated.
//
// - The DB doesn't exist at all. This reports a version number of 0. We
// need to create the DB here, at the latest version. This is used in
// fresh installations and tests.
let client = Client::new(db_address, &log);
match client.check_db_is_at_expected_version().await {

#6745 changes this slightly: instead of Client::new(db_address, ...) it becomes Client::new_with_pool(resolver, ...), which means we grab a connection out of the Qorb pool, then perform this db check, but only on initial startup. A Qorb pool can choose to implement on_acquire(). I wonder if instead of "acquire a client from the pool, check the database, then proceed assuming it never changes" it makes sense to make it "upon acquiring any client from the pool check the database, then use the client ..."? cc @smklein

I don't know what the implications are of "any time qorb gets a new connection, potentially try to create the db schema". That seems like the kind of thing that could go sideways, maybe?

@bnaecker
Copy link
Collaborator

bnaecker commented Oct 11, 2024 via email

@plotnick plotnick self-assigned this Oct 14, 2024
@davepacheco
Copy link
Collaborator

Would it make sense to make this part of Reconfigurator's action to add the new zone?

@bnaecker
Copy link
Collaborator

@davepacheco I think that makes sense, yeah. If we have information about the database we need to create (replicated or single-node) in the blueprint, then we can run it as part of creating the zone. In the long-run, having clickhouse-admin do that as part of starting up the actual ClickHouse server makes sense. I'm not sure if that's how a the discretionary ClickHouse zones will be launched. But either way, it seems pretty straightforward to run a few lines of code using the oximeter_db::Client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants