refactoring
This commit is contained in:
@@ -3,7 +3,6 @@ package filersink
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@@ -69,7 +68,7 @@ func (fs *FilerSink) fetchAndWrite(sourceChunk *filer_pb.FileChunk, dir string)
|
|||||||
var host string
|
var host string
|
||||||
var auth security.EncodedJwt
|
var auth security.EncodedJwt
|
||||||
|
|
||||||
if err := fs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
if err := fs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
request := &filer_pb.AssignVolumeRequest{
|
request := &filer_pb.AssignVolumeRequest{
|
||||||
Count: 1,
|
Count: 1,
|
||||||
@@ -114,7 +113,7 @@ func (fs *FilerSink) fetchAndWrite(sourceChunk *filer_pb.FileChunk, dir string)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
||||||
@@ -122,11 +121,6 @@ func (fs *FilerSink) withFilerClient(fn func(filer_pb.SeaweedFilerClient) error)
|
|||||||
}, fs.grpcAddress, fs.grpcDialOption)
|
}, fs.grpcAddress, fs.grpcDialOption)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func (fs *FilerSink) AdjustedUrl(hostAndPort string) string {
|
||||||
func volumeId(fileId string) string {
|
return hostAndPort
|
||||||
lastCommaIndex := strings.LastIndex(fileId, ",")
|
|
||||||
if lastCommaIndex > 0 {
|
|
||||||
return fileId[:lastCommaIndex]
|
|
||||||
}
|
|
||||||
return fileId
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,30 +65,21 @@ func (fs *FilerSink) initialize(grpcAddress string, dir string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FilerSink) DeleteEntry(key string, isDirectory, deleteIncludeChunks bool) error {
|
func (fs *FilerSink) DeleteEntry(key string, isDirectory, deleteIncludeChunks bool) error {
|
||||||
return fs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
|
||||||
|
|
||||||
dir, name := util.FullPath(key).DirAndName()
|
dir, name := util.FullPath(key).DirAndName()
|
||||||
|
|
||||||
request := &filer_pb.DeleteEntryRequest{
|
glog.V(1).Infof("delete entry: %v", key)
|
||||||
Directory: dir,
|
err := filer_pb.Remove(fs, dir, name, deleteIncludeChunks, false, false)
|
||||||
Name: name,
|
if err != nil {
|
||||||
IsDeleteData: deleteIncludeChunks,
|
glog.V(0).Infof("delete entry %s: %v", key, err)
|
||||||
}
|
return fmt.Errorf("delete entry %s: %v", key, err)
|
||||||
|
}
|
||||||
glog.V(1).Infof("delete entry: %v", request)
|
return nil
|
||||||
_, err := client.DeleteEntry(context.Background(), request)
|
|
||||||
if err != nil {
|
|
||||||
glog.V(0).Infof("delete entry %s: %v", key, err)
|
|
||||||
return fmt.Errorf("delete entry %s: %v", key, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FilerSink) CreateEntry(key string, entry *filer_pb.Entry) error {
|
func (fs *FilerSink) CreateEntry(key string, entry *filer_pb.Entry) error {
|
||||||
|
|
||||||
return fs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
return fs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
dir, name := util.FullPath(key).DirAndName()
|
dir, name := util.FullPath(key).DirAndName()
|
||||||
|
|
||||||
@@ -140,7 +131,7 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry *filer_pb.Entry, newParent
|
|||||||
|
|
||||||
// read existing entry
|
// read existing entry
|
||||||
var existingEntry *filer_pb.Entry
|
var existingEntry *filer_pb.Entry
|
||||||
err = fs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
err = fs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
request := &filer_pb.LookupDirectoryEntryRequest{
|
request := &filer_pb.LookupDirectoryEntryRequest{
|
||||||
Directory: dir,
|
Directory: dir,
|
||||||
@@ -192,7 +183,7 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry *filer_pb.Entry, newParent
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save updated meta data
|
// save updated meta data
|
||||||
return true, fs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
return true, fs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
request := &filer_pb.UpdateEntryRequest{
|
request := &filer_pb.UpdateEntryRequest{
|
||||||
Directory: newParentPath,
|
Directory: newParentPath,
|
||||||
|
|||||||
Reference in New Issue
Block a user