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

Migrate container configuration in portlayer in memory #4146

Merged
merged 9 commits into from
Mar 8, 2017

Conversation

emlin
Copy link
Contributor

@emlin emlin commented Mar 6, 2017

Fixes #3610

  • Migrate container configuration in memory if there is migration plugin registered
  • In commit method, drop extraconfig change if data is migrated
  • If data migration failed, keep partial migrated value, and keep migration error in container cache
  • In docker inspect and docker ps show container status as "broken" if data migration failed
  • If container status is broken
    • allow container stop
    • force delete even for "docker rm"

@emlin
Copy link
Contributor Author

emlin commented Mar 6, 2017

@matthewavery added you as reviewer cause you ever worked on this issue.

@@ -88,6 +88,7 @@ type VicContainerProxy interface {

Stop(vc *viccontainer.VicContainer, name string, seconds *int, unbound bool) error
IsRunning(vc *viccontainer.VicContainer) (bool, error)
IsBroken(vc *viccontainer.VicContainer) (bool, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure this will only be needed in the container endpoints? I am wondering if we will need this information for networks or volumes at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, guess this is fine.
This information is needed by container stop/start/rm, cause we still allow user to delete the broken container. But for all the other functions, if the configuration is available after half migration, those piece of function will looks good, it otherwise, that will not. The function is consistent.
We don't that care about the function of broken containers atm, as long as that's deletable.

@@ -34,7 +34,7 @@ type Common struct {
// A reference to the components hosting execution environment, if any
ExecutionEnvironment string

// Unambiguous ID with meaning in the context of its hosting execution environment
// Unambiguous ID with meaning in the context of its hosting execution environment. Change this definition will cause container backward compatibility issue
Copy link
Contributor

Choose a reason for hiding this comment

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

please add "Please don't change this." I am not sure, you might add a "without talking to emma lin" to that. That way if someone does want to change it for whatever reason they can talk to you about why they likely shouldn't.

@matthewavery
Copy link
Contributor

lgtm 😄 , other than the comment on the container ID field. Though that is simply a suggestion.

@emlin
Copy link
Contributor Author

emlin commented Mar 6, 2017

For easy to understand, here I posted the output of docker commands if there is one container broken for data migration error(the error if faked, I cannot have a real failure for that now):

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
fc67c420adb3        busybox             "sh"                10 minutes ago      broken                                  wonderful_mestorf```
```docker -H 10.160.58.173:2376 --tls inspect fc
[
    {
        "Id": "fc67c420adb38c166c3402fe925c9f28b47c036ae43ff07d43338aa6f3933e1e",
        "Created": "2017-03-06T17:22:04Z",
        "Path": "sh",
        "Args": [],
        "State": {
            "Status": "broken",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "Migration failed: Faked migration error",
            "StartedAt": "2017-03-06T17:22:28Z",
            "FinishedAt": "2017-03-06T17:22:52Z"
        },
...

return false, err
}

return inspectJSON.State.Running, nil
return inspectJSON.State.Status == "broken", nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any statuses defined as constants? Using strings is not the best solution especially if it used more than 2 times across all project.
I also don't like IsBroken method. It's just awkward. There should be a method that returns status only it would be way more useful for other possible cases too.

@emlin emlin changed the title [full ci]Migrate container configuration in portlayer in memory [specific ci=Group0-Bugs]Migrate container configuration in portlayer in memory Mar 6, 2017
if err != nil && IsNotFoundError(err) {
cache.ContainerCache().DeleteContainer(vc.ContainerID)
return err
}
if !running {
// attempt to stop container if status is running or broken
if !inspectJSON.State.Running && inspectJSON.State.Status != "broken" {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make this string a const?

info.ContainerConfig.State = s
var state string
if container.MigrationError != nil {
state = "broken"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

@@ -34,7 +34,7 @@ type Common struct {
// A reference to the components hosting execution environment, if any
ExecutionEnvironment string

// Unambiguous ID with meaning in the context of its hosting execution environment
// Unambiguous ID with meaning in the context of its hosting execution environment. Change this definition will cause container backward compatibility issue. Please don't change this.
Copy link
Contributor

Choose a reason for hiding this comment

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

Change/Changing

Also the comment might be little bit more than this so that reader can understand why he/she shouldn't be changing this

@@ -146,6 +146,12 @@ func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int
log.Debugf("Nilifying ExtraConfig as we are running")
s.ExtraConfig = nil
}
// nilify ExtraConfig if container configuration is migrated
// in this case, VCH and container are in different version. Migrated configuration cannot be written back to old container, to avoid data loss in old version's container
if h.Migrated {
Copy link
Contributor

Choose a reason for hiding this comment

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

We are setting ExtraConfig to nil if we are powered on so why do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because configuration data is migrated. If write back to container vmx file, the old binary cannot read back new data. We ever talked about that part in one meeting, remember?

@emlin emlin changed the title [specific ci=Group0-Bugs]Migrate container configuration in portlayer in memory [specific ci=Group1-Docker-Commands]Migrate container configuration in portlayer in memory Mar 6, 2017
@emlin emlin changed the title [specific ci=Group1-Docker-Commands]Migrate container configuration in portlayer in memory [full ci]Migrate container configuration in portlayer in memory Mar 7, 2017
@emlin emlin force-pushed the 3610 branch 3 times, most recently from 970a3e6 to ccaf115 Compare March 7, 2017 16:53
@emlin emlin changed the title [full ci]Migrate container configuration in portlayer in memory [specific ci=Group1-Docker-Commands]Migrate container configuration in portlayer in memory Mar 7, 2017
@emlin emlin force-pushed the 3610 branch 2 times, most recently from 6798498 to 554b448 Compare March 7, 2017 19:55
  This value is used to skip new features on old containers
return err
}
// force stop if container is broken to make sure container is deletable later
if state.Status == ContainerError {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is checking for status "error". Is this what you're using for "broken"?

Copy link
Contributor

Choose a reason for hiding this comment

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

So, I see where you're setting it on the portlayer side. Since this is our state string, why not use a more explicit string, such as "migrating"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one error state caused by migration, not a working state as migrating. I think we might have other incorrect scenarios other than migration error, so I didn't use migration error as the state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I just got broken was an actual status. It's actually a description, meaning the status is error.

Can you change the comment to say "if container is in an error state"? Or is broken the best description?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update the comment.

defer trace.End(trace.Begin(""))

if c.client == nil {
return false, InternalServerError("ContainerProxy.IsRunning failed to get a portlayer client")
return nil, InternalServerError("ContainerProxy.dockerInfo failed to get a portlayer client")
Copy link
Contributor

Choose a reason for hiding this comment

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

.State and not .dockerInfo

@sflxn
Copy link
Contributor

sflxn commented Mar 7, 2017

small nitpicks, but LGTM

Approved with PullApprove

@emlin emlin changed the title [specific ci=Group1-Docker-Commands]Migrate container configuration in portlayer in memory Migrate container configuration in portlayer in memory Mar 7, 2017
@emlin emlin merged commit f04b2a7 into vmware:master Mar 8, 2017
@emlin emlin deleted the 3610 branch March 8, 2017 00:14
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.

6 participants