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

[crdb-seed] use a tarball, fix omicron-dev run-all #4208

Merged

Conversation

sunshowers
Copy link
Contributor

@sunshowers sunshowers commented Oct 5, 2023

Several changes:

  1. In Make crdb-seed more robust to missing files #4193, @david-crespo observed some missing files in the crdb-seed generated directory. My suspicion is that that is due to the /tmp cleaner that runs on macOS. @davepacheco suggested using a tarball to get atomicity (either the file exists or it doesn't), and it ended up being pretty simple to do that at the end.
  2. Teach nexus-test-utils to ensure that the seed tarball exists, fixing omicron-dev run-all and anything else that uses nexus-test-utils (and avoiding a dependency on the environment).
  3. Move crdb-seed to dev-tools (thanks Dave for pointing it out!)
  4. Add a way to invalidate the cache with CRDB_SEED_INVALIDATE=1 in the environment.
  5. Add a readme for crdb-seed.

Fixes #4206.

Hopefully addresses #4193.

Created using spr 1.3.4
Created using spr 1.3.4
Created using spr 1.3.4
@sunshowers sunshowers requested a review from smklein October 5, 2023 01:04
@sunshowers
Copy link
Contributor Author

I tried migrating the function to anyhow so I could get better debugging, but couldn't get all the way -- there are still some .expects littered in there. Hopefully that isn't too much of a problem since this is test-only code.

Copy link
Collaborator

@smklein smklein left a comment

Choose a reason for hiding this comment

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

LGTM, leaving this as a single artifact seems simpler to manage.

Seems like we'd still be at-risk of a /tmp cleaner deleting this directory, say, "after nextest setup begins, but before the test executes", but I'm not sure we can ever deal with that problem while still using /tmp.

crdb-seed/Cargo.toml Outdated Show resolved Hide resolved
crdb-seed/Cargo.toml Outdated Show resolved Hide resolved
}

// TODO: switch to anyhow entirely -- this function is currently a mishmash
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to clarify, this appears to already be using an anyhow::Result?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is currently a mishmash of anyhow::Result and unwrap/expect. I've expanded the comment to make this clearer.

@sunshowers
Copy link
Contributor Author

I also added a way to invalidate the cache with CRDB_SEED_INVALIDATE=1. Any idea if/where this is worth documenting?

Created using spr 1.3.4
@smklein
Copy link
Collaborator

smklein commented Oct 5, 2023

I also added a way to invalidate the cache with CRDB_SEED_INVALIDATE=1. Any idea if/where this is worth documenting?

A help message for the crdb-seed binary would help -- we could also document NEXTEST_ENV usage there too?

@sunshowers
Copy link
Contributor Author

A help message for the crdb-seed binary would help -- we could also document NEXTEST_ENV usage there too?

Hmm, any thoughts on checking that argv[1] is --help vs just pulling in clap for that? clap seems a little overkill.

Maybe we could also add a README.

Created using spr 1.3.4
@sunshowers sunshowers changed the title [crdb-seed] use a tarball rather than a directory [crdb-seed] use a tarball, fix omicron-dev run-all Oct 5, 2023
@sunshowers sunshowers requested a review from smklein October 5, 2023 23:41
@sunshowers
Copy link
Contributor Author

Requesting review again because I added a bunch of new stuff to the PR.

Created using spr 1.3.4
Copy link
Collaborator

@smklein smklein left a comment

Choose a reason for hiding this comment

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

LGTM, mod one comment clarifying mtimes!

Comment on lines 71 to 84
/// This method should _not_ be used by tests. Instead, rely on the `crdb-seed`
/// setup script.
pub async fn ensure_seed_tarball_exists(
log: &Logger,
why_invalidate: Option<&str>,
) -> Result<(Utf8PathBuf, SeedTarballStatus)> {
// If the CRDB_SEED_TAR_ENV variable is set, return an error.
if let Ok(val) = std::env::var(CRDB_SEED_TAR_ENV) {
anyhow::bail!(
"{CRDB_SEED_TAR_ENV} is set to `{val}` -- implying that a test called \
ensure_seed_tarball_exists. Instead, tests should rely on the `crdb-seed` \
setup script."
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a bit of a proxy for #[ifcfg(not(test))] -- is that too extreme of a conditional qualifier to put on this method?

It does seem like it would make crdb-seed, the binary, untestable, but I think it would enforce more accurately what the comments are describing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a dependency (not a leaf node) so I don't think cfg(not(test)) would work? And if I try gating it behind a feature flag, the issue would be that omicron-dev needs this function and so feature unification would mean this gets included in test binaries if you're doing a top-level cargo test.

Copy link
Contributor Author

@sunshowers sunshowers Oct 6, 2023

Choose a reason for hiding this comment

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

Actually, I ended up both preserving this check and gating it behind a feature flag. So we're triply sure this module isn't used by code other than omicron-dev and crdb-seed.

Comment on lines 108 to 111
std::fs::OpenOptions::new()
.append(true)
.open(&desired_seed_tar)
.context("failed to touch seed tarball")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this sufficient to update mtime, if the file exists? If the file already exists, but nothing is written, I would have suspected that this does not update the underlying timestamp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really really good catch, thank you. I think I may end up using the filetime crate as in https://github.com/uutils/coreutils/blob/a596cda51612e72b5245ccb8c2fa6c05a89569a7/src/uu/touch/src/touch.rs#L205-L207.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, the filetime crate works great.

Comment on lines 127 to 128
// The tarball didn't exist when we started, so try to create it.
//
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: the tarball no longer exists

If why_invalidated is Some, it might have existed, but been removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Expanded this comment:

    // At this point the tarball does not exist (either because it didn't exist
    // in the first place or because it was deleted above), so try to create it.

Created using spr 1.3.4
@sunshowers sunshowers enabled auto-merge (squash) October 6, 2023 23:48
Created using spr 1.3.4
@sunshowers sunshowers merged commit 9f004d2 into main Oct 7, 2023
23 checks passed
@sunshowers sunshowers deleted the sunshowers/spr/crdb-seed-use-a-tarball-rather-than-a-directory branch October 7, 2023 04:11
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.

omicron-dev run-all relies on CRDB_SEED_DIR
2 participants