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

Public backend detection #3732

Merged
merged 3 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions changelog/unreleased/add-backend-detection-method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Make method for detecting the metadata backend public

We made a private method for detecting the decomposedfs metadata backend public

https://github.com/cs3org/reva/pull/3732
21 changes: 21 additions & 0 deletions pkg/storage/utils/decomposedfs/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,24 @@ func (lu *Lookup) CopyMetadataWithSourceLock(sourcePath, targetPath string, filt

return lu.MetadataBackend().SetMultiple(targetPath, newAttrs, true)
}

// DetectBackendOnDisk returns the name of the metadata backend being used on disk
func DetectBackendOnDisk(root string) string {
matches, _ := filepath.Glob(filepath.Join(root, "spaces", "*", "*"))
if len(matches) > 0 {
base := matches[len(matches)-1]
spaceid := strings.ReplaceAll(
strings.TrimPrefix(base, filepath.Join(root, "spaces")),
"/", "")
spaceRoot := Pathify(spaceid, 4, 2)
_, err := os.Stat(filepath.Join(base, "nodes", spaceRoot+".mpk"))
if err == nil {
return "mpk"
}
_, err = os.Stat(filepath.Join(base, "nodes", spaceRoot+".ini"))
if err == nil {
return "ini"
}
}
return "xattrs"
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// Migration0003 migrates the file metadata to the current backend.
// Only the xattrs -> messagepack path is supported.
func (m *Migrator) Migration0003() (Result, error) {
bod := m.detectBackendOnDisk()
bod := lookup.DetectBackendOnDisk(m.lu.InternalRoot())
if bod == "" {
return resultFailed, errors.New("could not detect metadata backend on disk")
}
Expand Down Expand Up @@ -106,25 +106,3 @@ func (m *Migrator) Migration0003() (Result, error) {
m.log.Info().Msg("done.")
return resultSucceeded, nil
}

func (m *Migrator) detectBackendOnDisk() string {
root := m.lu.InternalRoot()

matches, _ := filepath.Glob(filepath.Join(root, "spaces", "*", "*"))
if len(matches) > 0 {
base := matches[len(matches)-1]
spaceid := strings.ReplaceAll(
strings.TrimPrefix(base, filepath.Join(root, "spaces")),
"/", "")
spaceRoot := lookup.Pathify(spaceid, 4, 2)
_, err := os.Stat(filepath.Join(base, "nodes", spaceRoot+".mpk"))
if err == nil {
return "mpk"
}
_, err = os.Stat(filepath.Join(base, "nodes", spaceRoot+".ini"))
if err == nil {
return "ini"
}
}
return "xattrs"
}