mirror of https://github.com/docker/docs.git
improve locks
This commit is contained in:
parent
407d0bc37f
commit
07383edd47
|
@ -0,0 +1 @@
|
|||
swarm
|
|
@ -113,6 +113,9 @@ func (n *Node) updateContainers() error {
|
|||
return err
|
||||
}
|
||||
|
||||
n.Lock()
|
||||
defer n.Unlock()
|
||||
|
||||
merged := make(map[string]*Container)
|
||||
for _, c := range containers {
|
||||
if current, exists := n.containers[c.Id]; exists {
|
||||
|
@ -136,9 +139,7 @@ func (n *Node) updateContainers() error {
|
|||
}
|
||||
}
|
||||
|
||||
n.Lock()
|
||||
n.containers = merged
|
||||
n.Unlock()
|
||||
|
||||
log.Debugf("[%s] Updated state", n.ID)
|
||||
return nil
|
||||
|
|
|
@ -43,13 +43,13 @@ func (s *Scheduler) selectNodeForContainer(config *dockerclient.ContainerConfig)
|
|||
|
||||
// Schedule a brand new container into the cluster.
|
||||
func (s *Scheduler) CreateContainer(config *dockerclient.ContainerConfig, name string) (*cluster.Container, error) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if config.Memory == 0 || config.CpuShares == 0 {
|
||||
return nil, fmt.Errorf("Creating containers in clustering mode requires resource constraints (-c and -m) to be set")
|
||||
}
|
||||
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
node, err := s.selectNodeForContainer(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue