Repository: dragonflyoss/Dragonfly2
Pull request #1453 (2022-07-12 08:21:15)

feat: scheduler add data dir
Signed-off-by: Gaius <gaius.qi@gmail.com>

<!--- Provide a general summary of your changes in the Title above -->

## Description
- Scheduler add data dir.
<!--- Describe your changes in detail -->

## Related Issue

<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## Screenshots (if appropriate)

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation Update (if none of the other choices apply)

## Checklist

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.



Patch:
diff --git a/cmd/scheduler/cmd/root.go b/cmd/scheduler/cmd/root.go
index 452cd22b..e6a0c970 100644
--- a/cmd/scheduler/cmd/root.go
+++ b/cmd/scheduler/cmd/root.go
@@ -99,6 +99,12 @@ func initDfpath(cfg *config.ServerConfig) (dfpath.Dfpath, error) {
 	}
 	options = append(options, dfpath.WithCacheDir(cacheDir))
 
+	dataDir := dfpath.DefaultDataDir
+	if cfg.DataDir != "" {
+		dataDir = cfg.DataDir
+	}
+	options = append(options, dfpath.WithDataDir(dataDir))
+
 	return dfpath.New(options...)
 }
 
diff --git a/scheduler/config/config.go b/scheduler/config/config.go
index 1f99b5e9..d801b998 100644
--- a/scheduler/config/config.go
+++ b/scheduler/config/config.go
@@ -261,6 +261,9 @@ type ServerConfig struct {
 
 	// Server log directory.
 	LogDir string `yaml:"logDir" mapstructure:"logDir"`
+
+	// Server storage data directory.
+	DataDir string `yaml:"dataDir" mapstructure:"dataDir"`
 }
 
 type SchedulerConfig struct {


Test patch:
diff --git a/scheduler/config/config_test.go b/scheduler/config/config_test.go
index 41231c37..ef210b29 100644
--- a/scheduler/config/config_test.go
+++ b/scheduler/config/config_test.go
@@ -56,6 +56,7 @@ func TestConfig_Load(t *testing.T) {
 			Port:     8002,
 			CacheDir: "foo",
 			LogDir:   "bar",
+			DataDir:  "baz",
 		},
 		DynConfig: &DynConfig{
 			RefreshInterval: 5 * time.Minute,
diff --git a/scheduler/config/testdata/scheduler.yaml b/scheduler/config/testdata/scheduler.yaml
index 4ac5e7b9..4baea596 100644
--- a/scheduler/config/testdata/scheduler.yaml
+++ b/scheduler/config/testdata/scheduler.yaml
@@ -5,6 +5,7 @@ server:
   port: 8002
   cacheDir: foo
   logDir: bar
+  dataDir: baz
 
 scheduler:
   algorithm: default