generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 960
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
fix multi cache dir #2639
Merged
fluid-e2e-bot
merged 8 commits into
fluid-cloudnative:master
from
zwwhdls:juicefs/fix_cache_dir
Feb 27, 2023
Merged
fix multi cache dir #2639
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0b3044f
fix multi cache dir
zwwhdls 0371305
fix unit test
zwwhdls b541f15
fix cache clear when shutdown
zwwhdls a71b50d
fix static check
zwwhdls bff002c
fix go link
zwwhdls f1b5557
check cachedir valid before remove
zwwhdls 892dc0d
update error msg
zwwhdls 428d28e
fix valid cache dir
zwwhdls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# JuiceFSRuntime 缓存配置 | ||
|
||
如何在 Fluid 中使用 JuiceFS,请参考文档[示例 - 如何在 Fluid 中使用 JuiceFS](juicefs_runtime.md)。本文讲述所有在 Fluid 中有关 JuiceFS 的缓存相关配置。 | ||
|
||
## 设置多个路径缓存 | ||
|
||
缓存路径在 JuiceFSRuntime 中的 tiredstore 设置,worker 和 fuse pod 共享相同的配置。 | ||
|
||
注意:JuiceFS 支持多路径缓存,不支持多级缓存。 | ||
|
||
```yaml | ||
apiVersion: data.fluid.io/v1alpha1 | ||
kind: JuiceFSRuntime | ||
metadata: | ||
name: jfsdemo | ||
spec: | ||
replicas: 1 | ||
tieredstore: | ||
levels: | ||
- mediumtype: SSD | ||
path: /mnt/cache1:/mnt/cache2 | ||
quota: 40Gi | ||
low: "0.1" | ||
``` | ||
|
||
其中: | ||
- `spec.tiredstore.levels.path` 可设置为多个路径,以 `:` 分隔,缓存会被分配在这里设置的所有路径下;但不支持通配符; | ||
- `spec.tiredstore.levels.quota` 为缓存对象的总大小,与路径多少无关; | ||
- `spec.tiredstore.levels.low` 为缓存路径的最小剩余空间比例,无论缓存是否达到限额,都会保证缓存路径的剩余空间; | ||
- `spec.tiredstore.levels.mediumtype` 为缓存路径的类型,目前支持 `SSD` 和 `MEM`。 | ||
|
||
|
||
## 单独设置 worker 的缓存路径 | ||
|
||
默认情况下,worker 和 fuse 的缓存路径都在 `spec.tiredstore.levels.path` 中设置,但是也可以单独设置 worker 的缓存路径。 | ||
|
||
```yaml | ||
apiVersion: data.fluid.io/v1alpha1 | ||
kind: JuiceFSRuntime | ||
metadata: | ||
name: jfsdemo | ||
spec: | ||
worker: | ||
options: | ||
"cache-dir": "/mnt/cache1:/mnt/cache2" | ||
tieredstore: | ||
levels: | ||
- mediumtype: MEM | ||
path: /dev/shm | ||
quota: 500Mi | ||
low: "0.1" | ||
``` | ||
|
||
其中: | ||
- `spec.worker.options` 为 worker 的挂载参数,缓存路径以 `cache-dir` 为 key,以 `:` 分隔的多个路径; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
@@ -29,6 +30,10 @@ import ( | |
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient" | ||
) | ||
|
||
const DirRegexFormat = "^[^\\s]*$" | ||
|
||
var DirRegex = regexp.MustCompile(DirRegexFormat) | ||
|
||
type JuiceFileUtils struct { | ||
podName string | ||
namespace string | ||
|
@@ -184,8 +189,39 @@ func (j JuiceFileUtils) Mkdir(juiceSubPath string) (err error) { | |
return | ||
} | ||
|
||
// DeleteDir delete dir in pod | ||
func (j JuiceFileUtils) DeleteDir(dir string) (err error) { | ||
// DeleteCacheDirs delete cache dir in pod | ||
func (j JuiceFileUtils) DeleteCacheDirs(dirs []string) (err error) { | ||
for _, dir := range dirs { | ||
// cache dir check | ||
match := ValidCacheDir(dir) | ||
if !match { | ||
err = fmt.Errorf("dir %s is not valid", dir) | ||
return | ||
} | ||
} | ||
var ( | ||
command = []string{"rm", "-rf"} | ||
stdout string | ||
stderr string | ||
) | ||
command = append(command, dirs...) | ||
|
||
stdout, stderr, err = j.exec(command, true) | ||
if err != nil { | ||
err = fmt.Errorf("execute command %v with expectedErr: %v stdout %s and stderr %s", command, err, stdout, stderr) | ||
return | ||
} | ||
return | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent data loss from incorrect directory parameters, I suggest using regular expressions to validate before using "rm -rf" command. Is it possible for this case? |
||
|
||
// DeleteCacheDir delete cache dir in pod | ||
func (j JuiceFileUtils) DeleteCacheDir(dir string) (err error) { | ||
// cache dir check | ||
match := ValidCacheDir(dir) | ||
if !match { | ||
err = fmt.Errorf("dir %s is not valid", dir) | ||
return | ||
} | ||
var ( | ||
command = []string{"rm", "-rf", dir} | ||
stdout string | ||
|
@@ -349,3 +385,10 @@ func (j JuiceFileUtils) QueryMetaDataInfoIntoFile(key KeyOfMetaDataFile, filenam | |
} | ||
return | ||
} | ||
|
||
func ValidCacheDir(dir string) (match bool) { | ||
if !strings.HasSuffix(dir, "raw/chunks") { | ||
return false | ||
} | ||
return DirRegex.MatchString(dir) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using the following info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zwwhdls The code now returns an error but I think we should ignore the error if it's not a valid cache dir.