Add syncQueue, cpQueue back into defer

This commit is contained in:
Harshavardhana
2015-07-13 21:42:53 -07:00
parent 22982d392b
commit db679e58ff
4 changed files with 30 additions and 15 deletions
+2 -2
View File
@@ -28,8 +28,8 @@
},
{
"ImportPath": "github.com/minio/minio-go",
"Comment": "v0.1.0-19-g198c130",
"Rev": "198c13010e7ef0b0683db9752c997838d14c1561"
"Comment": "v0.1.0-20-g58c3be1",
"Rev": "58c3be19cd8de7e3f55a14e5cfa1c0ba55aa068d"
},
{
"ImportPath": "github.com/minio/minio/pkg/iodine",
+17 -3
View File
@@ -25,6 +25,7 @@ import (
"runtime"
"sort"
"strings"
"sync"
"time"
)
@@ -188,6 +189,7 @@ func (c *Config) SetUserAgent(name string, version string, comments ...string) {
}
type api struct {
*sync.Mutex
lowLevelAPI
}
@@ -202,7 +204,7 @@ func New(config Config) (API, error) {
}
config.SetUserAgent(LibraryName, LibraryVersion, runtime.GOOS, runtime.GOARCH)
config.isUserAgentSet = false // default
return api{lowLevelAPI{&config}}, nil
return api{&sync.Mutex{}, lowLevelAPI{&config}}, nil
}
/// Object operations
@@ -473,6 +475,8 @@ func (a api) listMultipartUploadsRecursiveInRoutine(bucket, object string, ch ch
//
// This version of PutObject automatically does multipart for more than 5MB worth of data
func (a api) PutObject(bucket, object, contentType string, size int64, data io.Reader) error {
a.Lock()
defer a.Unlock()
if err := invalidBucketToError(bucket); err != nil {
return err
}
@@ -506,9 +510,15 @@ func (a api) PutObject(bucket, object, contentType string, size int64, data io.R
}
}
if !inProgress {
return a.newObjectUpload(bucket, object, contentType, size, data)
if err := a.newObjectUpload(bucket, object, contentType, size, data); err != nil {
return err
}
return nil
}
return a.continueObjectUpload(bucket, object, inProgressUploadID, size, data)
if err := a.continueObjectUpload(bucket, object, inProgressUploadID, size, data); err != nil {
return err
}
return nil
}
return errors.New("Unexpected control flow, please report this error at https://github.com/minio/minio-go/issues")
}
@@ -555,6 +565,8 @@ func (a api) RemoveObject(bucket, object string) error {
// [ us-west-1 | us-west-2 | eu-west-1 | eu-central-1 | ap-southeast-1 | ap-northeast-1 | ap-southeast-2 | sa-east-1 ]
// Default - US standard
func (a api) MakeBucket(bucket string, acl BucketACL) error {
a.Lock()
defer a.Unlock()
if err := invalidBucketToError(bucket); err != nil {
return err
}
@@ -581,6 +593,8 @@ func (a api) MakeBucket(bucket string, acl BucketACL) error {
// authenticated-read - owner gets full access, authenticated users get read access
//
func (a api) SetBucketACL(bucket string, acl BucketACL) error {
a.Lock()
defer a.Unlock()
if err := invalidBucketToError(bucket); err != nil {
return err
}
+4 -3
View File
@@ -73,6 +73,9 @@ EXAMPLES:
// doCopy - Copy a singe file from source to destination
func doCopy(cpURLs copyURLs, bar *barSend, cpQueue chan bool, wg *sync.WaitGroup) error {
defer wg.Done() // Notify that this copy routine is done.
defer func() {
<-cpQueue
}()
if !globalQuietFlag || !globalJSONFlag {
bar.SetCaption(cpURLs.SourceContent.Name + ": ")
@@ -105,10 +108,8 @@ func doCopy(cpURLs copyURLs, bar *barSend, cpQueue chan bool, wg *sync.WaitGroup
if !globalQuietFlag || !globalJSONFlag {
bar.ErrorPut(length)
}
return iodine.New(err, map[string]string{"URL": cpURLs.TargetContent.Name})
console.Errorln(iodine.ToError(err))
}
<-cpQueue // Notify the copy queue that it is free to pickup next routine.
return nil
}
+7 -7
View File
@@ -72,6 +72,9 @@ EXAMPLES:
// doSync - Sync an object to multiple destination
func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGroup) (err error) {
defer wg.Done() // Notify that this copy routine is done.
defer func() {
<-syncQueue
}()
if !globalQuietFlag || !globalJSONFlag {
bar.SetCaption(sURLs.SourceContent.Name + ": ")
@@ -81,11 +84,11 @@ func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGrou
if err != nil {
if !globalQuietFlag || !globalJSONFlag {
bar.ErrorGet(int64(length))
console.Errors(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
}
console.Errors(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
}
var targetURLs []string
@@ -113,9 +116,6 @@ func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGrou
}
}
}
<-syncQueue // Notify the copy queue that it is free to pickup next routine.
return nil
}