Merge pull request #533 from fkautz/pr_out_simplifying_memory_sleep_logic

master
Frederick F. Kautz IV 10 years ago
commit b6daf99dcd
  1. 40
      pkg/storage/drivers/memory/memory.go

@ -484,34 +484,30 @@ func (memory *memoryDriver) expireObjects() {
return return
} }
var keysToRemove []string var keysToRemove []string
memory.lock.RLock() if len(memory.objectMetadata) > 0 {
var earliest time.Time memory.lock.RLock()
empty := true var earliest time.Time
for key, object := range memory.objectMetadata { for key, object := range memory.objectMetadata {
if empty { if time.Now().Add(-memory.expiration).After(object.metadata.Created) {
empty = false keysToRemove = append(keysToRemove, key)
} } else {
if time.Now().Add(-memory.expiration).After(object.metadata.Created) { if object.metadata.Created.Before(earliest) {
keysToRemove = append(keysToRemove, key) earliest = object.metadata.Created
} else { }
if object.metadata.Created.Before(earliest) {
earliest = object.metadata.Created
} }
} }
} memory.lock.RUnlock()
memory.lock.RUnlock() memory.lock.Lock()
memory.lock.Lock() for _, key := range keysToRemove {
for _, key := range keysToRemove { memory.objects.Remove(key)
memory.objects.Remove(key) }
} memory.lock.Unlock()
memory.lock.Unlock()
if empty {
time.Sleep(memory.expiration)
} else {
sleepFor := earliest.Sub(time.Now()) sleepFor := earliest.Sub(time.Now())
if sleepFor > 0 { if sleepFor > 0 {
time.Sleep(sleepFor) time.Sleep(sleepFor)
} }
} else {
time.Sleep(memory.expiration)
} }
} }
} }

Loading…
Cancel
Save