Skip to content

Conversation

@crosbymichael
Copy link
Member

One of the most complex parts of the container are the various states that it has. Pause, running, stopped, destroyed, checkpointed, resumed, etc. Transitioning to these various states are also complex. Right now we use various methods to figure out what state the container is in and not really where it was. There is a good pattern to follow when you have to deal with states and transitions.

For each of the container states there is a separate type. Right now most of the logic is around how to destroy the container and depending on the state what to remove on disk. By moving all the destroy logic to the state types and letting them handle what other states they are able to transition to this it reduces the complexity when figuring out the transitions even if it is a little more code and more types.

In the future we can move more of the container methods to the state types to better handle the error conditions and remove some of the if blocks in things like Start().

Let me know what you all think. This is part of the work making runc work with the new State type from the specs. Alot of the logic was spread out around Destory() in runc and libcontainer and this centralizes all that logic and handles all the changes properly no matter what combination.

Closes #218

@mrunalp
Copy link
Contributor

mrunalp commented Oct 2, 2015

Build failure libcontainer/container_linux.go:827: unreachable code

@mrunalp
Copy link
Contributor

mrunalp commented Oct 2, 2015

I like the idea of a state machine like you have 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crosbymichael
Do we depend on config frozen state(paused), I thought checking cgroup subsystem for the specific container would get the right state for freezer subsystem ?
or
As with your new changes, you are transitioning the state, can we leverage the state that instead of checking configs ( where Frozen never set in our configs while starting the container)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya, we need to get your commits in #218 to resolve this.

@rajasec
Copy link
Contributor

rajasec commented Oct 3, 2015

@crosbymichael
I like state machine approach to fix the container status/states and container cleans ups.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user checkpointed in different directory, I'm not sure whether that will get cleaned. This forces to run the checkpoint and restore from the same place ( which is expected) but the user does some mistake if the checkpoint directory exists ( not cleaned) it will pick up that image for restoring ?
Few times I faced the problem in this area.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is correct. That is not the checkpointed files but just a marker that the container was checkpointed. It will be removed like all the state after the container stops.

@crosbymichael
Copy link
Member Author

@rajasec i was actually going to either cherry-pick your commits in #218 to this PR or just rebase your PR for you and open one with your commits after this was merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/inprocess/in process/

@crosbymichael
Copy link
Member Author

@mrunalp updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the base here? From the patch it looks like we are using it for calling destroy on destroyed state. Could we have a common destroy helper function and call it from destroy() of runningState/destroyState instead?

@crosbymichael
Copy link
Member Author

@mrunalp @LK4D4 PTAL

Updated with your suggestions.

@crosbymichael
Copy link
Member Author

@LK4D4 ping

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you don't need else here

@LK4D4
Copy link
Contributor

LK4D4 commented Oct 15, 2015

Code looks logical for me. I posted some style recommendations though.

@crosbymichael
Copy link
Member Author

@LK4D4 updated thanks for the reivew

@LK4D4
Copy link
Contributor

LK4D4 commented Oct 15, 2015

@crosbymichael I think maybe it's possible to write some tests. Maybe simple unit-tests for transitions.

@mrunalp
Copy link
Contributor

mrunalp commented Oct 15, 2015

This looks fine to me. Could we rearrange the commits a bit before we merge (once all comments are addressed) ?

@crosbymichael
Copy link
Member Author

@LK4D4 @mrunalp added tests for state transitions and status

@mrunalp
Copy link
Contributor

mrunalp commented Nov 2, 2015

Needs rebase. Otherwise looks fine.

@LK4D4
Copy link
Contributor

LK4D4 commented Nov 2, 2015

Yeah, LGTM in advance
Sorry, I missing so much in mail flow

@crosbymichael
Copy link
Member Author

@LK4D4 updated and squashed

@crosbymichael
Copy link
Member Author

@mrunalp i squashed the commits for you ;)

@mrunalp
Copy link
Contributor

mrunalp commented Nov 16, 2015

@crosbymichael LGTM. I didn't really want you to have to squash to 1 :D (Just meant no big addition deletion over the series).

@LK4D4
Copy link
Contributor

LK4D4 commented Nov 16, 2015

@mrunalp yeah, maybe unsquash now...

@crosbymichael
Copy link
Member Author

noooooo

@rajasec rajasec mentioned this pull request Nov 24, 2015
@crosbymichael crosbymichael force-pushed the destory-state branch 2 times, most recently from f8ac1b5 to 03f07c8 Compare December 9, 2015 22:00
Signed-off-by: Michael Crosby <[email protected]>

Add state status() method

Signed-off-by: Michael Crosby <[email protected]>

Allow multiple checkpoint on restore

Signed-off-by: Michael Crosby <[email protected]>

Handle leave-running state

Signed-off-by: Michael Crosby <[email protected]>

Fix state transitions for inprocess

Because the tests use libcontainer in process between the various states
we need to ensure that that usecase works as well as the out of process
one.

Signed-off-by: Michael Crosby <[email protected]>

Remove isDestroyed method

Signed-off-by: Michael Crosby <[email protected]>

Handling Pausing from freezer state

Signed-off-by: Rajasekaran <[email protected]>

freezer status

Signed-off-by: Rajasekaran <[email protected]>

Fixing review comments

Signed-off-by: Rajasekaran <[email protected]>

Added comment when freezer not available

Signed-off-by: Rajasekaran <[email protected]>
Signed-off-by: Michael Crosby <[email protected]>

Conflicts:
	libcontainer/container_linux.go

Change checkFreezer logic to isPaused()

Signed-off-by: Michael Crosby <[email protected]>

Remove state base and factor out destroy func

Signed-off-by: Michael Crosby <[email protected]>

Add unit test for state transitions

Signed-off-by: Michael Crosby <[email protected]>
@crosbymichael
Copy link
Member Author

ping @mrunalp @LK4D4 any more comments because I don't know what else to do with the commits

@LK4D4
Copy link
Contributor

LK4D4 commented Jan 4, 2016

@crosbymichael Yeah, it was a joke about unsquash.
LGTM from me.

@mrunalp
Copy link
Contributor

mrunalp commented Jan 4, 2016

LGTM

mrunalp pushed a commit that referenced this pull request Jan 4, 2016
@mrunalp mrunalp merged commit fa24ebf into opencontainers:master Jan 4, 2016
@crosbymichael crosbymichael deleted the destory-state branch January 4, 2016 18:01
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants