-
Notifications
You must be signed in to change notification settings - Fork 202
K8SPXC-1748: add checks before creating functions in collector #2264
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
12537a1
a292563
e9d086f
7a14d1b
7f3588a
0f86adc
5484528
d827e83
6233eb6
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 |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ func NewPXC(addr string, user, pass string) (*PXC, error) { | |
| config.Params = map[string]string{ | ||
| "interpolateParams": "true", | ||
| "tls": "preferred", | ||
| "multiStatements": "true", | ||
| } | ||
| config.DBName = "mysql" | ||
|
|
||
|
|
@@ -205,7 +206,7 @@ func (p *PXC) SubtractGTIDSet(ctx context.Context, set, subSet string) (string, | |
| return result, nil | ||
| } | ||
|
|
||
| func getNodesByServiceName(ctx context.Context, pxcServiceName string) ([]string, error) { | ||
| func GetNodesByServiceName(ctx context.Context, pxcServiceName string) ([]string, error) { | ||
| cmd := exec.CommandContext(ctx, "/opt/percona/peer-list", "-on-start=/opt/percona/get-pxc-state.sh", "-service="+pxcServiceName) | ||
| out, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
|
|
@@ -215,7 +216,7 @@ func getNodesByServiceName(ctx context.Context, pxcServiceName string) ([]string | |
| } | ||
|
|
||
| func GetPXCFirstHost(ctx context.Context, pxcServiceName string) (string, error) { | ||
| nodes, err := getNodesByServiceName(ctx, pxcServiceName) | ||
| nodes, err := GetNodesByServiceName(ctx, pxcServiceName) | ||
| if err != nil { | ||
| return "", errors.Wrap(err, "get nodes by service name") | ||
| } | ||
|
|
@@ -236,7 +237,7 @@ func GetPXCFirstHost(ctx context.Context, pxcServiceName string) (string, error) | |
| } | ||
|
|
||
| func GetPXCOldestBinlogHost(ctx context.Context, pxcServiceName, user, pass string) (string, error) { | ||
| nodes, err := getNodesByServiceName(ctx, pxcServiceName) | ||
| nodes, err := GetNodesByServiceName(ctx, pxcServiceName) | ||
| if err != nil { | ||
| return "", errors.Wrap(err, "get nodes by service name") | ||
| } | ||
|
|
@@ -351,19 +352,27 @@ func (p *PXC) UninstallBinlogUDFComponent(ctx context.Context) error { | |
| } | ||
|
|
||
| func (p *PXC) CreateCollectorFunctions(ctx context.Context) error { | ||
| _, err := p.db.ExecContext(ctx, "CREATE FUNCTION IF NOT EXISTS get_last_record_timestamp_by_binlog RETURNS INTEGER SONAME 'binlog_utils_udf.so'") | ||
| if err != nil { | ||
| return errors.Wrap(err, "create function get_first_record_timestamp_by_binlog") | ||
| m := map[string]string{ | ||
| "get_last_record_timestamp_by_binlog": "INTEGER", | ||
| "get_gtid_set_by_binlog": "STRING", | ||
| "get_first_record_timestamp_by_binlog": "INTEGER", | ||
| } | ||
|
|
||
| _, err = p.db.ExecContext(ctx, "CREATE FUNCTION IF NOT EXISTS get_gtid_set_by_binlog RETURNS STRING SONAME 'binlog_utils_udf.so'") | ||
| if err != nil { | ||
| return errors.Wrap(err, "create function get_gtid_set_by_binlog") | ||
| } | ||
| for functionName, returnType := range m { | ||
| var x int | ||
| err := p.db.QueryRowContext(ctx, `SELECT 1 FROM mysql.func WHERE name = ? LIMIT 1`, functionName).Scan(&x) | ||
| if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||
| return errors.Wrapf(err, "check if function %s exists", functionName) | ||
| } | ||
| if err == nil { | ||
| log.Printf("function %s already exists", functionName) | ||
| continue | ||
| } | ||
|
Comment on lines
+363
to
+370
Contributor
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. Given that we are using the
Contributor
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, that's the whole point. |
||
|
|
||
| _, err = p.db.ExecContext(ctx, "CREATE FUNCTION IF NOT EXISTS get_first_record_timestamp_by_binlog RETURNS INTEGER SONAME 'binlog_utils_udf.so'") | ||
| if err != nil { | ||
| return errors.Wrap(err, "create function get_first_record_timestamp_by_binlog") | ||
| createQ := fmt.Sprintf("SET SESSION wsrep_on = OFF; CREATE FUNCTION IF NOT EXISTS %s RETURNS %s SONAME 'binlog_utils_udf.so'; SET SESSION wsrep_on = ON", functionName, returnType) | ||
| if _, err := p.db.ExecContext(ctx, createQ); err != nil { | ||
| return errors.Wrapf(err, "create function %s", functionName) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
|
|
||
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.
let's check for 8.4 as well
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.
0f86adc