mirror of
https://github.com/minio/minio.git
synced 2025-01-14 16:25:01 -05:00
Merge pull request #533 from fkautz/pr_out_simplifying_memory_sleep_logic
This commit is contained in:
commit
b6daf99dcd
@ -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…
Reference in New Issue
Block a user