Repository: dragonflyoss/Dragonfly2
Pull request #1482 (2022-07-25 07:11:20)

test: find parent with ancestor
Signed-off-by: Gaius <gaius.qi@gmail.com>

<!--- Provide a general summary of your changes in the Title above -->

## Description
- Find parent with ancestor testing.
<!--- 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/scheduler/config/config.go b/scheduler/config/config.go
index 9c23cc3d..1e80e79a 100644
--- a/scheduler/config/config.go
+++ b/scheduler/config/config.go
@@ -81,6 +81,12 @@ func New() *Config {
 				HostGCInterval: DefaultSchedulerHostGCInterval,
 				HostTTL:        DefaultSchedulerHostTTL,
 			},
+			Training: &TrainingConfig{
+				Enable:               false,
+				EnableAutoRefresh:    false,
+				RefreshModelInterval: DefaultRefreshModelInterval,
+				CPU:                  DefaultCPU,
+			},
 		},
 		DynConfig: &DynConfig{
 			RefreshInterval: DefaultDynConfigRefreshInterval,
@@ -172,6 +178,16 @@ func (cfg *Config) Validate() error {
 		return errors.New("scheduler requires parameter taskTTL")
 	}
 
+	if cfg.Scheduler.Training != nil && cfg.Scheduler.Training.Enable {
+		if cfg.Scheduler.Training.CPU <= 0 {
+			return errors.New("training requires parameter cpu")
+		}
+
+		if cfg.Scheduler.Training.EnableAutoRefresh && cfg.Scheduler.Training.RefreshModelInterval <= 0 {
+			return errors.New("training requires parameter refreshModelInterval")
+		}
+	}
+
 	if cfg.DynConfig.RefreshInterval <= 0 {
 		return errors.New("dynconfig requires parameter refreshInterval")
 	}
@@ -284,6 +300,23 @@ type SchedulerConfig struct {
 
 	// Task and peer gc configuration.
 	GC *GCConfig `yaml:"gc" mapstructure:"gc"`
+
+	// Training configuration.
+	Training *TrainingConfig `yaml:"training" mapstructure:"training"`
+}
+
+type TrainingConfig struct {
+	// Enable training.
+	Enable bool `yaml:"enable" mapstructure:"enable"`
+
+	// Enable auto refresh model.
+	EnableAutoRefresh bool `yaml:"enableAutoRefresh" mapstructure:"enableAutoRefresh"`
+
+	// RefreshModelInterval is refresh interval for refreshing model.
+	RefreshModelInterval time.Duration `yaml:"refreshModelInterval" mapstructure:"refreshModelInterval"`
+
+	// CPU limit while training.
+	CPU int `yaml:"cpu" mapstructure:"cpu"`
 }
 
 type GCConfig struct {
diff --git a/scheduler/config/constants.go b/scheduler/config/constants.go
index d6d482a3..0a0d978b 100644
--- a/scheduler/config/constants.go
+++ b/scheduler/config/constants.go
@@ -76,6 +76,12 @@ const (
 
 	// DefaultSchedulerHostTTL is default ttl for host.
 	DefaultSchedulerHostTTL = 48 * time.Hour
+
+	// DefaultRefreshModelInterval is model refresh interval.
+	DefaultRefreshModelInterval = 168 * time.Hour
+
+	// DefaultCPU is default cpu usage.
+	DefaultCPU = 1
 )
 
 const (


Test patch:
diff --git a/scheduler/config/config_test.go b/scheduler/config/config_test.go
index ef210b29..49ef5034 100644
--- a/scheduler/config/config_test.go
+++ b/scheduler/config/config_test.go
@@ -48,6 +48,12 @@ func TestConfig_Load(t *testing.T) {
 				HostGCInterval: 1 * time.Minute,
 				HostTTL:        10 * time.Minute,
 			},
+			Training: &TrainingConfig{
+				Enable:               true,
+				EnableAutoRefresh:    true,
+				RefreshModelInterval: 1 * time.Second,
+				CPU:                  2,
+			},
 		},
 		Server: &ServerConfig{
 			IP:       "127.0.0.1",
@@ -140,6 +146,12 @@ func TestConfig_New(t *testing.T) {
 				HostGCInterval: 30 * time.Minute,
 				HostTTL:        48 * time.Hour,
 			},
+			Training: &TrainingConfig{
+				Enable:               false,
+				EnableAutoRefresh:    false,
+				RefreshModelInterval: 168 * time.Hour,
+				CPU:                  1,
+			},
 		},
 		DynConfig: &DynConfig{
 			RefreshInterval: 10 * time.Second,
diff --git a/scheduler/config/testdata/scheduler.yaml b/scheduler/config/testdata/scheduler.yaml
index 4baea596..d8431a9b 100644
--- a/scheduler/config/testdata/scheduler.yaml
+++ b/scheduler/config/testdata/scheduler.yaml
@@ -20,6 +20,11 @@ scheduler:
     taskTTL: 600000000000
     hostGCInterval: 60000000000
     hostTTL: 600000000000
+  training:
+    enable: true
+    enableAutoRefresh: true
+    refreshModelInterval: 1000000000
+    cpu: 2
 
 dynconfig:
   refreshInterval: 300000000000
diff --git a/scheduler/scheduler/scheduler_test.go b/scheduler/scheduler/scheduler_test.go
index f1489f23..6365e94d 100644
--- a/scheduler/scheduler/scheduler_test.go
+++ b/scheduler/scheduler/scheduler_test.go
@@ -773,12 +773,11 @@ func TestScheduler_FindParent(t *testing.T) {
 				peer.Task.StorePeer(mockPeers[0])
 				peer.Task.StorePeer(mockPeers[1])
 				peer.Task.StorePeer(mockPeers[2])
-				peer.Task.StorePeer(mockPeers[3])
-				if err := peer.Task.AddPeerEdge(mockPeers[3], mockPeers[0]); err != nil {
+				if err := peer.Task.AddPeerEdge(mockPeers[2], mockPeers[0]); err != nil {
 					t.Fatal(err)
 				}
 
-				if err := peer.Task.AddPeerEdge(mockPeers[3], mockPeers[1]); err != nil {
+				if err := peer.Task.AddPeerEdge(mockPeers[2], mockPeers[1]); err != nil {
 					t.Fatal(err)
 				}