Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: use HEAD instead of LIST for single object #4623

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,29 @@ func listCommonPrefix(store object.ObjectStorage, prefix string, cp chan object.
}

func startProducer(tasks chan<- object.Object, src, dst object.ObjectStorage, prefix string, config *Config) error {
if prefix == "" && config.Limit == 1 && len(config.rules) == 0 {
// fast path for single key
obj, err := src.Head(config.Start)
if err == nil && (!obj.IsDir() || config.Dirs) {
var srckeys = make(chan object.Object, 1)
srckeys <- obj
close(srckeys)
var dstkeys = make(chan object.Object, 1)
if dobj, err := dst.Head(config.Start); err == nil || os.IsNotExist(err) {
if dobj != nil {
dstkeys <- dobj
}
close(dstkeys)
logger.Debugf("produce single key %s", config.Start)
produce(tasks, srckeys, dstkeys, config)
return nil
} else {
logger.Warnf("head %s from %s: %s", config.Start, dst, err)
}
} else if err != nil && !os.IsNotExist(err) {
logger.Warnf("head %s from %s: %s", config.Start, src, err)
}
}
if config.ListThreads <= 1 || strings.Count(prefix, "/") >= config.ListDepth {
return startSingleProducer(tasks, src, dst, prefix, config)
}
Expand Down
Loading