-
Notifications
You must be signed in to change notification settings - Fork 726
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
scheduler: refactor clusterInfo to extract a BasicCluster, and add mockCluster to easy testing #782
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
|
||
// NewMockCluster creates a new mockCluster | ||
func newMockCluster(id *core.MockIDAllocator) *mockCluster { | ||
return &mockCluster{ |
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.
maybe we can let clusterinfo
be public and use it directly
@disksing @nolouch We need to discuss about how we deal with clusterInfo in cache.go, as @nolouch proposed in his comment. |
server/schedulers/balance_test.go
Outdated
"github.com/pingcap/kvproto/pkg/pdpb" | ||
"github.com/pingcap/pd/server/cache" | ||
"github.com/pingcap/pd/server/core" | ||
"github.com/pingcap/pd/server/schedule" | ||
_ "github.com/pingcap/pd/server/schedulers" // Register schedulers for tests. | ||
"math" |
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.
put it before 3rd-part libraries.
How about extract a cluster struct in
Then embed it into |
Any update @qqsun8819 |
@siddontang I'm working on it , plan to complete it this weekend according to @disksing 's suggestion |
1f04348
to
1bc2717
Compare
1bc2717
to
4b7d001
Compare
@disksing @nolouch @siddontang PR is updated according to review comments, PTAL if you have time |
server/cache_test.go
Outdated
@@ -337,22 +337,22 @@ func (s *testClusterInfoSuite) testRegionHeartbeat(c *C, cache *clusterInfo) { | |||
n, np := uint64(3), uint64(3) | |||
|
|||
stores := newTestStores(3) | |||
regions := newTestRegions(n, np) | |||
Regions := newTestRegions(n, np) |
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.
Don't change local variable names...
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.
done
server/cache_test.go
Outdated
@@ -84,10 +84,10 @@ var _ = Suite(&testRegionsInfoSuite{}) | |||
|
|||
type testRegionsInfoSuite struct{} | |||
|
|||
// Create n regions (0..n) of n stores (0..n). | |||
// Create n Regions (0..n) of n stores (0..n). |
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.
Don't need to change the comment.
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.
done
return &MockIDAllocator{base: 0} | ||
} | ||
|
||
// Alloc return a new id |
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.
Alloc returns a new id.
"github.com/pingcap/kvproto/pkg/pdpb" | ||
"github.com/pingcap/pd/server/cache" | ||
"github.com/pingcap/pd/server/core" | ||
"github.com/pingcap/pd/server/namespace" | ||
"github.com/pingcap/pd/server/schedule" | ||
_ "github.com/pingcap/pd/server/schedulers" // Register schedulers for tests. | ||
"math" |
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.
We usually put builtin packages before 3rd-part ones.
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.
done
server/cache.go
Outdated
@@ -36,25 +36,19 @@ var ( | |||
) | |||
|
|||
type clusterInfo struct { | |||
*schedule.BasicCluster | |||
sync.RWMutex |
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.
The RWMutex should also wrap the basic cluster, if yes, move the RWMutex to the first line of the clusterInfo.
server/cache.go
Outdated
return nil, errors.Trace(err) | ||
} | ||
log.Infof("load %v stores cost %v", c.stores.GetStoreCount(), time.Since(start)) | ||
log.Infof("load %v Stores cost %v", c.Stores.GetStoreCount(), time.Since(start)) |
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.
using stores and regions in the log and comment is ok, no need to change them.
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.
done
server/cache_test.go
Outdated
} | ||
} | ||
|
||
func (s *testClusterInfoSuite) testStoreHeartbeat(c *C, cache *clusterInfo) { | ||
n, np := uint64(3), uint64(3) | ||
stores := newTestStores(n) | ||
regions := newTestRegions(n, np) | ||
Regions := newTestRegions(n, np) |
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.
regions :=
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.
done
LGTM. |
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.
LGTM
/run-all-tests |
This pr resolves issue issue 752
1 add mockCluster in schedulers , and implements basic interface in schedule.Cluster.
2 move balance_test.go into schedulers
3 remove balance.go in server for duplicate code of schedulers/util.go
On the other hand, this pr imports some new bad smell code:
1 mockCluster has some duplicate code of clusterInfo in server/cache.go, due to dependency problem.
2 coordinator_test.go also some duplicate code of mockCluster, this is a remaining problem after we move balance_test.go out of server.
I plan to propose a new pr to resolve these two problems after this pr is merged