-
Notifications
You must be signed in to change notification settings - Fork 42
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
[oximeter] Policy to redirect DB reads #7522
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this, it looks like a great start!
I have two general naming suggestions. First, I think we should use read
instead of reads
everywhere. "Reads" sounds like a verb to me, and read
/write
seems like a more familiar pair of terms than reads
/writes
.
Second, I think (but please correct me if I'm mistaken) that your version
field is basically a generation number, so I think it should be called generation
(or something like that) and use the provided Generation
API types. We seem to be converging on semantic versions everywhere, so I think the term version
should probably be reserved for those.
sql_query( | ||
r"INSERT INTO oximeter_reads_policy | ||
(version, oximeter_reads_mode, time_created) | ||
SELECT $1, $2, $3 | ||
FROM oximeter_reads_policy WHERE version = $4 AND version IN | ||
(SELECT version FROM oximeter_reads_policy | ||
ORDER BY version DESC LIMIT 1)", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally up to you, but if you want to stick to the diesel typed universe, @jgallagher just showed me how to wrangle basically this same query in #7518.
.authorize(authz::Action::Modify, &authz::BLUEPRINT_CONFIG) | ||
.await?; | ||
|
||
let num_inserted = if policy.version == 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again completely up to you, but I initially had this same kind of no-rows/some-rows split in #7518, and found that it simplified a lot of things to insert a default row (single_node
in this case, probably) as part of the schema migration so that there was always guaranteed to be at least one row.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @plotnick!
I have two general naming suggestions. First, I think we should use read instead of reads everywhere. "Reads" sounds like a verb to me, and read/write seems like a more familiar pair of terms than reads/writes.
Yeah, that makes sense. Now that I look at it I don't really know why I used "reads" in the first place 😄
Second, I think (but please correct me if I'm mistaken) that your version field is basically a generation number, so I think it should be called generation (or something like that) and use the provided Generation API types. We seem to be converging on semantic versions everywhere, so I think the term version should probably be reserved for those.
Hm, I used "version" because I saw it being used in other places https://github.com/oxidecomputer/omicron/blob/main/nexus/db-model/src/deployment.rs#L113-L117 https://github.com/oxidecomputer/omicron/blob/main/nexus/db-model/src/deployment.rs#L60-L70 https://github.com/oxidecomputer/omicron/blob/main/nexus/db-model/src/clickhouse_policy.rs#L31-L37 🤔
@@ -17,7 +17,7 @@ use std::collections::BTreeMap; | |||
/// | |||
/// This must be updated when you change the database schema. Refer to | |||
/// schema/crdb/README.adoc in the root of this repository for details. | |||
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(123, 0, 0); | |||
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(124, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: Make sure this version is still correct at time of merging
Closes: #7420