Skip to content

Commit

Permalink
scheduler: adjust Batch size when created by ConfigJSONDecoder (#…
Browse files Browse the repository at this point in the history
…4747)

close #4610

adjust `Batch` size when created by `ConfigJSONDecoder`

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
  • Loading branch information
CabinfeverB authored Mar 17, 2022
1 parent e278c6c commit f1b8f80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/cluster/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cluster

import (
"context"
"encoding/json"
"math/rand"
"sync"
"testing"
Expand Down Expand Up @@ -675,6 +676,18 @@ func (s *testCoordinatorSuite) TestAddScheduler(c *C) {
c.Assert(tc.addLeaderRegion(3, 3, 1, 2), IsNil)

oc := co.opController

// test ConfigJSONDecoder create
bl, err := schedule.CreateScheduler(schedulers.BalanceLeaderType, oc, storage.NewStorageWithMemoryBackend(), schedule.ConfigJSONDecoder([]byte("{}")))
c.Assert(err, IsNil)
conf, err := bl.EncodeConfig()
c.Assert(err, IsNil)
data := make(map[string]interface{})
err = json.Unmarshal(conf, &data)
c.Assert(err, IsNil)
batch := data["batch"].(float64)
c.Assert(int(batch), Equals, 4)

gls, err := schedule.CreateScheduler(schedulers.GrantLeaderType, oc, storage.NewStorageWithMemoryBackend(), schedule.ConfigSliceDecoder(schedulers.GrantLeaderType, []string{"0"}))
c.Assert(err, IsNil)
c.Assert(co.addScheduler(gls), NotNil)
Expand Down
3 changes: 3 additions & 0 deletions server/schedulers/balance_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func init() {
if err := decoder(conf); err != nil {
return nil, err
}
if conf.Batch == 0 {
conf.Batch = BalanceLeaderBatchSize
}
return newBalanceLeaderScheduler(opController, conf), nil
})
}
Expand Down

0 comments on commit f1b8f80

Please sign in to comment.