Browse Source

adding context

pull/895/head
Chris Lu 6 years ago
parent
commit
55c85f3a66
  1. 4
      weed/filer2/filer.go
  2. 3
      weed/filer2/memdb/memdb_store_test.go
  3. 2
      weed/server/filer_grpc_server.go
  4. 3
      weed/server/filer_server_handlers_write.go

4
weed/filer2/filer.go

@ -187,7 +187,7 @@ func (f *Filer) FindEntry(p FullPath) (entry *Entry, err error) {
return f.store.FindEntry(p) return f.store.FindEntry(p)
} }
func (f *Filer) DeleteEntryMetaAndData(p FullPath, isRecursive bool, shouldDeleteChunks bool) (err error) {
func (f *Filer) DeleteEntryMetaAndData(ctx context.Context, p FullPath, isRecursive bool, shouldDeleteChunks bool) (err error) {
entry, err := f.FindEntry(p) entry, err := f.FindEntry(p)
if err != nil { if err != nil {
return err return err
@ -211,7 +211,7 @@ func (f *Filer) DeleteEntryMetaAndData(p FullPath, isRecursive bool, shouldDelet
if isRecursive { if isRecursive {
for _, sub := range entries { for _, sub := range entries {
lastFileName = sub.Name() lastFileName = sub.Name()
f.DeleteEntryMetaAndData(sub.FullPath, isRecursive, shouldDeleteChunks)
f.DeleteEntryMetaAndData(ctx, sub.FullPath, isRecursive, shouldDeleteChunks)
limit-- limit--
if limit <= 0 { if limit <= 0 {
break break

3
weed/filer2/memdb/memdb_store_test.go

@ -1,6 +1,7 @@
package memdb package memdb
import ( import (
"context"
"github.com/chrislusf/seaweedfs/weed/filer2" "github.com/chrislusf/seaweedfs/weed/filer2"
"testing" "testing"
) )
@ -134,7 +135,7 @@ func TestCreateFileAndList(t *testing.T) {
} }
// delete file and count // delete file and count
filer.DeleteEntryMetaAndData(file3Path, false, false)
filer.DeleteEntryMetaAndData(context.Background(), file3Path, false, false)
entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"), "", false, 100) entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"), "", false, 100)
if len(entries) != 1 { if len(entries) != 1 {
t.Errorf("list entries count: %v", len(entries)) t.Errorf("list entries count: %v", len(entries))

2
weed/server/filer_grpc_server.go

@ -186,7 +186,7 @@ func (fs *FilerServer) UpdateEntry(ctx context.Context, req *filer_pb.UpdateEntr
} }
func (fs *FilerServer) DeleteEntry(ctx context.Context, req *filer_pb.DeleteEntryRequest) (resp *filer_pb.DeleteEntryResponse, err error) { func (fs *FilerServer) DeleteEntry(ctx context.Context, req *filer_pb.DeleteEntryRequest) (resp *filer_pb.DeleteEntryResponse, err error) {
err = fs.filer.DeleteEntryMetaAndData(filer2.FullPath(filepath.ToSlash(filepath.Join(req.Directory, req.Name))), req.IsRecursive, req.IsDeleteData)
err = fs.filer.DeleteEntryMetaAndData(ctx, filer2.FullPath(filepath.ToSlash(filepath.Join(req.Directory, req.Name))), req.IsRecursive, req.IsDeleteData)
return &filer_pb.DeleteEntryResponse{}, err return &filer_pb.DeleteEntryResponse{}, err
} }

3
weed/server/filer_server_handlers_write.go

@ -1,6 +1,7 @@
package weed_server package weed_server
import ( import (
"context"
"encoding/json" "encoding/json"
"errors" "errors"
"io/ioutil" "io/ioutil"
@ -218,7 +219,7 @@ func (fs *FilerServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {
isRecursive := r.FormValue("recursive") == "true" isRecursive := r.FormValue("recursive") == "true"
err := fs.filer.DeleteEntryMetaAndData(filer2.FullPath(r.URL.Path), isRecursive, true)
err := fs.filer.DeleteEntryMetaAndData(context.Background(), filer2.FullPath(r.URL.Path), isRecursive, true)
if err != nil { if err != nil {
glog.V(1).Infoln("deleting", r.URL.Path, ":", err.Error()) glog.V(1).Infoln("deleting", r.URL.Path, ":", err.Error())
writeJsonError(w, r, http.StatusInternalServerError, err) writeJsonError(w, r, http.StatusInternalServerError, err)

Loading…
Cancel
Save