mirror of
https://github.com/minio/minio.git
synced 2025-11-21 10:16:03 -05:00
Forbid the upload of files bigger than the memory backend capacity
This commit is contained in:
@@ -271,8 +271,11 @@ func (memory *memoryDriver) createObject(bucket, key, contentType, expectedMD5Su
|
||||
totalLength := len(readBytes)
|
||||
|
||||
memory.lock.Lock()
|
||||
memory.objects.Set(objectKey, readBytes)
|
||||
ok := memory.objects.Set(objectKey, readBytes)
|
||||
memory.lock.Unlock()
|
||||
if !ok {
|
||||
return "", iodine.New(drivers.InternalError{}, nil)
|
||||
}
|
||||
// setting up for de-allocation
|
||||
readBytes = nil
|
||||
|
||||
|
||||
@@ -115,23 +115,28 @@ func (r *Cache) Get(key string) (interface{}, bool) {
|
||||
}
|
||||
|
||||
// Set will persist a value to the cache
|
||||
func (r *Cache) Set(key string, value interface{}) {
|
||||
func (r *Cache) Set(key string, value interface{}) bool {
|
||||
r.Lock()
|
||||
// remove random key if only we reach the maxSize threshold,
|
||||
// if not assume infinite memory
|
||||
defer r.Unlock()
|
||||
valueLen := uint64(len(value.([]byte)))
|
||||
if r.maxSize > 0 {
|
||||
// check if the size of the object is not bigger than the
|
||||
// capacity of the cache
|
||||
if valueLen > r.maxSize {
|
||||
return false
|
||||
}
|
||||
// remove random key if only we reach the maxSize threshold
|
||||
for key := range r.items {
|
||||
for (r.currentSize + uint64(len(value.([]byte)))) > r.maxSize {
|
||||
for (r.currentSize + valueLen) > r.maxSize {
|
||||
r.Delete(key)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
r.items[key] = value
|
||||
r.currentSize += uint64(len(value.([]byte)))
|
||||
r.currentSize += valueLen
|
||||
r.updatedAt[key] = time.Now()
|
||||
r.Unlock()
|
||||
return
|
||||
return true
|
||||
}
|
||||
|
||||
// Expire expires keys which have expired
|
||||
|
||||
Reference in New Issue
Block a user