Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added retry on failure to client upload

  • Loading branch information...
commit 1a9b14550afb9538ba283200d9390adc3c1ad4e4 1 parent e0dceeb
@jaredwilkening jaredwilkening authored
Showing with 26 additions and 3 deletions.
  1. +23 −3 shock-client/pcreate.go
  2. +3 −0  shock-server/node/update.go
View
26 shock-client/pcreate.go
@@ -13,9 +13,9 @@ import (
func uploader(args ...interface{}) interface{} {
n := args[0].(lib.Node)
part := args[1].(int)
- r := args[2].(io.Reader)
+ fh := args[2].(*os.File)
size := args[3].(int64)
- return n.UploadPart(strconv.Itoa(part), r, size)
+ return n.UploadPart(strconv.Itoa(part), io.NewSectionReader(fh, int64(part-1)*conf.CHUNK_SIZE, size), size)
}
func pcreate(args []string) (err error) {
@@ -71,9 +71,29 @@ func pcreate(args []string) (err error) {
if size*(int64(i)+1) > filesize {
size = filesize - size*(int64(i))
}
- workers.Add(uploader, n, (i + 1), io.NewSectionReader(fh, int64(i)*conf.CHUNK_SIZE, size), size)
+ workers.Add(uploader, n, (i + 1), fh, size)
}
workers.Wait()
+ maxRetries := 10
+ for i := 1; i <= maxRetries; i++ {
+ errCount := 0
+ completed_jobs := workers.Results()
+ for _, job := range completed_jobs {
+ if job.Result != nil {
+ err := job.Result.(error)
+ println("Chunk", job.Args[1].(int), "error:", err.Error())
+ workers.Add(job.F, job.Args...)
+ errCount++
+ }
+ }
+ if errCount == 0 {
+ println("All chunks successfully upload.")
+ break
+ } else {
+ println("Retry", i, "of", maxRetries)
+ workers.Wait()
+ }
+ }
workers.Stop()
n.Get()
View
3  shock-server/node/update.go
@@ -109,15 +109,18 @@ func (node *Node) Update(params map[string]string, files FormFiles) (err error)
if parts_count > 1 {
for key, file := range files {
if node.HasFile() {
+ LockMgr.UnlockPartOp()
return errors.New(e.FileImut)
}
keyn, errf := strconv.Atoi(key)
if errf == nil && keyn <= parts_count {
err = node.addPart(keyn-1, &file)
if err != nil {
+ LockMgr.UnlockPartOp()
return err
}
} else {
+ LockMgr.UnlockPartOp()
return errors.New("invalid file parameter")
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.