Skip to content

Add job delete support #4717

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Add job delete support #4717

wants to merge 10 commits into from

Conversation

bcl
Copy link
Contributor

@bcl bcl commented May 7, 2025

This pull request includes:

  • adequate testing for the new functionality or fixed issue
  • adequate documentation informing people about the change such as
    • submit a PR for the READMEs listed here
    • submit a PR for the osbuild.org website repository if this PR changed any behavior not covered by the automatically updated READMEs

@lzap
Copy link
Contributor

lzap commented May 7, 2025

Dropped some random stuff, this is not a review as I do not feel confident to do that yet.

@bcl bcl force-pushed the main-delete-jobs branch 2 times, most recently from eca164d to ab73a24 Compare May 13, 2025 17:07
bcl added 3 commits May 16, 2025 16:06
This allows database entries to be deleted.

Related: RHEL-60120
This allows jobs to be deleted from the database.
Currently only implemented by fsjobqueue. The function for
dbjobqueue currently returns nil.

This will remove all the job files used by the root job UUID as long as
no other job depends on them. ie. It starts at the top, and moves down
the dependency tree until it finds a job that is also used by another
job, removes the job to be deleted from its dependants list, and moves
back up the tree only deleting jobs with empty dependants lists.

Related: RHEL-60120
@bcl bcl force-pushed the main-delete-jobs branch from ab73a24 to 055857f Compare May 16, 2025 23:10
@bcl
Copy link
Contributor Author

bcl commented May 16, 2025

Note that Snyk is wrong, no directory traversal is possible since it uses uuid.Parse() to make sure the id is a uuid not some arbitrary string.

@bcl bcl marked this pull request as ready for review May 16, 2025 23:28
@bcl bcl requested review from thozza and a team as code owners May 16, 2025 23:28
@bcl bcl requested review from mvo5 and achilleas-k and removed request for a team May 16, 2025 23:28
lzap
lzap previously approved these changes May 19, 2025
Copy link
Contributor

@lzap lzap left a comment

Choose a reason for hiding this comment

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

Thanks for adding those contexts.


// Start it off with an empty parent
return q.deleteJobs(ctx, conn, uuid.UUID{}, id)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider creating an explicit transaction here just like in Enqueue.

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 think I can. The functions all take connections or acquire their own from the pool, etc. But I agree that it needs something to lock access. Delete won't run unless the job is finished, so the only thing to worry about is other delete operations so a lock should work.

Copy link
Contributor

@lzap lzap May 20, 2025

Choose a reason for hiding this comment

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

That should not be a blocker, in Go you can create your own Connection interface that will only consist of functions that are in use (Query or QueryRows or both) which is automatically implemented by both Connection and Transaction from the pgx library. Once this is done, they can be reused from non-transaction methods as well, in fact, this is the pattern that should be used everywhere throughout this file because acquiring a new connection from a pool for every single small sub-query is not ideal, slower and error prone (what if someone wants to set a session-based configuration).

Frankly, not a huge fan of this hacky mutex if this breaks it bites hard. Example pseudo-code:

type QueueConnection interface {
  Exec(...)
  Query(...)
  QueryRows(...)
}

func (q *DBJobQueue) deleteJob(ctx context.Context, qc QueueConnection, jobID uuid.UUID) error
func (q *DBJobQueue) deleteJobDependencies(ctx context.Context, qc QueueConnection, jobID, dependencyID uuid.UUID) error
func (q *DBJobQueue) deleteJobs(ctx context.Context, qc QueueConnection, parent, id uuid.UUID) error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How is the mutex going to break? You'd have to call DeleteJob from inside DeleteJob to double lock it. I admit it is a bit of a hack, but so is making complex new interface type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If someone knows how to do this with pure SQL I'd be open to that. My SQL-foo is really rusty.

bcl added 7 commits May 19, 2025 11:33
This adds SQL to delete jobs and dependencies, and implements the
database version of the DeleteJob function.

Related: RHEL-60120
This adds tests for retrieving all root jobs, and deleting jobs
and unused dependencies. These tests are run against the fsjobqueue for
unit testing, and against dbjobqueue for integration testing.

Resolves: RHEL-60120
This removes all artifact directories, and their contents, if there
isn't an associated Job. This is used to clean up local artifacts after
the compose job has been deleted.

Related: RHEL-60120
This will be used to delete jobs and their artifacts.

Related: RHEL-60120
This adds the handler for /composes/delete/UUID which will delete a job and
all of its dependencies, and any artifacts.

Related: RHEL-60120
It was returning a null body instead of an empty list.

Related: RHEL-60120
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