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

Serial scheduling #266

Merged
merged 4 commits into from
Jan 21, 2019
Merged

Serial scheduling #266

merged 4 commits into from
Jan 21, 2019

Conversation

weekface
Copy link
Contributor

This pr fixes: #264, make sure only one pod can be scheduled at the same time.

@weekface
Copy link
Contributor Author

/run-e2e-tests

2 similar comments
@weekface
Copy link
Contributor Author

/run-e2e-tests

@weekface
Copy link
Contributor Author

/run-e2e-tests

var schedulingPVC *apiv1.PersistentVolumeClaim
for i := 0; i < len(pvcList.Items); i++ {
pvc := pvcList.Items[i]
if pvc.GetName() == currentPVCName && currentPVC == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to add the condition currentPVC == nil, will there be multiple PVCs with the same name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

currentPVCName := pvcName(component, podName)
var currentPVC *apiv1.PersistentVolumeClaim
var schedulingPVC *apiv1.PersistentVolumeClaim
for i := 0; i < len(pvcList.Items); i++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i := 0; i < len(pvcList.Items); i++ {
for _, pvc := range pvcList.Items {

Copy link
Contributor Author

@weekface weekface Jan 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this style to avoid the golang common mistakes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not use closures running as goroutines,If there is such a scene, then the way to use range can also avoid this problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentPVC and schedulingPVC are pointers, the pvc in the for range block is a variable, if we use the for range style, then these two variables will get the same address.

Copy link
Contributor Author

@weekface weekface Jan 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example:

package main

import "fmt"

func main() {
	arr := []string{"a", "b", "c"}

	var pa *string
	var pb *string
	for _, item := range arr {
		if item == "a" {
			pa = &item
		}
		if item == "b" {
			pb = &item
		}
	}
	fmt.Println(pa)
	fmt.Println(pb)
	fmt.Println(pa == pb)

	var ppa *string
	var ppb *string
	for i := 0; i < len(arr); i++ {
		if arr[i] == "a" {
			ppa = &arr[i]
		}
		if arr[i] == "b" {
			ppb = &arr[i]
		}
	}
	fmt.Println(ppa)
	fmt.Println(ppb)
	fmt.Println(ppa == ppb)
}

Outputs:

0xc00005e1c0
0xc00005e1c0
true
0xc000060180
0xc000060190
false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create a new variable to fix this problem. such as follow:

for i := 0; i < len(pvcList.Items); i++ { 
    pvc := pvcList.Items[i]
    ...
}
------
for _, pvc := range pvcList.Items {
    pvc := pvc
 ...
}

Copy link
Contributor Author

@weekface weekface Jan 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style for i:=0; i<n; i++ is equivalent to the for range style, but using for i:=0; i<n; i++ is more clear at this situation.

pvc := pvc looks weird.

Copy link
Contributor

@xiaojingchen xiaojingchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

xiaojingchen
xiaojingchen previously approved these changes Jan 17, 2019
onlymellb
onlymellb previously approved these changes Jan 17, 2019
Copy link
Contributor

@onlymellb onlymellb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

xiaojingchen
xiaojingchen previously approved these changes Jan 18, 2019
tennix
tennix previously approved these changes Jan 21, 2019
Copy link
Member

@tennix tennix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tennix
Copy link
Member

tennix commented Jan 21, 2019

/run-e2e-tests

@weekface weekface dismissed stale reviews from tennix, xiaojingchen, and onlymellb via 91a2c4a January 21, 2019 03:58
@weekface
Copy link
Contributor Author

/run-e2e-tests

@onlymellb onlymellb merged commit beea92f into pingcap:master Jan 21, 2019
@weekface weekface deleted the add-locl-to-scheduler branch January 21, 2019 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scheduler: scheduled the all tikv pods to same node
4 participants