From d4e71beb540e49e2a45aff9951bad28ded50309d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 13 Jun 2015 11:20:35 -0700 Subject: [PATCH] Add time.Since on buckets created time to avoid deleting buckets spuriously during eviction of objects --- pkg/storage/drivers/memory/memory.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/storage/drivers/memory/memory.go b/pkg/storage/drivers/memory/memory.go index b6426f015..ad05fa479 100644 --- a/pkg/storage/drivers/memory/memory.go +++ b/pkg/storage/drivers/memory/memory.go @@ -44,6 +44,7 @@ type memoryDriver struct { objects *trove.Cache multiPartObjects *trove.Cache maxSize uint64 + expiration time.Duration } type storedBucket struct { @@ -73,6 +74,7 @@ func Start(maxSize uint64, expiration time.Duration) (chan<- string, <-chan erro memory.storedBuckets = make(map[string]storedBucket) memory.objects = trove.NewCache(maxSize, expiration) memory.maxSize = maxSize + memory.expiration = expiration memory.multiPartObjects = trove.NewCache(0, time.Duration(0)) memory.lock = new(sync.RWMutex) @@ -517,7 +519,9 @@ func (memory *memoryDriver) expiredObject(a ...interface{}) { delete(storedBucket.objectMetadata, key) // remove bucket if no objects found anymore if len(storedBucket.objectMetadata) == 0 { - delete(memory.storedBuckets, bucket) + if time.Since(memory.storedBuckets[bucket].bucketMetadata.Created) > memory.expiration { + delete(memory.storedBuckets, bucket) + } } } debug.FreeOSMemory()