Skip to content
Open
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
10 changes: 5 additions & 5 deletions pkg/utils/ufs_path_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ func (u UFSPathBuilder) GenUFSPathInUnifiedNamespace(mount datav1alpha1.Mount) s
// GenAlluxioUFSRootPath determines which mount point should be mounted on the root path of
// the [unified namespace] in Alluxio engine. Commonly there are two cases:
//
// 1. If a `mount` item is the only item defined in `dataset.sepc.mounts[*]` and its ufs path equals to "/", its `mountpoint` should be on the root path.
// 1. If any `mount` item defined in `dataset.spec.mounts[*]` has its ufs path equal to "/", its `mountpoint` should be on the root path.
// e.g. alluxio fs mount s3://mybucket /
// 2. Otherwise, pick `/underFSStorage` as the default root path.
// e.g. alluxio fs mount /underFSStorage / && alluxio fs mount s3://mybucket /mybucket
//
// [unified namespace]: https://docs.alluxio.io/os/user/stable/en/core-services/Unified-Namespace.html
func (u UFSPathBuilder) GenAlluxioUFSRootPath(items []datav1alpha1.Mount) (string, *datav1alpha1.Mount) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation comment for GenAlluxioUFSRootPath (lines 50-53) is now outdated. It still states that the root path is only used if there is only a single mount item defined in dataset.spec.mounts. Since this PR enables identifying the root path in multi-mount scenarios, please update the documentation comment to reflect this new behavior.

if len(items) == 1 {
m := items[0]
for i := range items {
m := &items[i]
// only iff m matches all of the two following conditions (1) m is not a fluid-native mount point; (2) m.Path is "/", it should be the root path in cache UFS.
if !common.IsFluidNativeScheme(m.MountPoint) && u.GenUFSPathInUnifiedNamespace(m) == common.RootDirPath {
return m.MountPoint, &m
if !common.IsFluidNativeScheme(m.MountPoint) && u.GenUFSPathInUnifiedNamespace(*m) == common.RootDirPath {
return m.MountPoint, m
}
}
Comment on lines +57 to 63

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Returning a pointer directly to the slice element (&items[i]) can lead to accidental mutations of the original slice elements (which typically belong to dataset.Spec.Mounts in Kubernetes controllers). This breaks the read-only assumption of the spec and can cause subtle bugs or unexpected reconciliations.

To prevent this, copy the slice element by value first, and then return a pointer to the copy (which will be safely allocated on the heap by Go's escape analysis). This also simplifies the code by avoiding the need to dereference *m when calling GenUFSPathInUnifiedNamespace.

Suggested change
for i := range items {
m := &items[i]
// only iff m matches all of the two following conditions (1) m is not a fluid-native mount point; (2) m.Path is "/", it should be the root path in cache UFS.
if !common.IsFluidNativeScheme(m.MountPoint) && u.GenUFSPathInUnifiedNamespace(m) == common.RootDirPath {
return m.MountPoint, &m
if !common.IsFluidNativeScheme(m.MountPoint) && u.GenUFSPathInUnifiedNamespace(*m) == common.RootDirPath {
return m.MountPoint, m
}
}
for i := range items {
m := items[i]
// only iff m matches all of the two following conditions (1) m is not a fluid-native mount point; (2) m.Path is "/", it should be the root path in cache UFS.
if !common.IsFluidNativeScheme(m.MountPoint) && u.GenUFSPathInUnifiedNamespace(m) == common.RootDirPath {
return m.MountPoint, &m
}
}


Expand Down
16 changes: 16 additions & 0 deletions pkg/utils/ufs_path_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ func TestGenUFSRootPathForAlluxio(t *testing.T) {
wantMount *datav1alpha1.Mount
wantRootPath string
}{
"test multi mount item with root path": {
mounts: append(
mockMountSingleItem("spark", "https://mirrors.bit.edu.cn/apache/spark/", ""),
datav1alpha1.Mount{
Name: "flink",
MountPoint: "https://mirrors.bit.edu.cn/apache/flink/",
Path: "/",
},
),
wantRootPath: "https://mirrors.bit.edu.cn/apache/flink/",
wantMount: &datav1alpha1.Mount{
Name: "flink",
MountPoint: "https://mirrors.bit.edu.cn/apache/flink/",
Path: "/",
},
},
"test multi mount item case 1": {
mounts: mockMountMultiItems(mockMountSingleItem("spark", "local://mnt/local/path", "")),
wantRootPath: "/underFSStorage",
Expand Down
Loading