Skip to content

Conversation

Jamesbarford
Copy link
Contributor

Make the parent sha null if it does not refer to a tag in the benchmark_request table. This prevents a foreign key violation when subsequently trying to create jobs for back filling.

.conn()
.query_one(
"SELECT tag FROM benchmark_request WHERE tag = $1",
&[&benchmark_request.parent_sha()],
Copy link
Member

Choose a reason for hiding this comment

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

If the parent SHA is NULL (which will happen for try builds), tag = NULL will return NULL, which will be interpreted as false, right? Then the query_one call will fail.

Copy link
Member

Choose a reason for hiding this comment

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

The same would happen if the parent SHA was actually missing in the DB. We'll need to use e.g. query, not query_one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Judging by a raft of tests failing 😓. Yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if I like what I have done here but it does achieve what we want and should only be temporary; 68d0d87

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 will most likely mean that all parent_sha's will be null when initially starting the CRON. At least this is what I have observed locally.

@Jamesbarford Jamesbarford force-pushed the fix/null-out-parent-if-not-exists branch from 68d0d87 to 1acbb5b Compare September 22, 2025 10:36
@Kobzol
Copy link
Member

Kobzol commented Sep 22, 2025

Thinking about this a bit more, it would be better if this change was actually not only temporary; ideally, the system should be able to bootstrap itself even if we restart/redeploy it on some other server, or if we run it locally, otherwise we couldn't easily test the new job queue locally if it would be throwing the FK errors all the time.

So we should always count with the possibility that the parent commit might be missing.

I didn't like the option of modifying the benchmark request first, and wanted to only modify the creation of jobs, but after some experiments I did on the code, I guess it kind of makes sense. The master commit might not in fact have a parent available, because the git tree has to stop somewhere, so representing it by making the master parent SHA nullable kinda makes sense.

We should make use of the benchmark request index though. Rather than doing an extra SQL query, we can iterate the master commits in reverse order (from the oldest to the newest), and when we run into a request whose parent is not in the index, we will forcefully set the parent SHA to NULL. That should resolve the issue with the job queue. We will then ofc have to update the index in memory while we insert the master benchmark requests, but that shouldn't be an issue - we can clone it at the beginning of the cron job, and then mutate it while inserting the master requests.

let db = ctx.db();

// Releases don't need parent shas
ctx.insert_release_request("parent-sha-1").await;
Copy link
Member

Choose a reason for hiding this comment

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

We don't currently check against it, but a release request cannot be the parent of anything. So I'd rather not have this situation in tests.

Copy link
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Thanks, looks good! (Apart from CI failures, ofc xD)

@Jamesbarford Jamesbarford force-pushed the fix/null-out-parent-if-not-exists branch from c253a78 to fbba36c Compare September 22, 2025 14:52
@Jamesbarford
Copy link
Contributor Author

This PR is superseded by; #2255

@Kobzol Kobzol closed this Sep 23, 2025
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.

2 participants