mirror of https://github.com/docker/docs.git
Fix container update flow.
This guarantees that containers get fully updated before being inserted in the node (and returned by .Containers()). Fixes #560 Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
64d691a448
commit
23d52249fa
|
|
@ -242,8 +242,7 @@ func (n *node) refreshContainer(ID string, full bool) error {
|
||||||
func (n *node) updateContainer(c dockerclient.Container, containers map[string]*cluster.Container, full bool) (map[string]*cluster.Container, error) {
|
func (n *node) updateContainer(c dockerclient.Container, containers map[string]*cluster.Container, full bool) (map[string]*cluster.Container, error) {
|
||||||
var container *cluster.Container
|
var container *cluster.Container
|
||||||
|
|
||||||
n.Lock()
|
n.RLock()
|
||||||
|
|
||||||
if current, exists := n.containers[c.Id]; exists {
|
if current, exists := n.containers[c.Id]; exists {
|
||||||
// The container is already known.
|
// The container is already known.
|
||||||
container = current
|
container = current
|
||||||
|
|
@ -254,13 +253,11 @@ func (n *node) updateContainer(c dockerclient.Container, containers map[string]*
|
||||||
}
|
}
|
||||||
full = true
|
full = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update its internal state.
|
|
||||||
container.Container = c
|
|
||||||
containers[container.Id] = container
|
|
||||||
|
|
||||||
// Release the lock here as the next step is slow.
|
// Release the lock here as the next step is slow.
|
||||||
n.Unlock()
|
// Trade-off: If updateContainer() is called concurrently for the same
|
||||||
|
// container, we will end up doing a full refresh twice and the original
|
||||||
|
// container (containers[container.Id]) will get replaced.
|
||||||
|
n.RUnlock()
|
||||||
|
|
||||||
// Update ContainerInfo.
|
// Update ContainerInfo.
|
||||||
if full {
|
if full {
|
||||||
|
|
@ -273,6 +270,12 @@ func (n *node) updateContainer(c dockerclient.Container, containers map[string]*
|
||||||
container.Info.Config.CpuShares = container.Info.Config.CpuShares * 1024.0 / n.Cpus
|
container.Info.Config.CpuShares = container.Info.Config.CpuShares * 1024.0 / n.Cpus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update its internal state.
|
||||||
|
n.Lock()
|
||||||
|
container.Container = c
|
||||||
|
containers[container.Id] = container
|
||||||
|
n.Unlock()
|
||||||
|
|
||||||
return containers, nil
|
return containers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue