Merge pull request #1076 from iliul/fix-lookup-statuscode

master api: return http 404 when volumeId not exist
This commit is contained in:
Chris Lu 2019-09-28 23:34:05 -07:00 committed by GitHub
commit 1bb4449e5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 69 deletions

View File

@ -36,7 +36,7 @@ func main() {
var dbs []*leveldb.DB
var chans []chan string
for d := 0 ; d < *dbCount; d++ {
for d := 0; d < *dbCount; d++ {
dbFolder := fmt.Sprintf("%s/%02d", *dir, d)
os.MkdirAll(dbFolder, 0755)
db, err := leveldb.OpenFile(dbFolder, opts)
@ -49,9 +49,9 @@ func main() {
}
var wg sync.WaitGroup
for d := 0 ; d < *dbCount; d++ {
for d := 0; d < *dbCount; d++ {
wg.Add(1)
go func(d int){
go func(d int) {
defer wg.Done()
ch := chans[d]
@ -60,14 +60,13 @@ func main() {
for p := range ch {
if *useHash {
insertAsHash(db, p)
}else{
} else {
insertAsFullPath(db, p)
}
}
}(d)
}
counter := int64(0)
lastResetTime := time.Now()
@ -101,7 +100,7 @@ func main() {
}
}
for d := 0 ; d < *dbCount; d++ {
for d := 0; d < *dbCount; d++ {
close(chans[d])
}

View File

@ -2,14 +2,13 @@ package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/storage"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
"os"
"path/filepath"
"fmt"
)
var (
@ -18,7 +17,7 @@ var (
volumeId = flag.Int("volumeId", -1, "a volume id. The volume should already exist in the dir. The volume index file should not exist.")
)
func Checksum(n* needle.Needle) string {
func Checksum(n *needle.Needle) string {
return fmt.Sprintf("%s%x", n.Id, n.Cookie)
}
@ -28,7 +27,7 @@ type VolumeFileScanner4SeeDat struct {
dir string
hashes map[string]bool
dat * os.File
dat *os.File
}
func (scanner *VolumeFileScanner4SeeDat) VisitSuperBlock(superBlock storage.SuperBlock) error {

View File

@ -2,12 +2,11 @@ package main
import (
"flag"
"time"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/storage"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
"time"
)
var (
@ -45,5 +44,4 @@ func main() {
if err != nil {
glog.Fatalf("Reading Volume File [ERROR] %s\n", err)
}
}

View File

@ -275,7 +275,7 @@ func (fs *FilerServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {
isRecursive := r.FormValue("recursive") == "true"
ignoreRecursiveError := r.FormValue("ignoreRecursiveError") == "true"
err := fs.filer.DeleteEntryMetaAndData(context.Background(), filer2.FullPath(r.URL.Path), isRecursive, ignoreRecursiveError,true)
err := fs.filer.DeleteEntryMetaAndData(context.Background(), filer2.FullPath(r.URL.Path), isRecursive, ignoreRecursiveError, true)
if err != nil {
glog.V(1).Infoln("deleting", r.URL.Path, ":", err.Error())
writeJsonError(w, r, http.StatusInternalServerError, err)

View File

@ -48,7 +48,7 @@ func (ms *MasterServer) dirLookupHandler(w http.ResponseWriter, r *http.Request)
collection := r.FormValue("collection") //optional, but can be faster if too many collections
location := ms.findVolumeLocation(collection, vid)
httpStatus := http.StatusOK
if location.Error != "" {
if location.Error != "" || location.Locations == nil {
httpStatus = http.StatusNotFound
} else {
forRead := r.FormValue("read")
@ -60,7 +60,7 @@ func (ms *MasterServer) dirLookupHandler(w http.ResponseWriter, r *http.Request)
// findVolumeLocation finds the volume location from master topo if it is leader,
// or from master client if not leader
func (ms *MasterServer) findVolumeLocation(collection string, vid string) operation.LookupResult {
func (ms *MasterServer) findVolumeLocation(collection, vid string) operation.LookupResult {
var locations []operation.Location
var err error
if ms.Topo.IsLeader() {

View File

@ -98,7 +98,7 @@ func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo) statistics {
}
func writeVolumeInformationMessage(writer io.Writer, t *master_pb.VolumeInformationMessage) statistics {
fmt.Fprintf(writer, " volume %+v \n", t)
return newStatiscis(t)
return newStatistics(t)
}
type statistics struct {
@ -108,7 +108,7 @@ type statistics struct {
DeletedBytes uint64
}
func newStatiscis(t *master_pb.VolumeInformationMessage) statistics {
func newStatistics(t *master_pb.VolumeInformationMessage) statistics {
return statistics{
Size: t.Size,
FileCount: t.FileCount,