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

resource scheduler: implement first stage #8001

Closed
wants to merge 23 commits into from

Conversation

sanderr
Copy link
Contributor

@sanderr sanderr commented Aug 23, 2024

Description

First stage of the resource scheduler (#8007, ZenHub epic). Focus is mainly on the data structures for model state and scheduled work, and the algorithms to update that state when a new version comes in or as tasks are executed.

There is still some polishing to do. I propose to delegate that to #8008. That means that the focus of this review is on the stability of the server and agent interfaces, so that work on those will not conflict with further refinements in #8008.

Of course, feel free to already leave feedback for the other parts, I'll make sure to include it in #8008. I've already marked a lot of notes to self in the code as FIXME[#8008].

Please make sure to also consider the module structure. Do you agree that inmanta.deploy makes sense as a namespace?

closes #7548

Self Check:

Strike through any lines that are not applicable (~~line~~) then check the box

  • Attached issue to pull request
  • Changelog entry
  • Type annotations are present
  • Code is clear and sufficiently documented
  • No (preventable) type errors (check using make mypy or make mypy-diff)
  • Sufficient test cases (reproduces the bug/tests the requested feature) -> resource scheduler: polish scheduling algorithm #8008
  • Correct, in line with design
  • End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )
  • If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see test-fixes for more info)

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'd suggest to start your review here and to follow the flow from there.

@sanderr sanderr requested a review from wouterdb August 23, 2024 16:28
Copy link
Contributor

@wouterdb wouterdb left a comment

Choose a reason for hiding this comment

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

Cool stuff

src/inmanta/deploy/scheduler.py Show resolved Hide resolved
src/inmanta/deploy/scheduler.py Show resolved Hide resolved
src/inmanta/deploy/scheduler.py Outdated Show resolved Hide resolved
src/inmanta/deploy/scheduler.py Outdated Show resolved Hide resolved
src/inmanta/util/collections.py Outdated Show resolved Hide resolved
src/inmanta/util/collections.py Show resolved Hide resolved
src/inmanta/deploy/work.py Show resolved Hide resolved
src/inmanta/deploy/work.py Show resolved Hide resolved
src/inmanta/deploy/work.py Show resolved Hide resolved

:param ensure_scheduled: Set of resources that should be deployed. Adds a deploy task to the scheduled work for each
of these, unless it is already scheduled.
:param running_deploys: Set of resources for which a deploy is currently running, for the latest desired state, i.e.
Copy link
Contributor

Choose a reason for hiding this comment

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

this I don't understand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a bit of a last-minute addition, may need more refinement. I'll see what I can do in #8008 and if nothing else I'll clarify it there.

@sanderr sanderr changed the title Issue/resource scheduler resource scheduler: implement first stage Aug 28, 2024
@sanderr sanderr requested a review from wouterdb August 28, 2024 08:52
@sanderr
Copy link
Contributor Author

sanderr commented Aug 28, 2024

@wouterdb I updated the description with some more context.

@sanderr sanderr marked this pull request as ready for review August 28, 2024 08:52
@sanderr sanderr requested a review from arnaudsjs August 28, 2024 08:52
src/inmanta/deploy/scheduler.py Show resolved Hide resolved
src/inmanta/util/collections.py Outdated Show resolved Hide resolved
Comment on lines +22 to +26
P = TypeVar("P", bound=Hashable)
S = TypeVar("S", bound=Hashable)
# type vars not bound to the class
K = TypeVar("K", bound=Hashable)
V = TypeVar("V", bound=Hashable)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can use some comments. Single character type names are very to interpret.

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 found it hard to come up with meaningful names here. I changed it to the conventional S and T now. I'm not sure comments would be helpful, since the names really don't have much meaning.

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 you get notified about these comments, no need to look at them now, I'll make sure to link here from the new PR.)

self.set_primary(key, values)

@staticmethod
def _set(primary: dict[K, set[V]], reverse: dict[V, set[K]], key: K, values: Set[V]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

This method can use documentation.



# TODO: better name?
class BidirectionalManyToManyMapping(MutableMapping[P, Set[S]], Generic[P, S]):
Copy link
Contributor

Choose a reason for hiding this comment

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

This class can use a docstring.

Comment on lines +113 to +116
# can not drop tasks from queue without breaking the heap invariant, or potentially breaking asyncio.Queue invariants
# => take approach suggested in heapq docs: simply mark as deleted.
# => Keep view on all active tasks for a given resource, which also doubles as lookup for client operations
# Only tasks in this collection are considered queued, as far as this class' client interface is concerned.
Copy link
Contributor

Choose a reason for hiding this comment

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

This part I don't understand. Where does the problem with the deletion come from? As far as I can see the documentation of the PriorityQueue class doesn't say anything about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed it does not, but the heapq documentation does: https://docs.python.org/3/library/heapq.html#priority-queue-implementation-notes

And indeed, asyncio.PriorityQueue doesn't offer a remove method or similar.

src/inmanta/deploy/scheduler.py Outdated Show resolved Hide resolved
# short, synchronous operations (and therefore we wouldn't gain anything by allowing multiple readers).
self._scheduler_lock: asyncio.Lock = asyncio.Lock()
# - lock to serialize scheduler state updates (i.e. process new version)
self._update_lock: asyncio.Lock = asyncio.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self._update_lock: asyncio.Lock = asyncio.Lock()
self._desired_state_lock: asyncio.Lock = asyncio.Lock()

@sanderr
Copy link
Contributor Author

sanderr commented Aug 30, 2024

@arnaudsjs thanks for the review. I committed the bugfix suggestion you commented, but I'm leaving the rest of your comments for #8008 to unstuck @hlloreda for #8009.

@sanderr sanderr requested review from arnaudsjs and removed request for arnaudsjs August 30, 2024 12:09
@sanderr sanderr added the merge-tool-ready This ticket is ready to be merged in label Aug 30, 2024
@inmantaci
Copy link
Contributor

Processing this pull request

@inmantaci inmantaci removed the merge-tool-ready This ticket is ready to be merged in label Aug 30, 2024
@inmantaci
Copy link
Contributor

Pull request rejected by merge tool. This pull request has not been approved yet.

@sanderr sanderr dismissed arnaudsjs’s stale review August 30, 2024 13:55

Merging ASAP to unblock next tasks. #8008 will process final review comments.

@sanderr sanderr added the merge-tool-ready This ticket is ready to be merged in label Aug 30, 2024
@inmantaci
Copy link
Contributor

Processing this pull request

@inmantaci
Copy link
Contributor

Merged into branches master in d09c832

inmantaci pushed a commit that referenced this pull request Aug 30, 2024
# Description

First stage of the resource scheduler (#8007, [ZenHub epic](https://app.zenhub.com/workspaces/core-5a7c152b04a1652024289b7b/issues/gh/inmanta/inmanta-core/8007)). Focus is mainly on the data structures for model state and scheduled work, and the algorithms to update that state when a new version comes in or as tasks are executed.

There is still some polishing to do. I propose to delegate that to #8008. That means that the focus of this review is on the stability of the server and agent interfaces, so that work on those will not conflict with further refinements in #8008.

Of course, feel free to already leave feedback for the other parts, I'll make sure to include it in #8008. I've already marked a lot of notes to self in the code as `FIXME[#8008]`.

Please make sure to also consider the module structure. Do you agree that `inmanta.deploy` makes sense as a namespace?

closes #7548

# Self Check:

Strike through any lines that are not applicable (`~~line~~`) then check the box

- [x] Attached issue to pull request
- [x] Changelog entry
- [x] Type annotations are present
- [x] Code is clear and sufficiently documented
- [x] No (preventable) type errors (check using make mypy or make mypy-diff)
- [x] ~~Sufficient test cases (reproduces the bug/tests the requested feature)~~ -> #8008
- [x] Correct, in line with design
- [x] ~~End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )~~
- [x] ~~If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)~~
@inmantaci inmantaci closed this Aug 30, 2024
@inmantaci inmantaci deleted the issue/resource-scheduler branch August 30, 2024 14:30
inmantaci pushed a commit that referenced this pull request Sep 24, 2024
# Description

Polished the resource scheduler and addressed todos and review comments from #8001. I attached some comments to the diff with more details / motivation.

Please also have another look at the comments you made in #8001 to see if they have been resolved to your satisfaction.

closes #8008

# Self Check:

Strike through any lines that are not applicable (`~~line~~`) then check the box

- [x] Attached issue to pull request
- [x] Changelog entry
- [x] Type annotations are present
- [x] Code is clear and sufficiently documented
- [x] No (preventable) type errors (check using make mypy or make mypy-diff)
- [x] Sufficient test cases (reproduces the bug/tests the requested feature)
- [x] Correct, in line with design
- [x] ~~End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )~~
- [x] ~~If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-tool-ready This ticket is ready to be merged in
Projects
None yet
Development

Successfully merging this pull request may close these issues.

agent rework: deploy sequencing first steps
4 participants