SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
retry forever with filer.remote.sync, and some refactoring
Chris Lu49b5e47bd130
diff --git a/weed/command/filer_remote_sync.go b/weed/command/filer_remote_sync.goindex 8b20957e48..41b9c67e8a 100644--- a/weed/command/filer_remote_sync.go+++ b/weed/command/filer_remote_sync.go@@ -70,43 +70,33 @@ func runFilerRemoteSynchronize(cmd *Command, args []string) bool {grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")remoteSyncOptions.grpcDialOption = grpcDialOption+ dir := *remoteSyncOptions.dir+ filerAddress := *remoteSyncOptions.filerAddress+// read filer remote storage mount mappings- mappings, readErr := filer.ReadMountMappings(grpcDialOption, *remoteSyncOptions.filerAddress)- if readErr != nil {- fmt.Printf("read mount mapping: %v", readErr)+ _, _, remoteStorageMountLocation, storageConf, detectErr := filer.DetectMountInfo(grpcDialOption, filerAddress, dir)+ if detectErr != nil {+ fmt.Printf("read mount info: %v", detectErr)return false}filerSource := &source.FilerSource{}filerSource.DoInitialize(- *remoteSyncOptions.filerAddress,- pb.ServerToGrpcAddress(*remoteSyncOptions.filerAddress),+ filerAddress,+ pb.ServerToGrpcAddress(filerAddress),"/", // does not matter*remoteSyncOptions.readChunkFromFiler,)- var found bool- for dir, remoteStorageMountLocation := range mappings.Mappings {- if *remoteSyncOptions.dir == dir {- found = true- storageConf, readErr := filer.ReadRemoteStorageConf(grpcDialOption, *remoteSyncOptions.filerAddress, remoteStorageMountLocation.Name)- if readErr != nil {- fmt.Printf("read remote storage configuration for %s: %v", dir, readErr)- continue- }- fmt.Printf("synchronize %s to remote storage...\n", *remoteSyncOptions.dir)- if err := util.Retry("filer.remote.sync "+dir, func() error {- return followUpdatesAndUploadToRemote(&remoteSyncOptions, filerSource, dir, storageConf, remoteStorageMountLocation)- }); err != nil {- fmt.Printf("synchronize %s: %v\n", *remoteSyncOptions.dir, err)- }- break+ fmt.Printf("synchronize %s to remote storage...\n", dir)+ util.RetryForever("filer.remote.sync "+dir, func() error {+ return followUpdatesAndUploadToRemote(&remoteSyncOptions, filerSource, dir, storageConf, remoteStorageMountLocation)+ }, func(err error) bool {+ if err != nil {+ fmt.Printf("synchronize %s: %v\n", dir, err)}- }- if !found {- fmt.Printf("directory %s is not mounted to any remote storage\n", *remoteSyncOptions.dir)- return false- }+ return true+ })return true}diff --git a/weed/filer/filer_remote_storage.go b/weed/filer/filer_remote_storage.goindex 99ea1d3bb9..dd8d2303c2 100644--- a/weed/filer/filer_remote_storage.go+++ b/weed/filer/filer_remote_storage.go@@ -197,3 +197,33 @@ func ReadRemoteStorageConf(grpcDialOption grpc.DialOption, filerAddress string,return}++func DetectMountInfo(grpcDialOption grpc.DialOption, filerAddress string, dir string) (*filer_pb.RemoteStorageMapping, string, *filer_pb.RemoteStorageLocation, *filer_pb.RemoteConf, error) {++ mappings, listErr := ReadMountMappings(grpcDialOption, filerAddress)+ if listErr != nil {+ return nil, "", nil, nil, listErr+ }+ if dir == "" {+ return mappings, "", nil, nil, fmt.Errorf("need to specify '-dir' option")+ }++ var localMountedDir string+ var remoteStorageMountedLocation *filer_pb.RemoteStorageLocation+ for k, loc := range mappings.Mappings {+ if strings.HasPrefix(dir, k) {+ localMountedDir, remoteStorageMountedLocation = k, loc+ }+ }+ if localMountedDir == "" {+ return mappings, localMountedDir, remoteStorageMountedLocation, nil, fmt.Errorf("%s is not mounted", dir)+ }++ // find remote storage configuration+ remoteStorageConf, err := ReadRemoteStorageConf(grpcDialOption, filerAddress, remoteStorageMountedLocation.Name)+ if err != nil {+ return mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, err+ }++ return mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, nil+}diff --git a/weed/shell/command_remote_meta_sync.go b/weed/shell/command_remote_meta_sync.goindex d2b88ec161..08d08a46d7 100644--- a/weed/shell/command_remote_meta_sync.go+++ b/weed/shell/command_remote_meta_sync.go@@ -9,7 +9,6 @@ import ("github.com/chrislusf/seaweedfs/weed/remote_storage""github.com/chrislusf/seaweedfs/weed/util""io"- "strings")func init() {@@ -69,32 +68,7 @@ func (c *commandRemoteMetaSync) Do(args []string, commandEnv *CommandEnv, writer}func detectMountInfo(commandEnv *CommandEnv, writer io.Writer, dir string) (*filer_pb.RemoteStorageMapping, string, *filer_pb.RemoteStorageLocation, *filer_pb.RemoteConf, error) {- mappings, listErr := filer.ReadMountMappings(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress)- if listErr != nil {- return nil, "", nil, nil, listErr- }- if dir == "" {- return mappings, "", nil, nil, fmt.Errorf("need to specify '-dir' option")- }-- var localMountedDir string- var remoteStorageMountedLocation *filer_pb.RemoteStorageLocation- for k, loc := range mappings.Mappings {- if strings.HasPrefix(dir, k) {- localMountedDir, remoteStorageMountedLocation = k, loc- }- }- if localMountedDir == "" {- return mappings, localMountedDir, remoteStorageMountedLocation, nil, fmt.Errorf("%s is not mounted", dir)- }-- // find remote storage configuration- remoteStorageConf, err := filer.ReadRemoteStorageConf(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress, remoteStorageMountedLocation.Name)- if err != nil {- return mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, err- }-- return mappings, localMountedDir, remoteStorageMountedLocation, remoteStorageConf, nil+ return filer.DetectMountInfo(commandEnv.option.GrpcDialOption, commandEnv.option.FilerAddress, dir)}/*