Skip to content

Commit

Permalink
Do not hold the lock for a long time
Browse files Browse the repository at this point in the history
  • Loading branch information
lavalamp committed Aug 19, 2016
1 parent 57ad590 commit edc598a
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions pkg/client/cache/delta_fifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,21 +496,34 @@ func (f *DeltaFIFO) Replace(list []interface{}, resourceVersion string) error {

// Resync will send a sync event for each item
func (f *DeltaFIFO) Resync() error {
var keys []string
func() {
f.lock.RLock()
defer f.lock.RUnlock()
keys = f.knownObjects.ListKeys()
}()
for _, k := range keys {
if err := f.syncKey(k); err != nil {
return err
}
}
return nil
}

func (f *DeltaFIFO) syncKey(key string) error {
f.lock.Lock()
defer f.lock.Unlock()
for _, k := range f.knownObjects.ListKeys() {
obj, exists, err := f.knownObjects.GetByKey(k)
if err != nil {
glog.Errorf("Unexpected error %v during lookup of key %v, unable to queue object for sync", err, k)
continue
} else if !exists {
glog.Infof("Key %v does not exist in known objects store, unable to queue object for sync", k)
continue
}
obj, exists, err := f.knownObjects.GetByKey(key)
if err != nil {
glog.Errorf("Unexpected error %v during lookup of key %v, unable to queue object for sync", err, key)
return nil
} else if !exists {
glog.Infof("Key %v does not exist in known objects store, unable to queue object for sync", key)
return nil
}

if err := f.queueActionLocked(Sync, obj); err != nil {
return fmt.Errorf("couldn't queue object: %v", err)
}
if err := f.queueActionLocked(Sync, obj); err != nil {
return fmt.Errorf("couldn't queue object: %v", err)
}
return nil
}
Expand Down

0 comments on commit edc598a

Please sign in to comment.