Browse Source

feat(remote): add -noSync flag to skip upfront metadata pull on mount

Made-with: Cursor
pull/8568/head
Peter 19 hours ago
parent
commit
3f1a8279ae
  1. 19
      weed/shell/command_remote_mount.go
  2. 5
      weed/shell/command_remote_mount_buckets.go

19
weed/shell/command_remote_mount.go

@ -29,13 +29,15 @@ func (c *commandRemoteMount) Name() string {
} }
func (c *commandRemoteMount) Help() string { func (c *commandRemoteMount) Help() string {
return `mount remote storage and pull its metadata
return `mount remote storage and optionally pull its metadata
# assume a remote storage is configured to name "cloud1" # assume a remote storage is configured to name "cloud1"
remote.configure -name=cloud1 -type=s3 -s3.access_key=xxx -s3.secret_key=yyy remote.configure -name=cloud1 -type=s3 -s3.access_key=xxx -s3.secret_key=yyy
# mount and pull one bucket
# mount and pull one bucket (full upfront metadata sync)
remote.mount -dir=/xxx -remote=cloud1/bucket remote.mount -dir=/xxx -remote=cloud1/bucket
# mount without upfront sync; metadata is fetched lazily on access
remote.mount -dir=/xxx -remote=cloud1/bucket -noSync
# mount and pull one directory in the bucket # mount and pull one directory in the bucket
remote.mount -dir=/xxx -remote=cloud1/bucket/dir1 remote.mount -dir=/xxx -remote=cloud1/bucket/dir1
@ -55,6 +57,7 @@ func (c *commandRemoteMount) Do(args []string, commandEnv *CommandEnv, writer io
dir := remoteMountCommand.String("dir", "", "a directory in filer") dir := remoteMountCommand.String("dir", "", "a directory in filer")
nonEmpty := remoteMountCommand.Bool("nonempty", false, "allows the mounting over a non-empty directory") nonEmpty := remoteMountCommand.Bool("nonempty", false, "allows the mounting over a non-empty directory")
noSync := remoteMountCommand.Bool("noSync", false, "skip upfront metadata pull; rely on lazy metadata fetch on access")
remote := remoteMountCommand.String("remote", "", "a directory in remote storage, ex. <storageName>/<bucket>/path/to/dir") remote := remoteMountCommand.String("remote", "", "a directory in remote storage, ex. <storageName>/<bucket>/path/to/dir")
if err = remoteMountCommand.Parse(args); err != nil { if err = remoteMountCommand.Parse(args); err != nil {
@ -77,9 +80,8 @@ func (c *commandRemoteMount) Do(args []string, commandEnv *CommandEnv, writer io
return err return err
} }
// sync metadata from remote
if err = syncMetadata(commandEnv, writer, *dir, *nonEmpty, remoteConf, remoteStorageLocation); err != nil {
return fmt.Errorf("pull metadata: %w", err)
if err = syncMetadata(commandEnv, writer, *dir, *nonEmpty, *noSync, remoteConf, remoteStorageLocation); err != nil {
return fmt.Errorf("mount setup: %w", err)
} }
// store a mount configuration in filer // store a mount configuration in filer
@ -108,7 +110,7 @@ func jsonPrintln(writer io.Writer, message proto.Message) error {
return filer.ProtoToText(writer, message) return filer.ProtoToText(writer, message)
} }
func syncMetadata(commandEnv *CommandEnv, writer io.Writer, dir string, nonEmpty bool, remoteConf *remote_pb.RemoteConf, remote *remote_pb.RemoteStorageLocation) error {
func syncMetadata(commandEnv *CommandEnv, writer io.Writer, dir string, nonEmpty bool, noSync bool, remoteConf *remote_pb.RemoteConf, remote *remote_pb.RemoteStorageLocation) error {
// find existing directory, and ensure the directory is empty // find existing directory, and ensure the directory is empty
err := commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error { err := commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
@ -160,7 +162,10 @@ func syncMetadata(commandEnv *CommandEnv, writer io.Writer, dir string, nonEmpty
return err return err
} }
// pull metadata from remote
if noSync {
return nil
}
if err = pullMetadata(commandEnv, writer, util.FullPath(dir), remote, util.FullPath(dir), remoteConf); err != nil { if err = pullMetadata(commandEnv, writer, util.FullPath(dir), remote, util.FullPath(dir), remoteConf); err != nil {
return fmt.Errorf("cache metadata: %w", err) return fmt.Errorf("cache metadata: %w", err)
} }

5
weed/shell/command_remote_mount_buckets.go

@ -109,9 +109,8 @@ func (c *commandRemoteMountBuckets) Do(args []string, commandEnv *CommandEnv, wr
Path: "/", Path: "/",
} }
// sync metadata from remote
if err = syncMetadata(commandEnv, writer, string(dir), true, remoteConf, remoteStorageLocation); err != nil {
return fmt.Errorf("pull metadata on %+v: %v", remoteStorageLocation, err)
if err = syncMetadata(commandEnv, writer, string(dir), true, false, remoteConf, remoteStorageLocation); err != nil {
return fmt.Errorf("mount setup on %+v: %v", remoteStorageLocation, err)
} }
// store a mount configuration in filer // store a mount configuration in filer

Loading…
Cancel
Save