Skip to content

Commit

Permalink
[wip] namespace update locking fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbw committed Nov 15, 2019
1 parent 6a7ba6b commit 6b07265
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions go-controller/pkg/ovn/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,13 @@ func (oc *Controller) multicastDeleteNamespace(ns *kapi.Namespace) {
func (oc *Controller) AddNamespace(ns *kapi.Namespace) {
logrus.Debugf("Adding namespace: %s", ns.Name)
oc.namespaceMutexMutex.Lock()
if oc.namespaceMutex[ns.Name] == nil {
oc.namespaceMutex[ns.Name] = &sync.Mutex{}
mutex, ok := oc.namespaceMutex[ns.Name]
if !ok {
mutex = &sync.Mutex{}
oc.namespaceMutex[ns.Name] = mutex
}

// A big fat lock per namespace to prevent race conditions
// with namespace resources like address sets and deny acls.
oc.namespaceMutex[ns.Name].Lock()
defer oc.namespaceMutex[ns.Name].Unlock()
mutex.Lock()
defer mutex.Unlock()
oc.namespaceMutexMutex.Unlock()

oc.namespaceAddressSet[ns.Name] = make(map[string]string)
Expand Down Expand Up @@ -204,6 +203,12 @@ func (oc *Controller) AddNamespace(ns *kapi.Namespace) {
func (oc *Controller) updateNamespace(old, newer *kapi.Namespace) {
logrus.Debugf("Updating namespace: old %s new %s", old.Name, newer.Name)

mutex := oc.getNamespaceLock(newer.Name)
if mutex == nil {
return
}
defer mutex.Unlock()

// A big fat lock per namespace to prevent race conditions
// with namespace resources like address sets and deny acls.
oc.namespaceMutex[newer.Name].Lock()
Expand Down Expand Up @@ -244,12 +249,5 @@ func (oc *Controller) getNamespaceLock(ns string) *sync.Mutex {

// lock the individual namespace
mutex.Lock()

// check that the namespace wasn't deleted between getting the two locks
if _, ok := oc.namespaceMutex[ns]; !ok {
mutex.Unlock()
return nil
}

return mutex
}

0 comments on commit 6b07265

Please sign in to comment.