-
Notifications
You must be signed in to change notification settings - Fork 41
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
replace in-memory datastore with a CockroachDB-based one #57
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Apr 13, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The in-memory datastore was always intended just for prototyping, to defer the work of figuring out the database interaction until we had confidence in the bigger architectural pieces. It's time to replace it with a real database.
Compatibility / changes in developer workflow
My goal with this change is to make it as easy to run and test Omicron on CockroachDB as it was with the in-memory store. If you run
omicron_dev db-run
in one terminal to start up a single-node CockroachDB cluster, then you can essentially do everything you used to do with Nexus and Sled Agent, except that the data will be stored in CockroachDB instead of in memory. If you want to wipe the database, you can just stop and startomicron_dev db-run
again -- it deletes its database when it shuts down. (I built it that way to mimic the in-memory version, though it's worth considering if we'd rather have it store data in some well-known directory by default and not delete it.)The test suite uses the same facility to spin up a whole new CockroachDB instance for each test. This may be overkill -- in particular, it would probably be faster to spin up one CockroachDB cluster and use separate databases for each test -- but it works reliably for me and doesn't take very long.
It was tempting to keep the in-memory datastore, but I think that would add a lot more ongoing work. And given how easy it is to spin up single-node CockroachDB clusters that delete their data on clean shutdown, that seems like the better way to go.
In this change
Most of the new stuff is in the src/nexus/db. This is grouped into several files. (This ought to be documented in module-level documentation, but I have not done that yet.)
project_create()
)Other notable changes here:
database.url
property for configuring how to talk to CockroachDB.Arc
. The idea here was that we could cache these. However, our discussion of ORMs and Diesel led me to feeling like we want to discourage code paths that load entire objects most of the time, since that couples them tightly to the current schema. The pattern I'd like to pursue instead are to make more targeted updates. (Seeinstance_update_runtime()
.)i64
because that's what CockroachDB uses for integers.ApiProject
.Unrelated stuff here:
bail_unless!
macro. This is like anyhow's ensure, but it produces anApiError::InternalError
.Future work
There's a ton of future work here.
cockroach cert
to generate real TLS certificates rather than running the local cluster in insecure mode.Table
orLookupKey
traits, or other traits that can be attached to types that impl these.There's a lot more as well.