diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2018-07-28 21:03:29 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-28 21:03:29 -0700 |
| commit | 452bd0b01393e53e958fb9825bf1f27e6b3522df (patch) | |
| tree | e1a61e592118f9696b7f51501d3b3fd0f6c3eeb5 /weed/filer2/filer.go | |
| parent | 97603d6e176dd2b9f2aebd9f6122a8c60481463a (diff) | |
| parent | d3205a007071f26587affb416f71b5c63854b863 (diff) | |
| download | seaweedfs-452bd0b01393e53e958fb9825bf1f27e6b3522df.tar.xz seaweedfs-452bd0b01393e53e958fb9825bf1f27e6b3522df.zip | |
Merge pull request #702 from chrislusf/add_topo_listener
Add volume id location change listener
Diffstat (limited to 'weed/filer2/filer.go')
| -rw-r--r-- | weed/filer2/filer.go | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/weed/filer2/filer.go b/weed/filer2/filer.go index 2deb8ffd5..1f2697cda 100644 --- a/weed/filer2/filer.go +++ b/weed/filer2/filer.go @@ -1,30 +1,30 @@ package filer2 import ( + "context" "fmt" + "os" + "path/filepath" + "strings" + "time" "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/wdclient" "github.com/karlseguin/ccache" - "os" - "path/filepath" - "strings" - "time" ) type Filer struct { - masters []string store FilerStore directoryCache *ccache.Cache - - currentMaster string + MasterClient *wdclient.MasterClient } func NewFiler(masters []string) *Filer { return &Filer{ - masters: masters, directoryCache: ccache.New(ccache.Configure().MaxSize(1000).ItemsToPrune(100)), + MasterClient: wdclient.NewMasterClient(context.Background(), "filer", masters), } } @@ -36,6 +36,14 @@ func (f *Filer) DisableDirectoryCache() { f.directoryCache = nil } +func (fs *Filer) GetMaster() string { + return fs.MasterClient.GetMaster() +} + +func (fs *Filer) KeepConnectedToMaster() { + fs.MasterClient.KeepConnectedToMaster() +} + func (f *Filer) CreateEntry(entry *Entry) error { dirParts := strings.Split(string(entry.FullPath), "/") @@ -198,9 +206,17 @@ func (f *Filer) cacheSetDirectory(dirpath string, dirEntry *Entry, level int) { func (f *Filer) deleteChunks(chunks []*filer_pb.FileChunk) { for _, chunk := range chunks { - if err := operation.DeleteFile(f.GetMaster(), chunk.FileId, ""); err != nil { - glog.V(0).Infof("deleting file %s: %v", chunk.FileId, err) - } + f.DeleteFileByFileId(chunk.FileId) + } +} + +func (f *Filer) DeleteFileByFileId(fileId string) { + fileUrlOnVolume, err := f.MasterClient.LookupFileId(fileId) + if err != nil { + glog.V(0).Infof("can not find file %s: %v", fileId, err) + } + if err := operation.DeleteFromVolumeServer(fileUrlOnVolume, ""); err != nil { + glog.V(0).Infof("deleting file %s: %v", fileId, err) } } |
