-
Notifications
You must be signed in to change notification settings - Fork 720
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
schedule: refactor diagnostic manager #6771
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2022 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package diagnostic | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/tikv/pd/pkg/errs" | ||
"github.com/tikv/pd/pkg/schedule/schedulers" | ||
"github.com/tikv/pd/server/config" | ||
) | ||
|
||
// Manager is used to manage the diagnostic result of schedulers for now. | ||
type Manager struct { | ||
config *config.PersistOptions | ||
schedulerController map[string]*schedulers.ScheduleController | ||
} | ||
|
||
// NewManager creates a new Manager. | ||
func NewManager(schedulerController map[string]*schedulers.ScheduleController, config *config.PersistOptions) *Manager { | ||
return &Manager{ | ||
config: config, | ||
schedulerController: schedulerController, | ||
} | ||
} | ||
|
||
// GetDiagnosticResult gets the diagnostic result of the scheduler. | ||
func (d *Manager) GetDiagnosticResult(name string) (*schedulers.DiagnosticResult, error) { | ||
if !d.config.IsDiagnosticAllowed() { | ||
return nil, errs.ErrDiagnosticDisabled | ||
} | ||
|
||
scheduler, isSchedulerExisted := d.schedulerController[name] | ||
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. I think there's going to be a data race. We handle schedulers in coordinator with lock, but here is no lock. 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. Yes, add a lock, and I will remove it in the next PR. |
||
if !isSchedulerExisted { | ||
ts := uint64(time.Now().Unix()) | ||
res := &schedulers.DiagnosticResult{Name: name, Timestamp: ts, Status: schedulers.Disabled} | ||
return res, nil | ||
} | ||
var isDisabled bool | ||
t := scheduler.Scheduler.GetType() | ||
scheduleConfig := d.config.GetScheduleConfig() | ||
for _, s := range scheduleConfig.Schedulers { | ||
if t == s.Type { | ||
isDisabled = s.Disable | ||
break | ||
} | ||
} | ||
if isDisabled { | ||
ts := uint64(time.Now().Unix()) | ||
res := &schedulers.DiagnosticResult{Name: name, Timestamp: ts, Status: schedulers.Disabled} | ||
return res, nil | ||
} | ||
|
||
recorder := d.getSchedulerRecorder(name) | ||
if recorder == nil { | ||
return nil, errs.ErrSchedulerUndiagnosable.FastGenByArgs(name) | ||
} | ||
result := recorder.GetLastResult() | ||
if result == nil { | ||
return nil, errs.ErrNoDiagnosticResult.FastGenByArgs(name) | ||
} | ||
return result, nil | ||
} | ||
|
||
func (d *Manager) getSchedulerRecorder(name string) *schedulers.DiagnosticRecorder { | ||
return d.schedulerController[name].GetDiagnosticRecorder() | ||
} |
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.
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.
I think it's just a movement, maybe we don't need to change it?