|
|
@ -40,10 +40,6 @@ type WFS struct { |
|
|
|
pathToHandleIndex map[string]int |
|
|
|
pathToHandleLock sync.Mutex |
|
|
|
|
|
|
|
// cache grpc connections
|
|
|
|
grpcClients map[string]*grpc.ClientConn |
|
|
|
grpcClientsLock sync.Mutex |
|
|
|
|
|
|
|
stats statsCache |
|
|
|
} |
|
|
|
type statsCache struct { |
|
|
@ -56,7 +52,6 @@ func NewSeaweedFileSystem(option *Option) *WFS { |
|
|
|
option: option, |
|
|
|
listDirectoryEntriesCache: ccache.New(ccache.Configure().MaxSize(int64(option.DirListingLimit) + 200).ItemsToPrune(100)), |
|
|
|
pathToHandleIndex: make(map[string]int), |
|
|
|
grpcClients: make(map[string]*grpc.ClientConn), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -66,27 +61,11 @@ func (wfs *WFS) Root() (fs.Node, error) { |
|
|
|
|
|
|
|
func (wfs *WFS) withFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error { |
|
|
|
|
|
|
|
wfs.grpcClientsLock.Lock() |
|
|
|
|
|
|
|
existingConnection, found := wfs.grpcClients[wfs.option.FilerGrpcAddress] |
|
|
|
if found { |
|
|
|
wfs.grpcClientsLock.Unlock() |
|
|
|
client := filer_pb.NewSeaweedFilerClient(existingConnection) |
|
|
|
return util.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error { |
|
|
|
client := filer_pb.NewSeaweedFilerClient(grpcConnection) |
|
|
|
return fn(client) |
|
|
|
} |
|
|
|
|
|
|
|
grpcConnection, err := util.GrpcDial(wfs.option.FilerGrpcAddress) |
|
|
|
if err != nil { |
|
|
|
wfs.grpcClientsLock.Unlock() |
|
|
|
return fmt.Errorf("fail to dial %s: %v", wfs.option.FilerGrpcAddress, err) |
|
|
|
} |
|
|
|
|
|
|
|
wfs.grpcClients[wfs.option.FilerGrpcAddress] = grpcConnection |
|
|
|
wfs.grpcClientsLock.Unlock() |
|
|
|
|
|
|
|
client := filer_pb.NewSeaweedFilerClient(grpcConnection) |
|
|
|
}, wfs.option.FilerGrpcAddress) |
|
|
|
|
|
|
|
return fn(client) |
|
|
|
} |
|
|
|
|
|
|
|
func (wfs *WFS) AcquireHandle(file *File, uid, gid uint32) (fileHandle *FileHandle) { |
|
|
|