Get the new RefreshState into the right contexts

This commit is contained in:
James Bardin 2020-09-04 15:59:22 -04:00
parent d6a586709c
commit ad22e137e6
2 changed files with 25 additions and 11 deletions

View File

@ -781,20 +781,32 @@ func (c *Context) walk(graph *Graph, operation walkOperation) (*ContextGraphWalk
}
func (c *Context) graphWalker(operation walkOperation) *ContextGraphWalker {
if operation == walkValidate {
return &ContextGraphWalker{
Context: c,
State: states.NewState().SyncWrapper(),
Changes: c.changes.SyncWrapper(),
InstanceExpander: instances.NewExpander(),
Operation: operation,
StopContext: c.runContext,
RootVariableValues: c.variables,
}
var state *states.SyncState
var refreshState *states.SyncState
switch operation {
case walkValidate:
// validate should not use any state
s := states.NewState()
state = s.SyncWrapper()
// validate currently uses the plan graph, so we have to populate the
// refreshState.
refreshState = s.SyncWrapper()
case walkPlan:
state = c.state.SyncWrapper()
// plan requires a second state to store the refreshed resources
refreshState = c.state.DeepCopy().SyncWrapper()
default:
state = c.state.SyncWrapper()
}
return &ContextGraphWalker{
Context: c,
State: c.state.SyncWrapper(),
State: state,
RefreshState: refreshState,
Changes: c.changes.SyncWrapper(),
InstanceExpander: instances.NewExpander(),
Operation: operation,

View File

@ -26,6 +26,7 @@ type ContextGraphWalker struct {
// Configurable values
Context *Context
State *states.SyncState // Used for safe concurrent access to state
RefreshState *states.SyncState // Used for safe concurrent access to state
Changes *plans.ChangesSync // Used for safe concurrent writes to changes
InstanceExpander *instances.Expander // Tracks our gradual expansion of module and resource instances
Operation walkOperation
@ -96,6 +97,7 @@ func (w *ContextGraphWalker) EvalContext() EvalContext {
ProvisionerLock: &w.provisionerLock,
ChangesValue: w.Changes,
StateValue: w.State,
RefreshStateValue: w.RefreshState,
Evaluator: evaluator,
VariableValues: w.variableValues,
VariableValuesLock: &w.variableValuesLock,