|
@ -25,7 +25,7 @@ import ( |
|
|
"github.com/chrislusf/seaweedfs/weed/util" |
|
|
"github.com/chrislusf/seaweedfs/weed/util" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func (fs *FilerServer) autoChunk(ctx context.Context, w http.ResponseWriter, r *http.Request, replication string, collection string, dataCenter string, rack string, ttlSec int32, ttlString string, fsync bool) { |
|
|
|
|
|
|
|
|
func (fs *FilerServer) autoChunk(ctx context.Context, w http.ResponseWriter, r *http.Request, so *filer.StorageOption) { |
|
|
|
|
|
|
|
|
// autoChunking can be set at the command-line level or as a query param. Query param overrides command-line
|
|
|
// autoChunking can be set at the command-line level or as a query param. Query param overrides command-line
|
|
|
query := r.URL.Query() |
|
|
query := r.URL.Query() |
|
@ -51,10 +51,10 @@ func (fs *FilerServer) autoChunk(ctx context.Context, w http.ResponseWriter, r * |
|
|
if r.Header.Get("Content-Type") == "" && strings.HasSuffix(r.URL.Path, "/") { |
|
|
if r.Header.Get("Content-Type") == "" && strings.HasSuffix(r.URL.Path, "/") { |
|
|
reply, err = fs.mkdir(ctx, w, r) |
|
|
reply, err = fs.mkdir(ctx, w, r) |
|
|
} else { |
|
|
} else { |
|
|
reply, md5bytes, err = fs.doPostAutoChunk(ctx, w, r, chunkSize, replication, collection, dataCenter, rack, ttlSec, ttlString, fsync) |
|
|
|
|
|
|
|
|
reply, md5bytes, err = fs.doPostAutoChunk(ctx, w, r, chunkSize, so) |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
reply, md5bytes, err = fs.doPutAutoChunk(ctx, w, r, chunkSize, replication, collection, dataCenter, rack, ttlSec, ttlString, fsync) |
|
|
|
|
|
|
|
|
reply, md5bytes, err = fs.doPutAutoChunk(ctx, w, r, chunkSize, so) |
|
|
} |
|
|
} |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
writeJsonError(w, r, http.StatusInternalServerError, err) |
|
|
writeJsonError(w, r, http.StatusInternalServerError, err) |
|
@ -66,7 +66,7 @@ func (fs *FilerServer) autoChunk(ctx context.Context, w http.ResponseWriter, r * |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (fs *FilerServer) doPostAutoChunk(ctx context.Context, w http.ResponseWriter, r *http.Request, chunkSize int32, replication string, collection string, dataCenter string, rack string, ttlSec int32, ttlString string, fsync bool) (filerResult *FilerPostResult, md5bytes []byte, replyerr error) { |
|
|
|
|
|
|
|
|
func (fs *FilerServer) doPostAutoChunk(ctx context.Context, w http.ResponseWriter, r *http.Request, chunkSize int32, so *filer.StorageOption) (filerResult *FilerPostResult, md5bytes []byte, replyerr error) { |
|
|
|
|
|
|
|
|
multipartReader, multipartReaderErr := r.MultipartReader() |
|
|
multipartReader, multipartReaderErr := r.MultipartReader() |
|
|
if multipartReaderErr != nil { |
|
|
if multipartReaderErr != nil { |
|
@ -87,46 +87,46 @@ func (fs *FilerServer) doPostAutoChunk(ctx context.Context, w http.ResponseWrite |
|
|
contentType = "" |
|
|
contentType = "" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fileChunks, md5Hash, chunkOffset, err := fs.uploadReaderToChunks(w, r, part1, chunkSize, replication, collection, dataCenter, rack, ttlString, fileName, contentType, fsync) |
|
|
|
|
|
|
|
|
fileChunks, md5Hash, chunkOffset, err := fs.uploadReaderToChunks(w, r, part1, chunkSize, fileName, contentType, so) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, nil, err |
|
|
return nil, nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fileChunks, replyerr = filer.MaybeManifestize(fs.saveAsChunk(replication, collection, dataCenter, rack, ttlString, fsync), fileChunks) |
|
|
|
|
|
|
|
|
fileChunks, replyerr = filer.MaybeManifestize(fs.saveAsChunk(so), fileChunks) |
|
|
if replyerr != nil { |
|
|
if replyerr != nil { |
|
|
glog.V(0).Infof("manifestize %s: %v", r.RequestURI, replyerr) |
|
|
glog.V(0).Infof("manifestize %s: %v", r.RequestURI, replyerr) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
md5bytes = md5Hash.Sum(nil) |
|
|
md5bytes = md5Hash.Sum(nil) |
|
|
filerResult, replyerr = fs.saveMetaData(ctx, r, fileName, replication, collection, ttlSec, contentType, md5bytes, fileChunks, chunkOffset) |
|
|
|
|
|
|
|
|
filerResult, replyerr = fs.saveMetaData(ctx, r, fileName, contentType, so, md5bytes, fileChunks, chunkOffset) |
|
|
|
|
|
|
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (fs *FilerServer) doPutAutoChunk(ctx context.Context, w http.ResponseWriter, r *http.Request, chunkSize int32, replication string, collection string, dataCenter string, rack string, ttlSec int32, ttlString string, fsync bool) (filerResult *FilerPostResult, md5bytes []byte, replyerr error) { |
|
|
|
|
|
|
|
|
func (fs *FilerServer) doPutAutoChunk(ctx context.Context, w http.ResponseWriter, r *http.Request, chunkSize int32, so *filer.StorageOption) (filerResult *FilerPostResult, md5bytes []byte, replyerr error) { |
|
|
|
|
|
|
|
|
fileName := "" |
|
|
fileName := "" |
|
|
contentType := "" |
|
|
contentType := "" |
|
|
|
|
|
|
|
|
fileChunks, md5Hash, chunkOffset, err := fs.uploadReaderToChunks(w, r, r.Body, chunkSize, replication, collection, dataCenter, rack, ttlString, fileName, contentType, fsync) |
|
|
|
|
|
|
|
|
fileChunks, md5Hash, chunkOffset, err := fs.uploadReaderToChunks(w, r, r.Body, chunkSize, fileName, contentType, so) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, nil, err |
|
|
return nil, nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fileChunks, replyerr = filer.MaybeManifestize(fs.saveAsChunk(replication, collection, dataCenter, rack, ttlString, fsync), fileChunks) |
|
|
|
|
|
|
|
|
fileChunks, replyerr = filer.MaybeManifestize(fs.saveAsChunk(so), fileChunks) |
|
|
if replyerr != nil { |
|
|
if replyerr != nil { |
|
|
glog.V(0).Infof("manifestize %s: %v", r.RequestURI, replyerr) |
|
|
glog.V(0).Infof("manifestize %s: %v", r.RequestURI, replyerr) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
md5bytes = md5Hash.Sum(nil) |
|
|
md5bytes = md5Hash.Sum(nil) |
|
|
filerResult, replyerr = fs.saveMetaData(ctx, r, fileName, replication, collection, ttlSec, contentType, md5bytes, fileChunks, chunkOffset) |
|
|
|
|
|
|
|
|
filerResult, replyerr = fs.saveMetaData(ctx, r, fileName, contentType, so, md5bytes, fileChunks, chunkOffset) |
|
|
|
|
|
|
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileName string, replication string, collection string, ttlSec int32, contentType string, md5bytes []byte, fileChunks []*filer_pb.FileChunk, chunkOffset int64) (filerResult *FilerPostResult, replyerr error) { |
|
|
|
|
|
|
|
|
func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileName string, contentType string, so *filer.StorageOption, md5bytes []byte, fileChunks []*filer_pb.FileChunk, chunkOffset int64) (filerResult *FilerPostResult, replyerr error) { |
|
|
|
|
|
|
|
|
// detect file mode
|
|
|
// detect file mode
|
|
|
modeStr := r.URL.Query().Get("mode") |
|
|
modeStr := r.URL.Query().Get("mode") |
|
@ -163,9 +163,9 @@ func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileNa |
|
|
Mode: os.FileMode(mode), |
|
|
Mode: os.FileMode(mode), |
|
|
Uid: OS_UID, |
|
|
Uid: OS_UID, |
|
|
Gid: OS_GID, |
|
|
Gid: OS_GID, |
|
|
Replication: replication, |
|
|
|
|
|
Collection: collection, |
|
|
|
|
|
TtlSec: ttlSec, |
|
|
|
|
|
|
|
|
Replication: so.Replication, |
|
|
|
|
|
Collection: so.Collection, |
|
|
|
|
|
TtlSec: so.TtlSeconds, |
|
|
Mime: contentType, |
|
|
Mime: contentType, |
|
|
Md5: md5bytes, |
|
|
Md5: md5bytes, |
|
|
FileSize: uint64(chunkOffset), |
|
|
FileSize: uint64(chunkOffset), |
|
@ -199,7 +199,7 @@ func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileNa |
|
|
return filerResult, replyerr |
|
|
return filerResult, replyerr |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Request, reader io.Reader, chunkSize int32, replication string, collection string, dataCenter string, rack string, ttlString string, fileName string, contentType string, fsync bool) ([]*filer_pb.FileChunk, hash.Hash, int64, error) { |
|
|
|
|
|
|
|
|
func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Request, reader io.Reader, chunkSize int32, fileName, contentType string, so *filer.StorageOption) ([]*filer_pb.FileChunk, hash.Hash, int64, error) { |
|
|
var fileChunks []*filer_pb.FileChunk |
|
|
var fileChunks []*filer_pb.FileChunk |
|
|
|
|
|
|
|
|
md5Hash := md5.New() |
|
|
md5Hash := md5.New() |
|
@ -211,7 +211,7 @@ func (fs *FilerServer) uploadReaderToChunks(w http.ResponseWriter, r *http.Reque |
|
|
limitedReader := io.LimitReader(partReader, int64(chunkSize)) |
|
|
limitedReader := io.LimitReader(partReader, int64(chunkSize)) |
|
|
|
|
|
|
|
|
// assign one file id for one chunk
|
|
|
// assign one file id for one chunk
|
|
|
fileId, urlLocation, auth, assignErr := fs.assignNewFileInfo(replication, collection, dataCenter, rack, ttlString, fsync) |
|
|
|
|
|
|
|
|
fileId, urlLocation, auth, assignErr := fs.assignNewFileInfo(so) |
|
|
if assignErr != nil { |
|
|
if assignErr != nil { |
|
|
return nil, nil, 0, assignErr |
|
|
return nil, nil, 0, assignErr |
|
|
} |
|
|
} |
|
@ -255,11 +255,11 @@ func (fs *FilerServer) doUpload(urlLocation string, w http.ResponseWriter, r *ht |
|
|
return uploadResult, err |
|
|
return uploadResult, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (fs *FilerServer) saveAsChunk(replication string, collection string, dataCenter string, rack string, ttlString string, fsync bool) filer.SaveDataAsChunkFunctionType { |
|
|
|
|
|
|
|
|
func (fs *FilerServer) saveAsChunk(so *filer.StorageOption) filer.SaveDataAsChunkFunctionType { |
|
|
|
|
|
|
|
|
return func(reader io.Reader, name string, offset int64) (*filer_pb.FileChunk, string, string, error) { |
|
|
return func(reader io.Reader, name string, offset int64) (*filer_pb.FileChunk, string, string, error) { |
|
|
// assign one file id for one chunk
|
|
|
// assign one file id for one chunk
|
|
|
fileId, urlLocation, auth, assignErr := fs.assignNewFileInfo(replication, collection, dataCenter, rack, ttlString, fsync) |
|
|
|
|
|
|
|
|
fileId, urlLocation, auth, assignErr := fs.assignNewFileInfo(so) |
|
|
if assignErr != nil { |
|
|
if assignErr != nil { |
|
|
return nil, "", "", assignErr |
|
|
return nil, "", "", assignErr |
|
|
} |
|
|
} |
|
@ -270,7 +270,7 @@ func (fs *FilerServer) saveAsChunk(replication string, collection string, dataCe |
|
|
return nil, "", "", uploadErr |
|
|
return nil, "", "", uploadErr |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return uploadResult.ToPbFileChunk(fileId, offset), collection, replication, nil |
|
|
|
|
|
|
|
|
return uploadResult.ToPbFileChunk(fileId, offset), so.Collection, so.Replication, nil |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|