-
Notifications
You must be signed in to change notification settings - Fork 77
K8SPG-374: handle standby lag detection errors #1462
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 4 commits
4e93cf0
4777d26
ab5d6a7
ba26542
74d7974
3efc054
dfb1050
b00d26a
4ad6157
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 |
|---|---|---|
|
|
@@ -72,6 +72,24 @@ func (r *PGClusterReconciler) reconcileStandbyLag(ctx context.Context, cr *v2.Pe | |
|
|
||
| lagBytes, err := r.getStandbyLag(ctx, cr) | ||
| if err != nil { | ||
| if errors.Is(err, ErrPrimaryPodNotFound) && cr.Status.State != v2.AppStateReady { | ||
| meta.SetStatusCondition(&cr.Status.Conditions, metav1.Condition{ | ||
| Type: postgrescluster.ConditionStandbyLagging, | ||
| Status: metav1.ConditionUnknown, | ||
| Reason: "PrimaryNotFound", | ||
| Message: "Cannot find primary for replication lag calculation", | ||
| }) | ||
| return nil | ||
| } | ||
| if errors.Is(err, ErrInvalidLagQueryOutput) { | ||
| meta.SetStatusCondition(&cr.Status.Conditions, metav1.Condition{ | ||
| Type: postgrescluster.ConditionStandbyLagging, | ||
| Status: metav1.ConditionUnknown, | ||
| Reason: "InvalidLagQueryOutput", | ||
| Message: "Invalid output from lag query. The WAL receiver is probably not active", | ||
| }) | ||
| return nil | ||
| } | ||
|
pooknull marked this conversation as resolved.
Outdated
Member
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. I think we should unconditionally add We can have a standard reason
Contributor
Author
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. |
||
| return errors.Wrap(err, "calculate replication lag bytes") | ||
| } | ||
|
|
||
|
|
@@ -146,10 +164,15 @@ func (r *PGClusterReconciler) getStandbyLag(ctx context.Context, standby *v2.Per | |
| return r.getLagFromMainSite(ctx, standby) | ||
| } | ||
|
|
||
| var ( | ||
| ErrPrimaryPodNotFound = errors.New("primary pod not found") | ||
| ErrInvalidLagQueryOutput = errors.New("invalid lag query output") | ||
| ) | ||
|
Comment on lines
+167
to
+170
|
||
|
|
||
| func (r *PGClusterReconciler) getLagFromStreamingHost(ctx context.Context, standby *v2.PerconaPGCluster) (int64, error) { | ||
| primary, err := perconaPG.GetPrimaryPod(ctx, r.Client, standby) | ||
| if err != nil { | ||
| return 0, errors.Wrap(err, "get primary pod") | ||
| return 0, errors.Wrapf(ErrPrimaryPodNotFound, "get primary pod: %s", err.Error()) | ||
|
pooknull marked this conversation as resolved.
|
||
| } | ||
|
pooknull marked this conversation as resolved.
|
||
|
|
||
| podExecutor := postgres.Executor(func(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string) error { | ||
|
|
@@ -166,6 +189,9 @@ func (r *PGClusterReconciler) getLagFromStreamingHost(ctx context.Context, stand | |
| } | ||
|
|
||
| lagStr := strings.TrimSpace(stdout) | ||
| if lagStr == "" { | ||
| return 0, errors.Wrapf(ErrInvalidLagQueryOutput, "failed to get lag from streaming host: invalid value: %q", lagStr) | ||
| } | ||
| lagBytes, err := strconv.ParseInt(lagStr, 10, 64) | ||
| if err != nil { | ||
| return 0, errors.Wrapf(err, "parse lag bytes: %s", lagStr) | ||
|
|
@@ -213,7 +239,7 @@ func (r *PGClusterReconciler) getWALLagBytes( | |
| ) (int64, error) { | ||
| primary, err := perconaPG.GetPrimaryPod(ctx, r.Client, standby) | ||
| if err != nil { | ||
| return 0, errors.Wrap(err, "get primary pod") | ||
| return 0, errors.Wrap(ErrPrimaryPodNotFound, "get primary pod") | ||
|
pooknull marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| podExecutor := postgres.Executor(func(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string) error { | ||
|
|
@@ -239,7 +265,7 @@ func (r *PGClusterReconciler) getWALLagBytes( | |
| func (r *PGClusterReconciler) getCurrentWALLSN(ctx context.Context, cr *v2.PerconaPGCluster) (string, error) { | ||
| primary, err := perconaPG.GetPrimaryPod(ctx, r.Client, cr) | ||
| if err != nil { | ||
| return "", errors.Wrap(err, "get primary pod") | ||
| return "", errors.Wrapf(ErrPrimaryPodNotFound, "get primary pod: %s", err.Error()) | ||
|
pooknull marked this conversation as resolved.
|
||
| } | ||
|
|
||
| podExecutor := postgres.Executor(func(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string) error { | ||
|
|
@@ -374,7 +400,7 @@ func pollAndRequeueStandbys( | |
| if !cluster.ShouldCheckStandbyLag() || status.Standby == nil || shouldSkipLagCheck(&cluster) { | ||
| continue | ||
| } | ||
| log.Info("Requeuing standby cluster for lag check", "cluster", cluster.Name) | ||
| log.V(1).Info("Requeuing standby cluster for lag check", "cluster", cluster.Name) | ||
| events <- event.GenericEvent{Object: cluster.DeepCopy()} | ||
| } | ||
| case <-ctx.Done(): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
is it possible to have app state ready while the primary cannot be found?
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.
It refers to the primary pod of the main site, not the standby