Chris Lu
3 years ago
11 changed files with 174 additions and 313 deletions
-
35unmaintained/load_test/load_test_meta_tail/load_test_meta_tail.go
-
51weed/command/filer_backup.go
-
48weed/command/filer_meta_backup.go
-
36weed/command/filer_meta_tail.go
-
49weed/command/filer_sync.go
-
39weed/filer/filer_remote_storage.go
-
41weed/filesys/meta_cache/meta_cache_subscribe.go
-
94weed/pb/filer_pb_tail.go
-
46weed/remote_storage/mount_mapping.go
-
41weed/s3api/auth_credentials_subscribe.go
-
5weed/shell/command_remote_mount.go
@ -0,0 +1,94 @@ |
|||||
|
package pb |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"github.com/chrislusf/seaweedfs/weed/glog" |
||||
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" |
||||
|
"google.golang.org/grpc" |
||||
|
"io" |
||||
|
"time" |
||||
|
) |
||||
|
|
||||
|
type ProcessMetadataFunc func(resp *filer_pb.SubscribeMetadataResponse) error |
||||
|
|
||||
|
func FollowMetadata(filerAddress string, grpcDialOption grpc.DialOption, |
||||
|
clientName string, pathPrefix string, lastTsNs int64, selfSignature int32, |
||||
|
processEventFn ProcessMetadataFunc, fatalOnError bool) error { |
||||
|
|
||||
|
err := WithFilerClient(filerAddress, grpcDialOption, makeFunc( |
||||
|
clientName, pathPrefix, lastTsNs, selfSignature, processEventFn, fatalOnError)) |
||||
|
if err != nil { |
||||
|
return fmt.Errorf("subscribing filer meta change: %v", err) |
||||
|
} |
||||
|
return err |
||||
|
} |
||||
|
|
||||
|
func WithFilerClientFollowMetadata(filerClient filer_pb.FilerClient, |
||||
|
clientName string, pathPrefix string, lastTsNs int64, selfSignature int32, |
||||
|
processEventFn ProcessMetadataFunc, fatalOnError bool) error { |
||||
|
|
||||
|
err := filerClient.WithFilerClient(makeFunc( |
||||
|
clientName, pathPrefix, lastTsNs, selfSignature, processEventFn, fatalOnError)) |
||||
|
if err != nil { |
||||
|
return fmt.Errorf("subscribing filer meta change: %v", err) |
||||
|
} |
||||
|
|
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
func makeFunc(clientName string, pathPrefix string, lastTsNs int64, selfSignature int32, |
||||
|
processEventFn ProcessMetadataFunc, fatalOnError bool) func(client filer_pb.SeaweedFilerClient) error { |
||||
|
return func(client filer_pb.SeaweedFilerClient) error { |
||||
|
ctx, cancel := context.WithCancel(context.Background()) |
||||
|
defer cancel() |
||||
|
stream, err := client.SubscribeMetadata(ctx, &filer_pb.SubscribeMetadataRequest{ |
||||
|
ClientName: clientName, |
||||
|
PathPrefix: pathPrefix, |
||||
|
SinceNs: lastTsNs, |
||||
|
Signature: selfSignature, |
||||
|
}) |
||||
|
if err != nil { |
||||
|
return fmt.Errorf("subscribe: %v", err) |
||||
|
} |
||||
|
|
||||
|
for { |
||||
|
resp, listenErr := stream.Recv() |
||||
|
if listenErr == io.EOF { |
||||
|
return nil |
||||
|
} |
||||
|
if listenErr != nil { |
||||
|
return listenErr |
||||
|
} |
||||
|
|
||||
|
if err := processEventFn(resp); err != nil { |
||||
|
if fatalOnError { |
||||
|
glog.Fatalf("process %v: %v", resp, err) |
||||
|
} else { |
||||
|
glog.Errorf("process %v: %v", resp, err) |
||||
|
} |
||||
|
} |
||||
|
lastTsNs = resp.TsNs |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func AddOffsetFunc(processEventFn ProcessMetadataFunc, offsetInterval time.Duration, offsetFunc func(counter int64, offset int64) error) ProcessMetadataFunc { |
||||
|
var counter int64 |
||||
|
var lastWriteTime time.Time |
||||
|
return func(resp *filer_pb.SubscribeMetadataResponse) error { |
||||
|
if err := processEventFn(resp); err != nil { |
||||
|
return err |
||||
|
} |
||||
|
counter++ |
||||
|
if lastWriteTime.Add(offsetInterval).Before(time.Now()) { |
||||
|
counter = 0 |
||||
|
lastWriteTime = time.Now() |
||||
|
if err := offsetFunc(counter, resp.TsNs); err != nil { |
||||
|
return err |
||||
|
} |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
} |
@ -1,46 +0,0 @@ |
|||||
package remote_storage |
|
||||
|
|
||||
import ( |
|
||||
"fmt" |
|
||||
"github.com/chrislusf/seaweedfs/weed/filer" |
|
||||
"github.com/chrislusf/seaweedfs/weed/pb" |
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" |
|
||||
"github.com/golang/protobuf/proto" |
|
||||
"google.golang.org/grpc" |
|
||||
) |
|
||||
|
|
||||
func ReadMountMappings(grpcDialOption grpc.DialOption, filerAddress string) (mappings *filer_pb.RemoteStorageMapping, readErr error) { |
|
||||
var oldContent []byte |
|
||||
if readErr = pb.WithFilerClient(filerAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { |
|
||||
oldContent, readErr = filer.ReadInsideFiler(client, filer.DirectoryEtcRemote, filer.REMOTE_STORAGE_MOUNT_FILE) |
|
||||
return readErr |
|
||||
}); readErr != nil { |
|
||||
return nil, readErr |
|
||||
} |
|
||||
|
|
||||
mappings, readErr = filer.UnmarshalRemoteStorageMappings(oldContent) |
|
||||
if readErr != nil { |
|
||||
return nil, fmt.Errorf("unmarshal mappings: %v", readErr) |
|
||||
} |
|
||||
|
|
||||
return |
|
||||
} |
|
||||
|
|
||||
func ReadRemoteStorageConf(grpcDialOption grpc.DialOption, filerAddress string, storageName string) (conf *filer_pb.RemoteConf, readErr error) { |
|
||||
var oldContent []byte |
|
||||
if readErr = pb.WithFilerClient(filerAddress, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { |
|
||||
oldContent, readErr = filer.ReadInsideFiler(client, filer.DirectoryEtcRemote, storageName+filer.REMOTE_STORAGE_CONF_SUFFIX) |
|
||||
return readErr |
|
||||
}); readErr != nil { |
|
||||
return nil, readErr |
|
||||
} |
|
||||
|
|
||||
// unmarshal storage configuration
|
|
||||
conf = &filer_pb.RemoteConf{} |
|
||||
if unMarshalErr := proto.Unmarshal(oldContent, conf); unMarshalErr != nil { |
|
||||
readErr = fmt.Errorf("unmarshal %s/%s: %v", filer.DirectoryEtcRemote, storageName+filer.REMOTE_STORAGE_CONF_SUFFIX, unMarshalErr) |
|
||||
return |
|
||||
} |
|
||||
|
|
||||
return |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue