Skip to content

Commit

Permalink
global rebalance/limited scope: skipping virtual directories
Browse files Browse the repository at this point in the history
* fix and comment; minor cleanup
* part four, prev. commit: 84cc79c

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Dec 6, 2024
1 parent 84cc79c commit d4a36ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions cmn/objlist_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,14 @@ func TokenGreaterEQ(token, objName string) bool { return token >= objName }
// an alternative name for this function could be smth. like SameBranch()
// see also: cos.TrimPrefix
func DirHasOrIsPrefix(dirPath, prefix string) bool {
return prefix == "" || (strings.HasPrefix(prefix, dirPath) || strings.HasPrefix(dirPath, prefix))
debug.Assert(prefix != "")
return strings.HasPrefix(prefix, dirPath) || strings.HasPrefix(dirPath, prefix)
}

// see also: cos.TrimPrefix
func ObjHasPrefix(objName, prefix string) bool {
return prefix == "" || strings.HasPrefix(objName, prefix)
debug.Assert(prefix != "")
return strings.HasPrefix(objName, prefix)
}

// no recursion (LsNoRecursion) helper function:
Expand Down
11 changes: 9 additions & 2 deletions reb/globrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"net/http"
"path/filepath"
"strings"
"sync"
ratomic "sync/atomic"
"time"
Expand Down Expand Up @@ -834,8 +835,14 @@ func (rj *rebJogger) _lwalk(lom *core.LOM, fqn string) error {
if rj.rargs.prefix != "" {
debug.Assert(rj.rargs.bck != nil)
if !cmn.ObjHasPrefix(lom.ObjName, rj.rargs.prefix) {
if len(lom.ObjName) > len(rj.rargs.prefix)+1 {
nlog.Warningln(rj.rargs.logHdr, "skip-dir", lom.ObjName)
//
// TODO: unify via (fs.WalkBck => validateCb => cmn.DirHasOrIsPrefix)
//
i := strings.IndexByte(lom.ObjName, filepath.Separator)
if i > 0 && !cmn.DirHasOrIsPrefix(lom.ObjName[:i], rj.rargs.prefix) {
if cmn.Rom.FastV(4, cos.SmoduleReb) {
nlog.Warningln(rj.rargs.logHdr, "skip-dir", lom.ObjName, "prefix", rj.rargs.prefix)
}
return filepath.SkipDir
}
return cmn.ErrSkip
Expand Down
4 changes: 2 additions & 2 deletions xact/xs/wi_lso.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (wi *walkInfo) processDir(fqn string) error {
return nil
}

if !cmn.DirHasOrIsPrefix(ct.ObjectName(), wi.msg.Prefix) {
if wi.msg.Prefix != "" && !cmn.DirHasOrIsPrefix(ct.ObjectName(), wi.msg.Prefix) {
return filepath.SkipDir
}

Expand All @@ -81,7 +81,7 @@ func (wi *walkInfo) processDir(fqn string) error {
}

func (wi *walkInfo) match(objName string) bool {
if !cmn.ObjHasPrefix(objName, wi.msg.Prefix) {
if wi.msg.Prefix != "" && !cmn.ObjHasPrefix(objName, wi.msg.Prefix) {
return false
}
return wi.msg.ContinuationToken == "" || !cmn.TokenGreaterEQ(wi.msg.ContinuationToken, objName)
Expand Down

0 comments on commit d4a36ef

Please sign in to comment.