SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
refactoring: go fmt, reorg
Chris Lu8db9319a064c
diff --git a/weed/filer2/filechunks.go b/weed/filer2/filechunks.goindex bd4a57f0fb..c4c77d2701 100644--- a/weed/filer2/filechunks.go+++ b/weed/filer2/filechunks.go@@ -82,10 +82,10 @@ func ReadFromChunks(chunks []*filer_pb.FileChunk, offset int64, size int) (viewsfunc logPrintf(name string, visibles []*visibleInterval) {/*- log.Printf("%s len %d", name, len(visibles))- for _, v := range visibles {- log.Printf("%s: => %+v", name, v)- }+ log.Printf("%s len %d", name, len(visibles))+ for _, v := range visibles {+ log.Printf("%s: => %+v", name, v)+ }*/}diff --git a/weed/server/filer_server_handlers_write.go b/weed/server/filer_server_handlers_write.goindex 53b8d9e673..c4152ba4fe 100644--- a/weed/server/filer_server_handlers_write.go+++ b/weed/server/filer_server_handlers_write.go@@ -8,13 +8,13 @@ import ("net/url""strconv""strings"+ "time""github.com/chrislusf/seaweedfs/weed/filer2""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/operation""github.com/chrislusf/seaweedfs/weed/pb/filer_pb""github.com/chrislusf/seaweedfs/weed/util"- "time")type FilerPostResult struct {diff --git a/weed/server/filer_server_handlers_write_autochunk.go b/weed/server/filer_server_handlers_write_autochunk.goindex 76a720e49a..a1f0fa27fb 100644--- a/weed/server/filer_server_handlers_write_autochunk.go+++ b/weed/server/filer_server_handlers_write_autochunk.go@@ -3,15 +3,16 @@ package weed_serverimport ("bytes""io"+ "io/ioutil""net/http""path""strconv"+ "time"+"github.com/chrislusf/seaweedfs/weed/filer2""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/operation""github.com/chrislusf/seaweedfs/weed/pb/filer_pb"- "time"- "io/ioutil")func (fs *FilerServer) autoChunk(w http.ResponseWriter, r *http.Request, replication string, collection string) bool {diff --git a/weed/server/filer_server_handlers_write_monopart.go b/weed/server/filer_server_handlers_write_monopart.goindex 550d32aed5..30fbcf7f92 100644--- a/weed/server/filer_server_handlers_write_monopart.go+++ b/weed/server/filer_server_handlers_write_monopart.go@@ -5,13 +5,56 @@ import ("crypto/md5""encoding/base64""fmt"+ "io""io/ioutil"+ "mime/multipart""net/http"+ "net/textproto""strings""github.com/chrislusf/seaweedfs/weed/glog")+var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")++func escapeQuotes(s string) string {+ return quoteEscaper.Replace(s)+}++func createFormFile(writer *multipart.Writer, fieldname, filename, mime string) (io.Writer, error) {+ h := make(textproto.MIMEHeader)+ h.Set("Content-Disposition",+ fmt.Sprintf(`form-data; name="%s"; filename="%s"`,+ escapeQuotes(fieldname), escapeQuotes(filename)))+ if len(mime) == 0 {+ mime = "application/octet-stream"+ }+ h.Set("Content-Type", mime)+ return writer.CreatePart(h)+}++func makeFormData(filename, mimeType string, content io.Reader) (formData io.Reader, contentType string, err error) {+ buf := new(bytes.Buffer)+ writer := multipart.NewWriter(buf)+ defer writer.Close()++ part, err := createFormFile(writer, "file", filename, mimeType)+ if err != nil {+ glog.V(0).Infoln(err)+ return+ }+ _, err = io.Copy(part, content)+ if err != nil {+ glog.V(0).Infoln(err)+ return+ }++ formData = buf+ contentType = writer.FormDataContentType()++ return+}+func checkContentMD5(w http.ResponseWriter, r *http.Request) (err error) {if contentMD5 := r.Header.Get("Content-MD5"); contentMD5 != "" {buf, _ := ioutil.ReadAll(r.Body)@@ -65,3 +108,32 @@ func (fs *FilerServer) monolithicUploadAnalyzer(w http.ResponseWriter, r *http.R}return}++func multipartHttpBodyBuilder(w http.ResponseWriter, r *http.Request, fileName string) (err error) {+ body, contentType, te := makeFormData(fileName, r.Header.Get("Content-Type"), r.Body)+ if te != nil {+ glog.V(0).Infoln("S3 protocol to raw seaweed protocol failed", te.Error())+ writeJsonError(w, r, http.StatusInternalServerError, te)+ err = te+ return+ }++ if body != nil {+ switch v := body.(type) {+ case *bytes.Buffer:+ r.ContentLength = int64(v.Len())+ case *bytes.Reader:+ r.ContentLength = int64(v.Len())+ case *strings.Reader:+ r.ContentLength = int64(v.Len())+ }+ }++ r.Header.Set("Content-Type", contentType)+ rc, ok := body.(io.ReadCloser)+ if !ok && body != nil {+ rc = ioutil.NopCloser(body)+ }+ r.Body = rc+ return+}diff --git a/weed/server/filer_server_handlers_write_multipart.go b/weed/server/filer_server_handlers_write_multipart.goindex edf9305c67..91f892b524 100644--- a/weed/server/filer_server_handlers_write_multipart.go+++ b/weed/server/filer_server_handlers_write_multipart.go@@ -2,58 +2,14 @@ package weed_serverimport ("bytes"- "fmt"- "io""io/ioutil"- "mime/multipart""net/http"- "net/textproto""strings""github.com/chrislusf/seaweedfs/weed/glog""github.com/chrislusf/seaweedfs/weed/storage")-var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")--func escapeQuotes(s string) string {- return quoteEscaper.Replace(s)-}--func createFormFile(writer *multipart.Writer, fieldname, filename, mime string) (io.Writer, error) {- h := make(textproto.MIMEHeader)- h.Set("Content-Disposition",- fmt.Sprintf(`form-data; name="%s"; filename="%s"`,- escapeQuotes(fieldname), escapeQuotes(filename)))- if len(mime) == 0 {- mime = "application/octet-stream"- }- h.Set("Content-Type", mime)- return writer.CreatePart(h)-}--func makeFormData(filename, mimeType string, content io.Reader) (formData io.Reader, contentType string, err error) {- buf := new(bytes.Buffer)- writer := multipart.NewWriter(buf)- defer writer.Close()-- part, err := createFormFile(writer, "file", filename, mimeType)- if err != nil {- glog.V(0).Infoln(err)- return- }- _, err = io.Copy(part, content)- if err != nil {- glog.V(0).Infoln(err)- return- }-- formData = buf- contentType = writer.FormDataContentType()-- return-}-func (fs *FilerServer) multipartUploadAnalyzer(w http.ResponseWriter, r *http.Request, replication, collection string) (fileId, urlLocation string, err error) {//Default handle way for http multipartif r.Method == "PUT" {@@ -81,32 +37,3 @@ func (fs *FilerServer) multipartUploadAnalyzer(w http.ResponseWriter, r *http.Re}return}--func multipartHttpBodyBuilder(w http.ResponseWriter, r *http.Request, fileName string) (err error) {- body, contentType, te := makeFormData(fileName, r.Header.Get("Content-Type"), r.Body)- if te != nil {- glog.V(0).Infoln("S3 protocol to raw seaweed protocol failed", te.Error())- writeJsonError(w, r, http.StatusInternalServerError, te)- err = te- return- }-- if body != nil {- switch v := body.(type) {- case *bytes.Buffer:- r.ContentLength = int64(v.Len())- case *bytes.Reader:- r.ContentLength = int64(v.Len())- case *strings.Reader:- r.ContentLength = int64(v.Len())- }- }-- r.Header.Set("Content-Type", contentType)- rc, ok := body.(io.ReadCloser)- if !ok && body != nil {- rc = ioutil.NopCloser(body)- }- r.Body = rc- return-}