Merge pull request #17281 from vrothberg/rm-perf

container rm: save once for exec removal and state change
This commit is contained in:
OpenShift Merge Robot
2023-01-31 04:27:44 -05:00
committed by GitHub
2 changed files with 14 additions and 18 deletions

View File

@ -1072,14 +1072,6 @@ func (c *Container) removeAllExecSessions() error {
} }
c.state.ExecSessions = nil c.state.ExecSessions = nil
c.state.LegacyExecSessions = nil c.state.LegacyExecSessions = nil
if err := c.save(); err != nil {
if !errors.Is(err, define.ErrCtrRemoved) {
if lastErr != nil {
logrus.Errorf("Stopping container %s exec sessions: %v", c.ID(), lastErr)
}
lastErr = err
}
}
return lastErr return lastErr
} }

View File

@ -776,16 +776,6 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force, remo
cleanupErr = fmt.Errorf("cleaning up container %s: %w", c.ID(), err) cleanupErr = fmt.Errorf("cleaning up container %s: %w", c.ID(), err)
} }
// Set ContainerStateRemoving
c.state.State = define.ContainerStateRemoving
if err := c.save(); err != nil {
if cleanupErr != nil {
logrus.Errorf(err.Error())
}
return fmt.Errorf("unable to set container %s removing state in database: %w", c.ID(), err)
}
// Remove all active exec sessions // Remove all active exec sessions
// removing the exec sessions might temporarily unlock the container's lock. Using it // removing the exec sessions might temporarily unlock the container's lock. Using it
// after setting the state to ContainerStateRemoving will prevent that the container is // after setting the state to ContainerStateRemoving will prevent that the container is
@ -798,6 +788,20 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force, remo
} }
} }
// Set ContainerStateRemoving as an intermediate state (we may get
// killed at any time) and save the container.
c.state.State = define.ContainerStateRemoving
if err := c.save(); err != nil {
if !errors.Is(err, define.ErrCtrRemoved) {
if cleanupErr == nil {
cleanupErr = err
} else {
logrus.Errorf("Saving container: %v", err)
}
}
}
// Stop the container's storage // Stop the container's storage
if err := c.teardownStorage(); err != nil { if err := c.teardownStorage(); err != nil {
if cleanupErr == nil { if cleanupErr == nil {