mirror of https://github.com/minio/minio.git
Merge pull request #547 from fkautz/pr_out_removing_entity_too_large_errors_from_memory_driver
This commit is contained in:
commit
63ba97fd8e
|
@ -19,19 +19,17 @@ package memory
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"runtime/debug"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/minio-io/minio/pkg/iodine"
|
"github.com/minio-io/minio/pkg/iodine"
|
||||||
"github.com/minio-io/minio/pkg/storage/drivers"
|
"github.com/minio-io/minio/pkg/storage/drivers"
|
||||||
|
@ -260,11 +258,6 @@ func (memory *memoryDriver) CreateObject(bucket, key, contentType, expectedMD5Su
|
||||||
}
|
}
|
||||||
if uint64(totalLength)+memory.totalSize > memory.maxSize {
|
if uint64(totalLength)+memory.totalSize > memory.maxSize {
|
||||||
memory.objects.RemoveOldest()
|
memory.objects.RemoveOldest()
|
||||||
return iodine.New(drivers.EntityTooLarge{
|
|
||||||
Size: strconv.FormatInt(int64(totalLength), 10),
|
|
||||||
TotalSize: strconv.FormatUint(memory.totalSize, 10),
|
|
||||||
MaxSize: strconv.FormatUint(memory.maxSize, 10),
|
|
||||||
}, nil)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,24 +286,14 @@ func (memory *memoryDriver) CreateObject(bucket, key, contentType, expectedMD5Su
|
||||||
memory.lock.Unlock()
|
memory.lock.Unlock()
|
||||||
return iodine.New(drivers.ObjectExists{Bucket: bucket, Object: key}, nil)
|
return iodine.New(drivers.ObjectExists{Bucket: bucket, Object: key}, nil)
|
||||||
}
|
}
|
||||||
// could lead to out of Memory, verify and proceed
|
|
||||||
if uint64(bytesBuffer.Len())+memory.totalSize > memory.maxSize {
|
|
||||||
memory.objects.RemoveOldest()
|
|
||||||
memory.lock.Unlock()
|
|
||||||
return iodine.New(drivers.EntityTooLarge{
|
|
||||||
Size: strconv.FormatInt(int64(bytesBuffer.Len()), 10),
|
|
||||||
TotalSize: strconv.FormatUint(memory.totalSize, 10),
|
|
||||||
MaxSize: strconv.FormatUint(memory.maxSize, 10),
|
|
||||||
}, nil)
|
|
||||||
}
|
|
||||||
memory.objectMetadata[objectKey] = newObject
|
memory.objectMetadata[objectKey] = newObject
|
||||||
memory.objects.Add(objectKey, bytesBuffer.Bytes())
|
memory.objects.Add(objectKey, bytesBuffer.Bytes())
|
||||||
memory.totalSize = memory.totalSize + uint64(newObject.metadata.Size)
|
memory.totalSize = memory.totalSize + uint64(newObject.metadata.Size)
|
||||||
if memory.totalSize > memory.maxSize {
|
for memory.totalSize > memory.maxSize {
|
||||||
memory.objects.RemoveOldest()
|
memory.objects.RemoveOldest()
|
||||||
}
|
}
|
||||||
log.Println("Size:", memory.totalSize)
|
|
||||||
memory.lock.Unlock()
|
memory.lock.Unlock()
|
||||||
|
debug.FreeOSMemory()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,9 +476,8 @@ func (memory *memoryDriver) GetObjectMetadata(bucket, key, prefix string) (drive
|
||||||
func (memory *memoryDriver) evictObject(key lru.Key, value interface{}) {
|
func (memory *memoryDriver) evictObject(key lru.Key, value interface{}) {
|
||||||
k := key.(string)
|
k := key.(string)
|
||||||
memory.totalSize = memory.totalSize - uint64(memory.objectMetadata[k].metadata.Size)
|
memory.totalSize = memory.totalSize - uint64(memory.objectMetadata[k].metadata.Size)
|
||||||
log.Println("evicting:", k, memory.objectMetadata[k].metadata.Size)
|
|
||||||
log.Println("Size:", memory.totalSize)
|
|
||||||
delete(memory.objectMetadata, k)
|
delete(memory.objectMetadata, k)
|
||||||
|
debug.FreeOSMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (memory *memoryDriver) expireObjects() {
|
func (memory *memoryDriver) expireObjects() {
|
||||||
|
|
Loading…
Reference in New Issue