aboutsummaryrefslogtreecommitdiff
path: root/go/operation/submit.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2014-03-09 23:54:07 -0700
committerChris Lu <chris.lu@gmail.com>2014-03-09 23:54:07 -0700
commita121453188f14ac3580bf61b47268bf029d61390 (patch)
tree8c72b2455111bd8e85c2d027a253bc42c6fde7bc /go/operation/submit.go
parenteac9c4d86b7c7c9683504566e680bfb6531bfbff (diff)
downloadseaweedfs-a121453188f14ac3580bf61b47268bf029d61390.tar.xz
seaweedfs-a121453188f14ac3580bf61b47268bf029d61390.zip
benchmarking writing data to a specific collection
Diffstat (limited to 'go/operation/submit.go')
-rw-r--r--go/operation/submit.go34
1 files changed, 19 insertions, 15 deletions
diff --git a/go/operation/submit.go b/go/operation/submit.go
index 814c64957..693b90db1 100644
--- a/go/operation/submit.go
+++ b/go/operation/submit.go
@@ -12,14 +12,16 @@ import (
)
type FilePart struct {
- Reader io.Reader
- FileName string
- FileSize int64
- IsGzipped bool
- MimeType string
- ModTime int64 //in seconds
- Server string //this comes from assign result
- Fid string //this comes from assign result, but customizable
+ Reader io.Reader
+ FileName string
+ FileSize int64
+ IsGzipped bool
+ MimeType string
+ ModTime int64 //in seconds
+ Replication string
+ Collection string
+ Server string //this comes from assign result
+ Fid string //this comes from assign result, but customizable
}
type SubmitResult struct {
@@ -30,12 +32,12 @@ type SubmitResult struct {
Error string `json:"error"`
}
-func SubmitFiles(master string, files []FilePart, replication string, maxMB int) ([]SubmitResult, error) {
+func SubmitFiles(master string, files []FilePart, replication string, collection string, maxMB int) ([]SubmitResult, error) {
results := make([]SubmitResult, len(files))
for index, file := range files {
results[index].FileName = file.FileName
}
- ret, err := Assign(master, len(files), replication)
+ ret, err := Assign(master, len(files), replication, collection)
if err != nil {
for index, _ := range files {
results[index].Error = err.Error()
@@ -48,7 +50,9 @@ func SubmitFiles(master string, files []FilePart, replication string, maxMB int)
file.Fid = file.Fid + "_" + strconv.Itoa(index)
}
file.Server = ret.PublicUrl
- results[index].Size, err = file.Upload(maxMB, master, replication)
+ file.Replication = replication
+ file.Collection = collection
+ results[index].Size, err = file.Upload(maxMB, master)
if err != nil {
results[index].Error = err.Error()
}
@@ -95,7 +99,7 @@ func newFilePart(fullPathFilename string) (ret FilePart, err error) {
return ret, nil
}
-func (fi FilePart) Upload(maxMB int, master, replication string) (retSize int, err error) {
+func (fi FilePart) Upload(maxMB int, master string) (retSize int, err error) {
fileUrl := "http://" + fi.Server + "/" + fi.Fid
if fi.ModTime != 0 {
fileUrl += "?ts=" + strconv.Itoa(int(fi.ModTime))
@@ -108,7 +112,7 @@ func (fi FilePart) Upload(maxMB int, master, replication string) (retSize int, e
chunks := fi.FileSize/chunkSize + 1
fids := make([]string, 0)
for i := int64(0); i < chunks; i++ {
- id, count, e := upload_one_chunk(fi.FileName+"-"+strconv.FormatInt(i+1, 10), io.LimitReader(fi.Reader, chunkSize), master, replication)
+ id, count, e := upload_one_chunk(fi.FileName+"-"+strconv.FormatInt(i+1, 10), io.LimitReader(fi.Reader, chunkSize), master, fi.Replication, fi.Collection)
if e != nil {
return 0, e
}
@@ -126,8 +130,8 @@ func (fi FilePart) Upload(maxMB int, master, replication string) (retSize int, e
return
}
-func upload_one_chunk(filename string, reader io.Reader, master, replication string) (fid string, size int, e error) {
- ret, err := Assign(master, 1, replication)
+func upload_one_chunk(filename string, reader io.Reader, master, replication string, collection string) (fid string, size int, e error) {
+ ret, err := Assign(master, 1, replication, collection)
if err != nil {
return "", 0, err
}