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

Remove RESTARTING/PURGING states #3905

Merged
merged 4 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions pkg/pillar/cmd/zedagent/parseconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,6 @@ func countRunningApps(getconfigCtx *getconfigContext) (runningCount uint) {
switch status.State {
case types.BOOTING, types.RUNNING, types.HALTING:
runningCount++
case types.PURGING, types.RESTARTING:
log.Noticef("countRunningApps: %s for %s in %s",
status.Key(), status.DisplayName, status.State)
runningCount++
}
}
return runningCount
Expand Down
27 changes: 9 additions & 18 deletions pkg/pillar/cmd/zedmanager/updatestatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func doUpdate(ctx *zedmanagerContext,
log.Functionf("PurgeInprogress(%s) volumemgr done",
status.Key())
status.PurgeInprogress = types.BringDown
status.State = types.HALTING
changed = true
// Keep the old volumes in place
_, done := doRemove(ctx, status, false)
Expand Down Expand Up @@ -802,15 +803,10 @@ func doActivate(ctx *zedmanagerContext, uuidStr string,
}
}
if ds.State != status.State {
switch status.State {
case types.RESTARTING, types.PURGING:
// Leave unchanged
default:
log.Functionf("Set State from DomainStatus from %d to %d",
status.State, ds.State)
status.State = ds.State
changed = true
}
log.Functionf("Set State from DomainStatus from %d to %d",
status.State, ds.State)
status.State = ds.State
changed = true
}
// XXX compare with equal before setting changed?
status.IoAdapterList = ds.IoAdapterList
Expand Down Expand Up @@ -1174,15 +1170,10 @@ func doInactivateHalt(ctx *zedmanagerContext,
changed = true
}
if ds.State != status.State {
switch status.State {
case types.RESTARTING, types.PURGING:
// Leave unchanged
default:
log.Functionf("Set State from DomainStatus from %d to %d",
status.State, ds.State)
status.State = ds.State
changed = true
}
log.Functionf("Set State from DomainStatus from %d to %d",
status.State, ds.State)
status.State = ds.State
changed = true
}
// Ignore errors during a halt
if ds.HasError() {
Expand Down
5 changes: 1 addition & 4 deletions pkg/pillar/cmd/zedmanager/zedmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,6 @@ func handleCreate(ctxArg interface{}, key string,
log.Warnf("handleCreate(%v) for %s found different purge counter %d vs. %d",
config.UUIDandVersion, config.DisplayName, persistedCounter, configCounter)
status.PurgeInprogress = types.DownloadAndVerify
status.State = types.PURGING
status.PurgeStartedAt = time.Now()
// We persist the PurgeCmd Counter when
// PurgeInprogress is done
Expand Down Expand Up @@ -1222,8 +1221,7 @@ func handleModify(ctxArg interface{}, key string,
// Will restart even if we crash/power cycle since that
// would also restart the app. Hence we can update
// the status counter here.
status.RestartInprogress = types.BringDown
status.State = types.RESTARTING
status.RestartInprogress = types.BringDown // indicate to restart
status.RestartStartedAt = time.Now()
} else {
log.Functionf("handleModify(%v) for %s restartcmd ignored config !Activate",
Expand Down Expand Up @@ -1254,7 +1252,6 @@ func handleModify(ctxArg interface{}, key string,
status.ClearErrorWithSource()
}
status.PurgeInprogress = types.DownloadAndVerify
status.State = types.PURGING
status.PurgeStartedAt = time.Now()
// We persist the PurgeCmd Counter when PurgeInprogress is done
} else if needPurge {
Expand Down
16 changes: 3 additions & 13 deletions pkg/pillar/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// SwState started with enum names from OMA-TS-LWM2M_SwMgmt-V1_0-20151201-C
// but now has many additions.
// They are in order of progression (except for the RESTARTING and PURGING ones)
// They are in order of progression
// We map this to info.ZSwState
type SwState uint8

Expand All @@ -44,10 +44,8 @@ const (
PAUSED
HALTING // being halted
HALTED
RESTARTING // Restarting due to config change or zcli
PURGING // Purging due to config change
BROKEN // Domain is still alive, but its device model has failed
UNKNOWN // State of the domain can't be determined
BROKEN // BROKEN means domain is still alive, but its device model has failed
UNKNOWN // UNKNOWN means state of the domain can't be determined
// PENDING to start
PENDING
// SCHEDULING waiting to be scheduled
Expand Down Expand Up @@ -98,10 +96,6 @@ func (state SwState) String() string {
return "HALTING"
case HALTED:
return "HALTED"
case RESTARTING:
return "RESTARTING"
case PURGING:
return "PURGING"
case PENDING:
return "PENDING"
case FAILED:
Expand Down Expand Up @@ -170,10 +164,6 @@ func (state SwState) ZSwState() info.ZSwState {
return info.ZSwState_HALTING
case HALTED:
return info.ZSwState_HALTED
case RESTARTING:
return info.ZSwState_RESTARTING
case PURGING:
return info.ZSwState_PURGING
// we map BROKEN to HALTING to indicate that EVE has an active
// role in reaping BROKEN domains and transitioning them to
// a final HALTED state
Expand Down
20 changes: 10 additions & 10 deletions pkg/pillar/zedcloud/deferred.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const longTime2 = time.Hour * 48
// DeferredContext is part of ZedcloudContext
type DeferredContext struct {
deferredItems []*deferredItem
deferredItemsLock *sync.Mutex
Ticker flextimer.FlexTickerHandle
priorityCheckFunctions []TypePriorityCheckFunction
lock *sync.Mutex
sentHandler *SentHandlerFunction
zedcloudCtx *ZedCloudContext
iteration int
Expand Down Expand Up @@ -92,7 +92,7 @@ func CreateDeferredCtx(zedcloudCtx *ZedCloudContext,
})

ctx := &DeferredContext{
lock: &sync.Mutex{},
deferredItemsLock: &sync.Mutex{},
Ticker: flextimer.NewRangeTicker(longTime1, longTime2),
sentHandler: sentHandler,
priorityCheckFunctions: priorityCheckFunctions,
Expand Down Expand Up @@ -134,10 +134,10 @@ func (ctx *DeferredContext) processQueueTask(ps *pubsub.PubSub,

// handleDeferred try to send all deferred items
func (ctx *DeferredContext) handleDeferred() bool {
ctx.lock.Lock()
ctx.deferredItemsLock.Lock()
reqs := ctx.deferredItems
ctx.deferredItems = []*deferredItem{}
ctx.lock.Unlock()
ctx.deferredItemsLock.Unlock()

log := ctx.zedcloudCtx.log

Expand Down Expand Up @@ -235,13 +235,13 @@ func (ctx *DeferredContext) handleDeferred() bool {
}
}

ctx.lock.Lock()
ctx.deferredItemsLock.Lock()
// Merge with the incoming requests, recently added are in the tail
ctx.deferredItems = append(notSentReqs, ctx.deferredItems...)
if len(ctx.deferredItems) == 0 {
stopTimer(log, ctx)
}
ctx.lock.Unlock()
ctx.deferredItemsLock.Unlock()

allSent := len(notSentReqs) == 0

Expand All @@ -258,8 +258,8 @@ func (ctx *DeferredContext) handleDeferred() bool {
func (ctx *DeferredContext) SetDeferred(
key string, buf *bytes.Buffer, size int64, url string, bailOnHTTPErr,
withNetTracing, ignoreErr bool, itemType interface{}) {
ctx.lock.Lock()
defer ctx.lock.Unlock()
ctx.deferredItemsLock.Lock()
defer ctx.deferredItemsLock.Unlock()

log := ctx.zedcloudCtx.log
log.Functionf("SetDeferred(%s) size %d items %d",
Expand Down Expand Up @@ -300,8 +300,8 @@ func (ctx *DeferredContext) SetDeferred(

// RemoveDeferred removes key from deferred items if exists
func (ctx *DeferredContext) RemoveDeferred(key string) {
ctx.lock.Lock()
defer ctx.lock.Unlock()
ctx.deferredItemsLock.Lock()
defer ctx.deferredItemsLock.Unlock()

log := ctx.zedcloudCtx.log
log.Functionf("RemoveDeferred(%s) items %d",
Expand Down