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

Flatten modules into main graph #1781

Merged
merged 34 commits into from
May 5, 2015
Merged

Flatten modules into main graph #1781

merged 34 commits into from
May 5, 2015

Conversation

mitchellh
Copy link
Contributor

Fixes #1582

Might affect #1637 (hopefully fixes, unsure due to private repo).

All context tests pass but this is a pretty big change and I'll want to try at least on our core ops repo before merging (since we use modules heavily).

This changes the way the graph treats modules. Prior to this PR, modules were their own isolated subgraphs. When evaluating, the entire subgraph would get walked in one step. The problem with this is that it turns out that modules can't always be seen as a single executable unit.

This PR flattens the subgraphs of modules into the main root graph, then does the destroy transformations after this flattening. This lets the destroy edge manipulations have a global view of the graph, and create the proper ordering of things.

Most of this was surprisingly straightforward. The only part I'm really unhappy about is the special casing in graph builder to only do some steps for the root path.

I think a future change/refactor can probably simplify this even further by just getting rid of static subgraphs altogether and just having the transform add all the nodes for all the modules at once. I was about to go down this route, but decided that if this works, we should get this in first, and refactor later, especially given that the changes here aren't hideous.

I have a feeling this will fix weird module-boundary create-before-destroy issues as well but I don't have a test case yet to reproduce anything of that sort so I can't confirm.

Additionally, @armon raised good points about this will hurt performance of Terraform for very large graphs. This is because the O(N) lookups for graph vertices will get bad since N Is getting quite large (before it was N within each subgraph). Given that almost all O(N) lookups are for interface implementations, I think we can just do interface-specific lookaside tables in the future and speed everything up to O(1).

@phinze: One thing for you is to ask if the graph functionality looks good? I don't want to affect the terraform graph output we did for 0.5 for this.

}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I love how the big overarching test comes first in the diff. 😄

"WE GON' MAKE THIS WORK!"

// Perform the transitive reduction to make our graph a bit
// more sane if possible (it usually is possible).
&TransitiveReductionTransformer{},
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah this is funky, but agreed with top-level description that it's better to land it working and then refactor.

@phinze
Copy link
Contributor

phinze commented May 4, 2015

Running this on a local sample infra with a cycle I thought would have been fixed by this yielded unexpected results. Digging in and I'll follow up.

mitchellh added a commit that referenced this pull request May 5, 2015
Flatten modules into main graph
@mitchellh mitchellh merged commit c863565 into master May 5, 2015
@mitchellh mitchellh deleted the b-module-deps branch May 5, 2015 20:19
@ketzacoatl
Copy link
Contributor

@mitchellh I can get you access to the repo if you would like to test with it in some capacity. I can also test that repo with this updated revision. That repo will be public soon..

@mitchellh
Copy link
Contributor Author

@ketzacoatl I worked with @phinze and verified we've fixed your bvug.

@ketzacoatl
Copy link
Contributor

very exciting!

phinze added a commit that referenced this pull request May 5, 2015
This reimplements my prior attempt at nipping issues where a plan did
not yield the same cycle an apply did. My prior attempt was to have
ctx.Validate generate a "Verbose" worst-case graph. It turns out that
skipping PruneDestroyTransformer to generate this graph misses important
heuristics that prevent cycles by dropping destroy nodes that are
determined to be unused.

This resulted in Validate improperly failing in scenarios where these
heuristics would have broken the cycle.

We detected the problem during the work on #1781 and worked around the
issue by reverting to the non-Verbose graph in Validate.

This commit accomplishes the original goal in a better way - by
generating the full graph and checking it once Plan has calculated the
diff. This guarantees that any graph issue that would be caught by Apply
will be caught by Plan.
@ghost
Copy link

ghost commented May 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Destroy doesn't respect module dependencies correctly
3 participants