format changes

This commit is contained in:
chrislusf 2015-12-14 22:38:58 -08:00
parent df5e54e02a
commit e921cb1a9d
9 changed files with 30 additions and 34 deletions

View file

@ -74,7 +74,7 @@ func (cm *ChunkManifest) DeleteChunks(master string) error {
for _, ci := range cm.Chunks { for _, ci := range cm.Chunks {
if e := DeleteFile(master, ci.Fid, ""); e != nil { if e := DeleteFile(master, ci.Fid, ""); e != nil {
deleteError++ deleteError++
glog.V(0).Infof("Delete %s error: %s, master: %s", ci.Fid, e.Error(), master) glog.V(0).Infof("Delete %s error: %v, master: %s", ci.Fid, e, master)
} }
} }
if deleteError > 0 { if deleteError > 0 {

View file

@ -3,6 +3,7 @@ package operation
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"net/url" "net/url"
"strings" "strings"
"sync" "sync"
@ -23,9 +24,13 @@ type DeleteResult struct {
func DeleteFile(master string, fileId string, jwt security.EncodedJwt) error { func DeleteFile(master string, fileId string, jwt security.EncodedJwt) error {
fileUrl, err := LookupFileId(master, fileId) fileUrl, err := LookupFileId(master, fileId)
if err != nil { if err != nil {
return err return fmt.Errorf("Failed to lookup %s:%v", fileId, err)
} }
return util.Delete(fileUrl, jwt) err = util.Delete(fileUrl, jwt)
if err != nil {
return fmt.Errorf("Failed to delete %s:%v", fileUrl, err)
}
return nil
} }
func ParseFileId(fid string) (vid string, key_cookie string, err error) { func ParseFileId(fid string) (vid string, key_cookie string, err error) {

View file

@ -4,13 +4,12 @@ import (
"bytes" "bytes"
"io" "io"
"mime" "mime"
"net/url"
"os" "os"
"path" "path"
"strconv" "strconv"
"strings" "strings"
"net/url"
"github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/glog"
"github.com/chrislusf/seaweedfs/go/security" "github.com/chrislusf/seaweedfs/go/security"
) )
@ -188,7 +187,7 @@ func upload_chunked_file_manifest(fileUrl string, manifest *ChunkManifest, jwt s
glog.V(4).Info("Uploading chunks manifest ", manifest.Name, " to ", fileUrl, "...") glog.V(4).Info("Uploading chunks manifest ", manifest.Name, " to ", fileUrl, "...")
u, _ := url.Parse(fileUrl) u, _ := url.Parse(fileUrl)
q := u.Query() q := u.Query()
q.Set("cm", "1") q.Set("cm", "true")
u.RawQuery = q.Encode() u.RawQuery = q.Encode()
_, e = Upload(u.String(), manifest.Name, bufReader, false, "application/json", jwt) _, e = Upload(u.String(), manifest.Name, bufReader, false, "application/json", jwt)
return e return e

View file

@ -14,8 +14,8 @@ import (
"github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/glog"
"github.com/chrislusf/seaweedfs/go/images" "github.com/chrislusf/seaweedfs/go/images"
"github.com/chrislusf/seaweedfs/go/util"
"github.com/chrislusf/seaweedfs/go/operation" "github.com/chrislusf/seaweedfs/go/operation"
"github.com/chrislusf/seaweedfs/go/util"
) )
const ( const (
@ -53,7 +53,9 @@ func (n *Needle) String() (str string) {
return return
} }
func ParseUpload(r *http.Request) (fileName string, data []byte, mimeType string, isGzipped bool, modifiedTime uint64, ttl *TTL, isChunkedFile bool, e error) { func ParseUpload(r *http.Request) (
fileName string, data []byte, mimeType string, isGzipped bool,
modifiedTime uint64, ttl *TTL, isChunkedFile bool, e error) {
form, fe := r.MultipartReader() form, fe := r.MultipartReader()
if fe != nil { if fe != nil {
glog.V(0).Infoln("MultipartReader [ERROR]", fe) glog.V(0).Infoln("MultipartReader [ERROR]", fe)
@ -163,7 +165,7 @@ func NewNeedle(r *http.Request, fixJpgOrientation bool) (n *Needle, e error) {
} }
if isChunkedFile { if isChunkedFile {
n.SetChunkManifest() n.SetIsChunkManifest()
} }
if fixJpgOrientation { if fixJpgOrientation {

View file

@ -16,7 +16,7 @@ const (
FlagHasMime = 0x04 FlagHasMime = 0x04
FlagHasLastModifiedDate = 0x08 FlagHasLastModifiedDate = 0x08
FlagHasTtl = 0x10 FlagHasTtl = 0x10
FlagChunkManifest = 0x80 FlagIsChunkManifest = 0x80
LastModifiedBytesLength = 5 LastModifiedBytesLength = 5
TtlBytesLength = 2 TtlBytesLength = 2
) )
@ -283,9 +283,9 @@ func (n *Needle) SetHasTtl() {
} }
func (n *Needle) IsChunkedManifest() bool { func (n *Needle) IsChunkedManifest() bool {
return n.Flags&FlagChunkManifest > 0 return n.Flags&FlagIsChunkManifest > 0
} }
func (n *Needle) SetChunkManifest() { func (n *Needle) SetIsChunkManifest() {
n.Flags = n.Flags | FlagChunkManifest n.Flags = n.Flags | FlagIsChunkManifest
} }

View file

@ -2,6 +2,8 @@ package util
import ( import (
"bytes" "bytes"
"encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -9,10 +11,7 @@ import (
"net/url" "net/url"
"strings" "strings"
"encoding/json"
"github.com/chrislusf/seaweedfs/go/security" "github.com/chrislusf/seaweedfs/go/security"
"github.com/syndtr/goleveldb/leveldb/errors"
) )
var ( var (

View file

@ -3,11 +3,9 @@ package main
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"io/ioutil"
"strings" "strings"
"github.com/chrislusf/seaweedfs/go/operation" "github.com/chrislusf/seaweedfs/go/operation"

View file

@ -1,18 +1,16 @@
package weed_server package weed_server
import ( import (
"bytes"
"io" "io"
"mime" "mime"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"path"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"path"
"bytes"
"github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/glog"
"github.com/chrislusf/seaweedfs/go/images" "github.com/chrislusf/seaweedfs/go/images"
"github.com/chrislusf/seaweedfs/go/operation" "github.com/chrislusf/seaweedfs/go/operation"
@ -135,15 +133,10 @@ func (vs *VolumeServer) tryHandleChunkedFile(n *storage.Needle, fileName string,
if !n.IsChunkedManifest() { if !n.IsChunkedManifest() {
return false return false
} }
raw, _ := strconv.ParseBool(r.FormValue("raw"))
if raw {
return false
}
processed = true
chunkManifest, e := operation.LoadChunkManifest(n.Data, n.IsGzipped()) chunkManifest, e := operation.LoadChunkManifest(n.Data, n.IsGzipped())
if e != nil { if e != nil {
glog.V(0).Infof("load chunked manifest (%s) error: %s", r.URL.Path, e.Error()) glog.V(0).Infof("load chunked manifest (%s) error: %v", r.URL.Path, e)
return false return false
} }
if fileName == "" && chunkManifest.Name != "" { if fileName == "" && chunkManifest.Name != "" {
@ -167,7 +160,7 @@ func (vs *VolumeServer) tryHandleChunkedFile(n *storage.Needle, fileName string,
if e := writeResponseContent(fileName, mType, chunkedFileReader, w, r); e != nil { if e := writeResponseContent(fileName, mType, chunkedFileReader, w, r); e != nil {
glog.V(2).Infoln("response write error:", e) glog.V(2).Infoln("response write error:", e)
} }
return return true
} }
func writeResponseContent(filename, mimeType string, rs io.ReadSeeker, w http.ResponseWriter, r *http.Request) error { func writeResponseContent(filename, mimeType string, rs io.ReadSeeker, w http.ResponseWriter, r *http.Request) error {

View file

@ -2,6 +2,7 @@ package weed_server
import ( import (
"errors" "errors"
"fmt"
"net/http" "net/http"
"github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/glog"
@ -72,12 +73,12 @@ func (vs *VolumeServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {
if n.IsChunkedManifest() { if n.IsChunkedManifest() {
chunkManifest, e := operation.LoadChunkManifest(n.Data, n.IsGzipped()) chunkManifest, e := operation.LoadChunkManifest(n.Data, n.IsGzipped())
if e != nil { if e != nil {
writeJsonError(w, r, http.StatusInternalServerError, errors.New("Load chunks manifest error: "+e.Error())) writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("Load chunks manifest error: %v", e))
return return
} }
// make sure all chunks had deleted before delete manifest // make sure all chunks had deleted before delete manifest
if e := chunkManifest.DeleteChunks(vs.GetMasterNode()); e != nil { if e := chunkManifest.DeleteChunks(vs.GetMasterNode()); e != nil {
writeJsonError(w, r, http.StatusInternalServerError, errors.New("Delete chunks error: "+e.Error())) writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("Delete chunks error: %v", e))
return return
} }
count = chunkManifest.Size count = chunkManifest.Size
@ -123,11 +124,10 @@ func (vs *VolumeServer) batchDeleteHandler(w http.ResponseWriter, r *http.Reques
} }
if n.IsChunkedManifest() { if n.IsChunkedManifest() {
//Don't allow delete manifest in batch delete mode
ret = append(ret, operation.DeleteResult{ ret = append(ret, operation.DeleteResult{
Fid: fid, Fid: fid,
Status: http.StatusNotAcceptable, Status: http.StatusNotAcceptable,
Error: "ChunkManifest: not allow.", Error: "ChunkManifest: not allowed in batch delete mode.",
}) })
continue continue
} }