improve locks

This commit is contained in:
Victor Vieux 2014-11-18 23:04:11 +00:00
parent 407d0bc37f
commit 07383edd47
3 changed files with 7 additions and 5 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
swarm

View File

@ -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

View File

@ -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