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 { func (c *Context) graphWalker(operation walkOperation) *ContextGraphWalker {
if operation == walkValidate { var state *states.SyncState
return &ContextGraphWalker{ var refreshState *states.SyncState
Context: c,
State: states.NewState().SyncWrapper(), switch operation {
Changes: c.changes.SyncWrapper(), case walkValidate:
InstanceExpander: instances.NewExpander(), // validate should not use any state
Operation: operation, s := states.NewState()
StopContext: c.runContext, state = s.SyncWrapper()
RootVariableValues: c.variables,
} // 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{ return &ContextGraphWalker{
Context: c, Context: c,
State: c.state.SyncWrapper(), State: state,
RefreshState: refreshState,
Changes: c.changes.SyncWrapper(), Changes: c.changes.SyncWrapper(),
InstanceExpander: instances.NewExpander(), InstanceExpander: instances.NewExpander(),
Operation: operation, Operation: operation,

View File

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