Don't validate GLM state tx if there is no previous state
This commit is contained in:
parent
92802da2dd
commit
8073a05415
@ -81,18 +81,20 @@ type glmState struct {
|
||||
ActiveAllocations []daecommon.ConfigStorageAllocation
|
||||
}
|
||||
|
||||
func (glm *garageLayoutManager) get() (glmState, error) {
|
||||
func (glm *garageLayoutManager) get() (glmState, bool, error) {
|
||||
var (
|
||||
path = filepath.Join(glm.dir.Path, glmStateFile)
|
||||
state glmState
|
||||
)
|
||||
|
||||
err := jsonutil.LoadFile(&state, path)
|
||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||
return glmState{}, err
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return glmState{}, false, nil
|
||||
} else if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||
return glmState{}, false, err
|
||||
}
|
||||
|
||||
return state, nil
|
||||
return state, true, nil
|
||||
}
|
||||
|
||||
func (glm *garageLayoutManager) set(state glmState) error {
|
||||
@ -103,7 +105,7 @@ func (glm *garageLayoutManager) set(state glmState) error {
|
||||
func (glm *garageLayoutManager) GetActiveAllocations(context.Context) (
|
||||
[]daecommon.ConfigStorageAllocation, error,
|
||||
) {
|
||||
state, err := glm.get()
|
||||
state, _, err := glm.get()
|
||||
return state.ActiveAllocations, err
|
||||
}
|
||||
|
||||
@ -117,9 +119,13 @@ func (glm *garageLayoutManager) SetActiveAllocations(
|
||||
func (glm *garageLayoutManager) Validate(
|
||||
_ context.Context, targetAllocs []daecommon.ConfigStorageAllocation,
|
||||
) error {
|
||||
state, err := glm.get()
|
||||
state, ok, err := glm.get()
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading state: %w", err)
|
||||
} else if !ok {
|
||||
// If there is no previously state then we assume the new state can't
|
||||
// conflict with it.
|
||||
return nil
|
||||
}
|
||||
|
||||
return validateTargetAllocs(
|
||||
@ -135,16 +141,20 @@ func (glm *garageLayoutManager) CalculateStateTransition(
|
||||
) (
|
||||
StateTransition, error,
|
||||
) {
|
||||
state, err := glm.get()
|
||||
state, ok, err := glm.get()
|
||||
if err != nil {
|
||||
return StateTransition{}, fmt.Errorf("reading state: %w", err)
|
||||
}
|
||||
|
||||
err = validateTargetAllocs(state.ActiveAllocations, targetAllocs)
|
||||
if err != nil {
|
||||
return StateTransition{}, fmt.Errorf(
|
||||
"validating target allocations: %w", err,
|
||||
)
|
||||
if ok {
|
||||
// If there is no previously state then we assume the new state can't
|
||||
// conflict with it.
|
||||
err = validateTargetAllocs(state.ActiveAllocations, targetAllocs)
|
||||
if err != nil {
|
||||
return StateTransition{}, fmt.Errorf(
|
||||
"validating target allocations: %w", err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
allKnownNodes, knownNodes := knownNodes, knownNodes[:0]
|
||||
|
Loading…
Reference in New Issue
Block a user