Merge pull request #507 from harshavardhana/pr_out_limit_memory_at_100_buckets_and_return_error_appropriately

This commit is contained in:
Harshavardhana 2015-04-26 22:17:03 -07:00
commit f5a51ae1bb
5 changed files with 26 additions and 1 deletions

View File

@ -171,6 +171,10 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques
w.Header().Set("Connection", "close") w.Header().Set("Connection", "close")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }
case drivers.TooManyBuckets:
{
writeErrorResponse(w, req, TooManyBuckets, acceptsContentType, req.URL.Path)
}
case drivers.BucketNameInvalid: case drivers.BucketNameInvalid:
{ {
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)

View File

@ -163,6 +163,10 @@ func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Reques
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
case drivers.ObjectExists: case drivers.ObjectExists:
{ {
// we need to debate about this, if this is the right message to send back
// https://github.com/minio-io/minio/issues/505
// Ideally we can use 405 Method No Allowed
writeErrorResponse(w, req, NotImplemented, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, NotImplemented, acceptsContentType, req.URL.Path)
} }
case drivers.BadDigest: case drivers.BadDigest:

View File

@ -20,12 +20,13 @@ import (
"log" "log"
"net/http" "net/http"
"time"
router "github.com/gorilla/mux" router "github.com/gorilla/mux"
"github.com/minio-io/minio/pkg/api/config" "github.com/minio-io/minio/pkg/api/config"
"github.com/minio-io/minio/pkg/api/quota" "github.com/minio-io/minio/pkg/api/quota"
"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"
"time"
) )
// private use // private use

View File

@ -78,6 +78,9 @@ type BucketExists GenericBucketError
// BucketNotFound - requested bucket not found // BucketNotFound - requested bucket not found
type BucketNotFound GenericBucketError type BucketNotFound GenericBucketError
// TooManyBuckets - total buckets exceeded
type TooManyBuckets GenericBucketError
/// Object related errors /// Object related errors
// ObjectNotFound - requested object not found // ObjectNotFound - requested object not found
@ -149,6 +152,11 @@ func (e BucketExists) Error() string {
return "Bucket exists: " + e.Bucket return "Bucket exists: " + e.Bucket
} }
// Return string an error formatted as the given text
func (e TooManyBuckets) Error() string {
return "Bucket limit exceeded beyond 100, cannot create bucket: " + e.Bucket
}
// Return string an error formatted as the given text // Return string an error formatted as the given text
func (e BucketNotFound) Error() string { func (e BucketNotFound) Error() string {
return "Bucket not Found: " + e.Bucket return "Bucket not Found: " + e.Bucket

View File

@ -60,6 +60,10 @@ type storedObject struct {
metadata drivers.ObjectMetadata metadata drivers.ObjectMetadata
} }
const (
totalBuckets = 100
)
// Start memory object server // Start memory object server
func Start(maxSize uint64) (chan<- string, <-chan error, drivers.Driver) { func Start(maxSize uint64) (chan<- string, <-chan error, drivers.Driver) {
ctrlChannel := make(chan string) ctrlChannel := make(chan string)
@ -263,6 +267,10 @@ func (memory *memoryDriver) CreateObject(bucket, key, contentType, expectedMD5Su
// CreateBucket - create bucket in memory // CreateBucket - create bucket in memory
func (memory *memoryDriver) CreateBucket(bucketName, acl string) error { func (memory *memoryDriver) CreateBucket(bucketName, acl string) error {
memory.lock.RLock() memory.lock.RLock()
if len(memory.bucketMetadata) == totalBuckets {
memory.lock.RLock()
return iodine.New(drivers.TooManyBuckets{Bucket: bucketName}, nil)
}
if !drivers.IsValidBucket(bucketName) { if !drivers.IsValidBucket(bucketName) {
memory.lock.RUnlock() memory.lock.RUnlock()
return iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil) return iodine.New(drivers.BucketNameInvalid{Bucket: bucketName}, nil)