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

Add internal "pilot" concept #627

Merged
merged 1 commit into from
Oct 4, 2024
Merged

Add internal "pilot" concept #627

merged 1 commit into from
Oct 4, 2024

Conversation

bgentry
Copy link
Contributor

@bgentry bgentry commented Sep 29, 2024

This builds out a new layer to sit between the Client and Driver, focused more on higher level operations than individual database queries. This allows those operations to be implemented with a combination of multiple database queries in a transaction, rather than just a single one.

Naming here was tough, I really didn't like any of the options I came up with and ultimately landed on "pilot", but I'm pretty indifferent to it if a truly good one can be found. I spent enough time trying to find a good one that I truly don't care at this point 😆

For now, the only operations implemented in the pilot are InsertMany and JobSetStateIfRunningMany (from the completer). I also made some changes within River to use these at the correct places and to propagate the pilot as needed. JobCompleteTx was updated to pull a Client out of the context in order to access this and use the same underlying query (via the pilot) as the BatchCompleter.

Based on #614 (including #624).

@bgentry bgentry requested a review from brandur September 29, 2024 22:23
@bgentry bgentry force-pushed the bg-remove-advisory-lock-unique-jobs branch 2 times, most recently from 95d5825 to 6264e3f Compare September 30, 2024 22:58
@bgentry bgentry force-pushed the bg-remove-advisory-lock-unique-jobs branch from 6264e3f to 182dfb4 Compare October 4, 2024 00:53
Base automatically changed from bg-remove-advisory-lock-unique-jobs to master October 4, 2024 01:03
This builds out a new higher level layer to sit between the Client and
Driver, focused more on higher level operations than individual database
queries. This allows those operations to be implemented with a
combination of multiple database queries in a transaction, rather than
just a single one.

Naming here was tough, I really didn't like any of the options I came up
with and ultimately landed on "pilot", but I'm pretty indifferent to it
if a truly good one can be found.

For now, the only operations implemented in the pilot are `InsertMany`
and `JobSetStateIfRunningMany` (from the completer). I also made some
changes within River to use these at the correct places and to propagate
the pilot as needed. `JobCompleteTx` was updated to pull a `Client` out
of the context in order to access this and use the same underlying query
(via the pilot) as the `BatchCompleter`.
@bgentry bgentry force-pushed the bg-proof-out-pilot branch from 0fd29f5 to 13ab563 Compare October 4, 2024 01:04
}
defer tx.Rollback(ctx)

rows, err := c.pilot.JobSetStateIfRunningMany(ctx, tx, batchParams)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The choice here was to either wrap this with a transaction before calling into the pilot method, or to do so within it. I opted for the former primarily because it seemed to simplify the interfaces related to the driver system and avoid having to make the pilot type generic with TTx.

Open to changing any of this of course as long as it lets us do what we need to do!

Comment on lines 28 to +29
type partialExecutorMock struct {
riverdriver.Executor
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 now a full executor, but one that allows specific methods to be overridden. A tx variant of it was also needed because of the txn change in the completer.

Comment on lines +105 to +107
func serviceName(service startstop.Service) string {
elem := reflect.TypeOf(service).Elem()
return elem.PkgPath() + "." + elem.Name()
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 made this change to the make the internal names more unique because I had originally had two pro maintenance processes with the same name in different packages, and I lost a fair bit of time trying to figure out why one of them wasn't working. I don't think there are downsides/risks here other than just the internal name being the longer & more complicated path+type combo since it's only used internally.

"github.com/riverqueue/river/rivertype"
)

type StandardPilot struct {
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 one is just a passthrough to the driver queries as of now.

@bgentry
Copy link
Contributor Author

bgentry commented Oct 4, 2024

I'd still call this a bit of a work in progress and I think it will evolve or even change significantly, but for now I think it's good enough to move forward and iterate on.

@bgentry bgentry merged commit 5dd7f7c into master Oct 4, 2024
14 checks passed
@bgentry bgentry deleted the bg-proof-out-pilot branch October 4, 2024 01:19
@nexovec
Copy link

nexovec commented Oct 4, 2024

Would you mind telling me what this is even for? The implementation is basically empty now, what's the pilot supposed to be doing?

@bgentry
Copy link
Contributor Author

bgentry commented Oct 4, 2024

@nexovec essentially we need a way to be able to override or extend certain functions with more complex implementations to power upcoming River Pro features. Our "driver" concept mainly exists to power low level queries across different database engines with query or type differences, so abusing/reusing that concept for something like a higher level grouping of functionality didn't feel appropriate, hence the added layer. As of now the "pilot" in the OSS version is just a passthrough to the driver, I'm not sure whether that will change or not in the future, though it's unlikely to be anything users need to care about.

@nexovec
Copy link

nexovec commented Oct 5, 2024

So it's something for workflows?

@bgentry
Copy link
Contributor Author

bgentry commented Oct 6, 2024

Not currently being used for workflows, no. But yes for the next Pro feature and some of the ones after that 🚀

tigrato pushed a commit to gravitational/river that referenced this pull request Dec 18, 2024
This builds out a new higher level layer to sit between the Client and
Driver, focused more on higher level operations than individual database
queries. This allows those operations to be implemented with a
combination of multiple database queries in a transaction, rather than
just a single one.

Naming here was tough, I really didn't like any of the options I came up
with and ultimately landed on "pilot", but I'm pretty indifferent to it
if a truly good one can be found.

For now, the only operations implemented in the pilot are `InsertMany`
and `JobSetStateIfRunningMany` (from the completer). I also made some
changes within River to use these at the correct places and to propagate
the pilot as needed. `JobCompleteTx` was updated to pull a `Client` out
of the context in order to access this and use the same underlying query
(via the pilot) as the `BatchCompleter`.
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