Skip to content
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

[to #48] try to fix scheduler problem #90

Merged
merged 20 commits into from
Jun 15, 2022
4 changes: 2 additions & 2 deletions cdc/cdc/model/owner_test.go
Original file line number Diff line number Diff line change
@@ -120,8 +120,8 @@ func TestTaskWorkloadMarshal(t *testing.T) {
t.Parallel()

workload := &TaskWorkload{
12: WorkloadInfo{Workload: uint64(1)},
15: WorkloadInfo{Workload: uint64(3)},
12: WorkloadInfo{Workload: int64(1)},
15: WorkloadInfo{Workload: int64(3)},
}
expected := `{"12":{"workload":1},"15":{"workload":3}}`

5 changes: 2 additions & 3 deletions cdc/cdc/owner/changefeed_test.go
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ func (s *changefeedSuite) TestRemoveChangefeed(c *check.C) {
ID: ctx.ChangefeedVars().ID,
Info: info,
})
testChangefeedReleaseResource(c, ctx, cancel, dir, true /*expectedInitialized*/)
testChangefeedReleaseResource(c, ctx, cancel, true /*expectedInitialized*/)
}

func (s *changefeedSuite) TestRemovePausedChangefeed(c *check.C) {
@@ -155,14 +155,13 @@ func (s *changefeedSuite) TestRemovePausedChangefeed(c *check.C) {
ID: ctx.ChangefeedVars().ID,
Info: info,
})
testChangefeedReleaseResource(c, ctx, cancel, dir, false /*expectedInitialized*/)
testChangefeedReleaseResource(c, ctx, cancel, false /*expectedInitialized*/)
}

func testChangefeedReleaseResource(
c *check.C,
ctx cdcContext.Context,
cancel context.CancelFunc,
redoLogDir string,
expectedInitialized bool,
) {
cf, state, captures, tester := createChangefeed4Test(ctx, c)
18 changes: 9 additions & 9 deletions cdc/pkg/scheduler/workload.go
Original file line number Diff line number Diff line change
@@ -55,23 +55,23 @@ func (w workloads) RemoveKeySpan(captureID model.CaptureID, keyspanID model.KeyS
delete(captureWorkloads, keyspanID)
}

func (w workloads) AvgEachKeySpan() uint64 {
var totalWorkload uint64
var totalKeySpan uint64
func (w workloads) AvgEachKeySpan() int64 {
var totalWorkload int64
var totalKeySpan int64
for _, captureWorkloads := range w {
for _, workload := range captureWorkloads {
totalWorkload += workload.Workload
}
totalKeySpan += uint64(len(captureWorkloads))
totalKeySpan += int64(len(captureWorkloads))
}
return totalWorkload / totalKeySpan
}

func (w workloads) Skewness() float64 {
totalWorkloads := make([]uint64, 0, len(w))
var workloadSum uint64
totalWorkloads := make([]int64, 0, len(w))
var workloadSum int64
for _, captureWorkloads := range w {
var total uint64
var total int64
for _, workload := range captureWorkloads {
total += workload.Workload
}
@@ -88,10 +88,10 @@ func (w workloads) Skewness() float64 {
}

func (w workloads) SelectIdleCapture() model.CaptureID {
minWorkload := uint64(math.MaxUint64)
minWorkload := int64(math.MaxInt64)
var minCapture model.CaptureID
for captureID, captureWorkloads := range w {
var totalWorkloadInCapture uint64
var totalWorkloadInCapture int64
for _, workload := range captureWorkloads {
totalWorkloadInCapture += workload.Workload
}
2 changes: 1 addition & 1 deletion cdc/pkg/scheduler/workload_test.go
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ func TestWorkloads(t *testing.T) {
"capture2": {4: model.WorkloadInfo{Workload: 1}, 3: model.WorkloadInfo{Workload: 2}, 5: model.WorkloadInfo{Workload: 8}},
"capture3": {6: model.WorkloadInfo{Workload: 1}},
})
require.Equal(t, w.AvgEachKeySpan(), uint64(2+1+2+8+1)/5)
require.Equal(t, w.AvgEachKeySpan(), int64(2+1+2+8+1)/5)
require.Equal(t, w.SelectIdleCapture(), "capture3")

require.Equal(t, fmt.Sprintf("%.2f%%", w.Skewness()*100), "96.36%")