Skip to content

Introduce executor.Coordinator and split up responsibilities between Coordinator/Service/executor#536

Merged
mrnugget merged 16 commits into
mainfrom
mrn/refactor-statuses
May 19, 2021
Merged

Introduce executor.Coordinator and split up responsibilities between Coordinator/Service/executor#536
mrnugget merged 16 commits into
mainfrom
mrn/refactor-statuses

Conversation

@mrnugget

@mrnugget mrnugget commented May 12, 2021

Copy link
Copy Markdown
Contributor

On the quest to making caching more flexible (see https://github.com/sourcegraph/sourcegraph/issues/20850) I dug into the executor, TaskStatus, Service and how all the things fit together. This is the result of that digging. Hopefully it improves the clarity in the codebase by pulling apart some of the things that have been mixed together over time: caching, execution of steps, updating of task statuses.

It's also a follow-up to #535 in which I left a bunch of TODOs lying around. These are now gone.

And it also contains @eseliger's fix from #539.


Now, what's in here?

I introduced another entity in the executor package: the Coordinator. Its job is to coordinate the execution of a batch spec: kick off the executor that does the actual execution of steps, check the cache before and save the results to the cache after, go through the importChangesets statements.

This separation lets us write clearer tests: the executor tests are now only about the execution of steps and the coordinator tests now test the creation and caching of changeset specs, which the executor knows nothing about.

(Sidenote: a better name for the executor package would now be execution because it would give us: execution.NewCoordinator as identifier)

Out of necessity I also had to change how the updating of TaskStatuses works. I have some more ideas for the future (how about updates to a task are published on a channel instead of sharing the whole slice of all TaskStatus behind a mutex?).

Base automatically changed from mrn/explicit-caching to main May 14, 2021 08:32
@mrnugget mrnugget force-pushed the mrn/refactor-statuses branch 2 times, most recently from 5e73bf8 to fd560a2 Compare May 14, 2021 10:35
@mrnugget mrnugget changed the title refactor status stuff Introduce executor.Coordinator and split up responsibilities between Coordinator/Service/executor May 17, 2021
@mrnugget mrnugget marked this pull request as ready for review May 18, 2021 09:46
@mrnugget mrnugget force-pushed the mrn/refactor-statuses branch from 81d1153 to 5a92db3 Compare May 18, 2021 09:51
@mrnugget mrnugget requested a review from a team May 18, 2021 09:51
@@ -0,0 +1,313 @@
package executor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nothing changed in this file. I only moved the test here from executor_test.go

// Update the status of Task
status.Update(taskResult.task, func(status *TaskStatus) {
status.ChangesetSpecs = specs
// TODO(mrnugget): Ideally we'd get rid of this dependency on the task

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reason we still have this dependency is that we log information about the diff in the TUI.

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work! 🧹 I like how this code base is taking some nice shape :)

@LawnGnome LawnGnome left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is a really powerful new concept! Great job! 👍

Are there any background documents on docs.sourcegraph.com that we need to update/write as a result of this?

)

func createChangesetSpecs(task *Task, result executionResult, features batches.FeatureFlags) ([]*batches.ChangesetSpec, error) {
func createChangesetSpecs(task *Task, result executionResult, autoAuthorDetails bool) ([]*batches.ChangesetSpec, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't change this, but as a note to myself, I have to update #538 since it was relying on the features being drilled through to this function. 😬

Comment thread internal/batches/executor/coordinator.go Outdated
Comment on lines +52 to +55
var s []*TaskStatus
for _, status := range tsc.statuses {
s = append(s, status)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to shallow copy the statuses, since the read lock is still going to be held until after callback(s) returns anyway?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is just copy and pasted from the old method, so I didn't chnage it. I'm not 100% sure we still need it. Will investigate in a separate branch (because I'm scared of this part of the codebase)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, the reason we do the copy of the pointers is because tsc.statuses is a map[*Task]*TaskStatus, not a slice.

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>
@mrnugget mrnugget merged commit d6c876c into main May 19, 2021
@mrnugget mrnugget deleted the mrn/refactor-statuses branch May 19, 2021 08:12
scjohns pushed a commit that referenced this pull request Apr 24, 2023
…Coordinator/Service/executor (#536)

* Broken build with TaskStatusHubThing

* Introduce Coordinator

* Replace TaskStatusHubThing with TaskStatusCollection

* Clean up the executor

* Clean up handling of ExecutionOpts

* Fix missing rename

* Make executor property and status a runtime arg

* Create separate tests for Coordinator

* Fix tests for Coordinator

* More test cleanup

* Re-add missing test

* Re-add transfromGroup test but its passing, what

* Add test for transform group

* Add test helpers

* Backport fix from #539

* Update internal/batches/executor/coordinator.go

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>

Co-authored-by: Adam Harvey <aharvey@sourcegraph.com>
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.

3 participants