-
Notifications
You must be signed in to change notification settings - Fork 32
K8SPS-548: fix comparePrimaryPurged function
#1125
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
f78a187
4c560b8
20ebaa0
2cc8deb
7c504f3
1d3f5d9
462f069
72c999f
703ecc3
586f28a
ae1a4be
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 |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "log" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/pkg/errors" | ||
|
|
@@ -34,7 +33,12 @@ func gtidSubtract(ctx context.Context, shell SQLRunner, a, b string) (string, er | |
| return "", errors.Errorf("unexpected output: %+v", result) | ||
| } | ||
|
|
||
| return v, nil | ||
| s, ok := v.(string) | ||
| if !ok { | ||
| return "", errors.Errorf("unexpected type: %T", v) | ||
| } | ||
|
|
||
| return s, nil | ||
| } | ||
|
|
||
| func gtidSubtractIntersection(ctx context.Context, shell SQLRunner, a, b string) (string, error) { | ||
|
|
@@ -53,7 +57,12 @@ func gtidSubtractIntersection(ctx context.Context, shell SQLRunner, a, b string) | |
| return "", errors.Errorf("unexpected output: %+v", result) | ||
| } | ||
|
|
||
| return v, nil | ||
| s, ok := v.(string) | ||
| if !ok { | ||
| return "", errors.Errorf("unexpected type: %T", v) | ||
| } | ||
|
|
||
| return s, nil | ||
| } | ||
|
|
||
| type GTIDSetRelation string | ||
|
|
@@ -114,25 +123,25 @@ func compareGTIDs(ctx context.Context, shell SQLRunner, a, b string) (GTIDSetRel | |
|
|
||
| // If purged has more gtids than the executed on the replica | ||
| // it means some data will not be recoverable | ||
| func comparePrimaryPurged(ctx context.Context, shell SQLRunner, purged, executed string) bool { | ||
| query := fmt.Sprintf("SELECT GTID_SUBTRACT('%s', '%s') = ''", purged, executed) | ||
| func comparePrimaryPurged(ctx context.Context, shell SQLRunner, purged, executed string) (bool, error) { | ||
| query := fmt.Sprintf("SELECT GTID_SUBTRACT('%s', '%s') = '' AS is_subset", purged, executed) | ||
|
|
||
| result, err := shell.runSQL(ctx, query) | ||
| if err != nil { | ||
| return false | ||
| return false, errors.Wrap(err, "run sql") | ||
| } | ||
|
|
||
| v, ok := result.Rows[0]["GTID_SUBTRACT"] | ||
| v, ok := result.Rows[0]["is_subset"] | ||
| if !ok { | ||
| return false | ||
| return false, errors.Errorf("unexpected output: %+v", result) | ||
| } | ||
|
|
||
| sub, err := strconv.Atoi(v) | ||
| if err != nil { | ||
| return false | ||
| s, ok := v.(float64) | ||
|
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. why float and not int? as far as i remember 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. Yes, it returns 1 or 0, but |
||
| if !ok { | ||
| return false, errors.Errorf("unexpected type: %T", v) | ||
| } | ||
|
|
||
| return sub == 0 | ||
| return s == 1, nil | ||
| } | ||
|
|
||
| func checkReplicaState(ctx context.Context, primary, replica SQLRunner) (innodbcluster.ReplicaGtidState, error) { | ||
|
|
@@ -169,7 +178,14 @@ func checkReplicaState(ctx context.Context, primary, replica SQLRunner) (innodbc | |
| case GTIDSetEqual: | ||
| return innodbcluster.ReplicaGtidIdentical, nil | ||
| case GTIDSetContains: | ||
| if primaryPurged == "" || comparePrimaryPurged(ctx, primary, primaryPurged, replicaExecuted) { | ||
| if primaryPurged == "" { | ||
| return innodbcluster.ReplicaGtidRecoverable, nil | ||
| } | ||
| compareRes, err := comparePrimaryPurged(ctx, primary, primaryPurged, replicaExecuted) | ||
| if err != nil { | ||
| return "", errors.Wrap(err, "compare primary purged") | ||
| } | ||
| if compareRes { | ||
| return innodbcluster.ReplicaGtidRecoverable, nil | ||
| } | ||
| return innodbcluster.ReplicaGtidIrrecoverable, nil | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.