-
Notifications
You must be signed in to change notification settings - Fork 1k
removing inner goroutine in cluster.Switchover #1876
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
Changes from all commits
3641911
edd5d0a
125512e
264e66d
fcb74e9
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 |
---|---|---|
|
@@ -67,7 +67,7 @@ func (c *Cluster) markRollingUpdateFlagForPod(pod *v1.Pod, msg string) error { | |
return fmt.Errorf("could not form patch for pod's rolling update flag: %v", err) | ||
} | ||
|
||
err = retryutil.Retry(c.OpConfig.PatroniAPICheckInterval, c.OpConfig.PatroniAPICheckTimeout, | ||
err = retryutil.Retry(1*time.Second, 5*time.Second, | ||
func() (bool, error) { | ||
_, err2 := c.KubeClient.Pods(pod.Namespace).Patch( | ||
context.TODO(), | ||
|
@@ -151,12 +151,13 @@ func (c *Cluster) unregisterPodSubscriber(podName spec.NamespacedName) { | |
c.podSubscribersMu.Lock() | ||
defer c.podSubscribersMu.Unlock() | ||
|
||
if _, ok := c.podSubscribers[podName]; !ok { | ||
ch, ok := c.podSubscribers[podName] | ||
if !ok { | ||
panic("subscriber for pod '" + podName.String() + "' is not found") | ||
} | ||
|
||
close(c.podSubscribers[podName]) | ||
delete(c.podSubscribers, podName) | ||
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. close() before delete() looks a bit safer here. (what does Goalng do to 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. Delete only removes the channel from c.podSubscribers map. We can still safely close it afterwards. As the go routine |
||
close(ch) | ||
} | ||
|
||
func (c *Cluster) registerPodSubscriber(podName spec.NamespacedName) chan PodEvent { | ||
|
@@ -399,11 +400,12 @@ func (c *Cluster) getPatroniMemberData(pod *v1.Pod) (patroni.MemberData, error) | |
} | ||
|
||
func (c *Cluster) recreatePod(podName spec.NamespacedName) (*v1.Pod, error) { | ||
stopCh := make(chan struct{}) | ||
ch := c.registerPodSubscriber(podName) | ||
defer c.unregisterPodSubscriber(podName) | ||
stopChan := make(chan struct{}) | ||
defer close(stopCh) | ||
|
||
err := retryutil.Retry(c.OpConfig.PatroniAPICheckInterval, c.OpConfig.PatroniAPICheckTimeout, | ||
err := retryutil.Retry(1*time.Second, 5*time.Second, | ||
func() (bool, error) { | ||
err2 := c.KubeClient.Pods(podName.Namespace).Delete( | ||
context.TODO(), | ||
|
@@ -421,7 +423,7 @@ func (c *Cluster) recreatePod(podName spec.NamespacedName) (*v1.Pod, error) { | |
if err := c.waitForPodDeletion(ch); err != nil { | ||
return nil, err | ||
} | ||
pod, err := c.waitForPodLabel(ch, stopChan, nil) | ||
pod, err := c.waitForPodLabel(ch, stopCh, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -446,7 +448,7 @@ func (c *Cluster) recreatePods(pods []v1.Pod, switchoverCandidates []spec.Namesp | |
continue | ||
} | ||
|
||
podName := util.NameFromMeta(pod.ObjectMeta) | ||
podName := util.NameFromMeta(pods[i].ObjectMeta) | ||
newPod, err := c.recreatePod(podName) | ||
if err != nil { | ||
return fmt.Errorf("could not recreate replica pod %q: %v", util.NameFromMeta(pod.ObjectMeta), err) | ||
|
Uh oh!
There was an error while loading. Please reload this page.