mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-20 07:47:58 +08:00
refactoring
This commit is contained in:
@@ -117,6 +117,8 @@ func (wfs *WFS) Root() (fs.Node, error) {
|
|||||||
return wfs.root, nil
|
return wfs.root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ = filer_pb.FilerClient(&WFS{})
|
||||||
|
|
||||||
func (wfs *WFS) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
func (wfs *WFS) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||||
|
|
||||||
err := pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
err := pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
||||||
|
@@ -98,6 +98,8 @@ func (broker *MessageBroker) assignAndUpload(topicConfig *messaging_pb.TopicConf
|
|||||||
return assignResult, uploadResult, nil
|
return assignResult, uploadResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ = filer_pb.FilerClient(&MessageBroker{})
|
||||||
|
|
||||||
func (broker *MessageBroker) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) (err error) {
|
func (broker *MessageBroker) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) (err error) {
|
||||||
|
|
||||||
for _, filer := range broker.option.Filers {
|
for _, filer := range broker.option.Filers {
|
||||||
@@ -111,3 +113,7 @@ func (broker *MessageBroker) WithFilerClient(fn func(filer_pb.SeaweedFilerClient
|
|||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (broker *MessageBroker) AdjustedUrl(hostAndPort string) string {
|
||||||
|
return hostAndPort
|
||||||
|
}
|
||||||
|
@@ -85,7 +85,7 @@ func (s *Subscriber) doSubscribe(partition int, processFn func(m *messaging_pb.M
|
|||||||
|
|
||||||
// Subscribe starts goroutines to process the messages
|
// Subscribe starts goroutines to process the messages
|
||||||
func (s *Subscriber) Subscribe(processFn func(m *messaging_pb.Message)) {
|
func (s *Subscriber) Subscribe(processFn func(m *messaging_pb.Message)) {
|
||||||
for i:=0;i<len(s.subscriberClients);i++{
|
for i := 0; i < len(s.subscriberClients); i++ {
|
||||||
go s.doSubscribe(i, processFn)
|
go s.doSubscribe(i, processFn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -113,6 +113,8 @@ func (fs *FilerSink) fetchAndWrite(sourceChunk *filer_pb.FileChunk, dir string)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ = filer_pb.FilerClient(&FilerSink{})
|
||||||
|
|
||||||
func (fs *FilerSink) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
func (fs *FilerSink) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||||
|
|
||||||
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
||||||
|
@@ -47,7 +47,7 @@ func (fs *FilerSource) LookupFileId(part string) (fileUrl string, err error) {
|
|||||||
|
|
||||||
vid := volumeId(part)
|
vid := volumeId(part)
|
||||||
|
|
||||||
err = fs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
err = fs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
glog.V(4).Infof("read lookup volume id locations: %v", vid)
|
glog.V(4).Infof("read lookup volume id locations: %v", vid)
|
||||||
resp, err := client.LookupVolume(context.Background(), &filer_pb.LookupVolumeRequest{
|
resp, err := client.LookupVolume(context.Background(), &filer_pb.LookupVolumeRequest{
|
||||||
@@ -91,7 +91,9 @@ func (fs *FilerSource) ReadPart(part string) (filename string, header http.Heade
|
|||||||
return filename, header, readCloser, err
|
return filename, header, readCloser, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FilerSource) withFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
var _ = filer_pb.FilerClient(&FilerSource{})
|
||||||
|
|
||||||
|
func (fs *FilerSource) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||||
|
|
||||||
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
||||||
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
||||||
@@ -100,6 +102,10 @@ func (fs *FilerSource) withFilerClient(fn func(filer_pb.SeaweedFilerClient) erro
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fs *FilerSource) AdjustedUrl(hostAndPort string) string {
|
||||||
|
return hostAndPort
|
||||||
|
}
|
||||||
|
|
||||||
func volumeId(fileId string) string {
|
func volumeId(fileId string) string {
|
||||||
lastCommaIndex := strings.LastIndex(fileId, ",")
|
lastCommaIndex := strings.LastIndex(fileId, ",")
|
||||||
if lastCommaIndex > 0 {
|
if lastCommaIndex > 0 {
|
||||||
|
@@ -38,6 +38,8 @@ func encodeResponse(response interface{}) []byte {
|
|||||||
return bytesBuffer.Bytes()
|
return bytesBuffer.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ = filer_pb.FilerClient(&S3ApiServer{})
|
||||||
|
|
||||||
func (s3a *S3ApiServer) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
func (s3a *S3ApiServer) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||||
|
|
||||||
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
||||||
|
@@ -110,6 +110,8 @@ func NewWebDavFileSystem(option *WebDavOption) (webdav.FileSystem, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ = filer_pb.FilerClient(&WebDavFileSystem{})
|
||||||
|
|
||||||
func (fs *WebDavFileSystem) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
func (fs *WebDavFileSystem) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||||
|
|
||||||
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
||||||
|
@@ -52,4 +52,3 @@ func (c *commandUnlock) Do(args []string, commandEnv *CommandEnv, writer io.Writ
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -92,6 +92,8 @@ func (ce *CommandEnv) checkDirectory(path string) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ = filer_pb.FilerClient(&CommandEnv{})
|
||||||
|
|
||||||
func (ce *CommandEnv) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
func (ce *CommandEnv) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
||||||
|
|
||||||
filerGrpcAddress := fmt.Sprintf("%s:%d", ce.option.FilerHost, ce.option.FilerPort+10000)
|
filerGrpcAddress := fmt.Sprintf("%s:%d", ce.option.FilerHost, ce.option.FilerPort+10000)
|
||||||
|
Reference in New Issue
Block a user