filer.conf: match inode_index scope on path boundaries

inodeIndexInScope used MatchStorageRule's raw prefix match, so a rule on /exports also indexed entries under /exports2 and /exports_old. MatchInodeIndexRule requires the rule location to end at a '/' boundary, and InodeIndexActiveUnder now uses the same check for its own-coverage branch.
This commit is contained in:
Chris Lu committed 2026-10-22 03:14:14 -07:00
1 parent d6b4290527
commit 8311221fb4
3 files changed
+34 -2

No files matched your search

+20 -1
View File
@@ -252,11 +252,30 @@ func ClonePathConf(src *filer_pb.FilerConf_PathConf) *filer_pb.FilerConf_PathCon
}
}
// MatchInodeIndexRule reports whether an inode_index rule covers path. Unlike
// MatchStorageRule it requires the rule's location to end at a path boundary,
// so a rule on /exports does not index /exports2 or /exports_old.
func (fc *FilerConf) MatchInodeIndexRule(path string) bool {
active := false
fc.rules.MatchPrefix([]byte(path), func(key []byte, value *filer_pb.FilerConf_PathConf) bool {
if !value.InodeIndex {
return true
}
rulePath := strings.TrimSuffix(string(key), "/")
if path == rulePath || strings.HasPrefix(path, rulePath+"/") {
active = true
return false
}
return true
})
return active
}
// InodeIndexActiveUnder reports whether entries inside dirPath may carry inode
// index rows: either dirPath itself is covered by an inode_index rule, or such
// a rule applies to a subtree inside dirPath.
func (fc *FilerConf) InodeIndexActiveUnder(dirPath string) bool {
if fc.MatchStorageRule(dirPath).InodeIndex {
if fc.MatchInodeIndexRule(dirPath) {
return true
}
prefix := dirPath
+1 -1
View File
@@ -164,7 +164,7 @@ func (fsw *FilerStoreWrapper) inodeIndexInScope(path util.FullPath) bool {
if fc == nil {
return false
}
return fc.MatchStorageRule(string(path)).InodeIndex
return fc.MatchInodeIndexRule(string(path))
}
// inodeIndexUnder reports whether any entry inside dirPath may carry an inode
+13
View File
@@ -301,3 +301,16 @@ func TestInodeIndexActiveUnder(t *testing.T) {
assert.False(t, NewFilerConf().InodeIndexActiveUnder("/"))
}
func TestMatchInodeIndexRule(t *testing.T) {
fc := inodeIndexConf("/exports")
assert.True(t, fc.MatchInodeIndexRule("/exports"))
assert.True(t, fc.MatchInodeIndexRule("/exports/sub/file"))
assert.False(t, fc.MatchInodeIndexRule("/exports2"))
assert.False(t, fc.MatchInodeIndexRule("/exports_old/x"))
assert.False(t, fc.MatchInodeIndexRule("/exp"))
assert.False(t, fc.MatchInodeIndexRule("/other"))
assert.True(t, inodeIndexConf("/").MatchInodeIndexRule("/anything"))
assert.False(t, NewFilerConf().MatchInodeIndexRule("/exports"))
}