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

Dispatcher cleanup #3025

Merged
merged 5 commits into from
Feb 26, 2019
Merged

Dispatcher cleanup #3025

merged 5 commits into from
Feb 26, 2019

Conversation

johnhaddon
Copy link
Member

This is a followup for #3024, since overnight I realised that some cleanup I had avoided was possible after all.

We use a compatibility config file to convert old plugs on loading instead.
These were going to varying degrees of trouble to ensure that they only requested tasks that had valid input connections. But these were buggy, and although we "fixed" the problem for TaskNode in a538b69, it was still wrong in several other derived classes. One of our basic rules for nodes is that they shouldn't "look outside", and should deal only with their directly owned plugs. By following that rule here, we can remove responsibility from the TaskNodes entirely, and deal with it centrally in the dispatcher.
This isn't testing anything that isn't already tested in GafferDispatch (ExecutableOpHolder doesn't reimplement `preTasks()`, so the base class tests are fine). We could update it to account for the latest changes, but I don't think it's worth it.
Copy link
Contributor

@danieldresser-ie danieldresser-ie left a comment

Choose a reason for hiding this comment

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

Made one comment. I'm not familiar enough with this to be totally confident everything still works, but it has been working for me, and it definitely looks cleaner.

@@ -648,6 +648,11 @@ class Dispatcher::Batcher
}
}

const Gaffer::Plug *dispatcherPlug( const TaskNode::Task &task )
{
return static_cast<const TaskNode *>( task.plug()->node() )->dispatcherPlug();
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to think a bit about whether this would ever fail. If you had a node implemented as a network, with a task output, and then you removed the internal task nodes ( maybe the network for some reason no longer needs to submit tasks ), then you could end up with source() returning an output plug on the network, which might not be a TaskNode, causing a crash? This is an obscure situation, but it means that I'm not super clear on what the rules for TaskPlugs are. You may only have an output TaskPlug on a TaskNode, or a network ( if it's connected to an internal TaskNode )?

Copy link
Member Author

Choose a reason for hiding this comment

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

GafferDispatch used to be pretty hazy in this area, mixing and matching where it passed plugs vs nodes, and I'm slowly refactoring it into line with ComputeNode/ValuePlug. The general rule in all this is that nodes are the "doers" but their API is protected, and plugs provide the public API. You don't call ComputeNode::compute(), you call ValuePlug::getValue(), and you don't call TaskNode::execute(), you call TaskPlug::execute(). The rule for output TaskPlugs is also analogous to that for output ValuePlugs : the source plug needs to belong to a TaskNode. If you inadvertently build an invalid network, this will trigger the exception in TaskNodeProcess. This will be triggered before we call dispatcherPlug(), so the cast here is safe. The prior code used runTimeCast() via the removed Task::node() method, but did not check for failure, making runTimeCast() pointless. Since we have checked that we have a TaskNode already, I felt that static_cast was appropriate here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I figured that this was subtle enough as to warrant some test coverage, so I've pushed one further commit, which adds some. I'll merge once the CI passes.

@johnhaddon johnhaddon merged commit 2e762d6 into GafferHQ:master Feb 26, 2019
@johnhaddon johnhaddon deleted the dispatcherCleanup branch February 26, 2019 16:54
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