Skip to content

Commit 49ffca1

Browse files
MySQL Mirror: set max execution time (#2958)
MySQL has a setting - `max_execution_time` - after which queries are cancelled, including ours This PR sets this setting to unlimited at a session level when connecting to MySQL --------- Co-authored-by: Kevin Biju <kevin@peerdb.io>
1 parent 7ecd289 commit 49ffca1

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

flow/activities/flowable.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ func (a *FlowableActivity) ReplicateQRepPartitions(ctx context.Context,
586586
}
587587

588588
if err != nil {
589+
logger.Error("failed to replicate partition", slog.Any("error", err))
589590
return a.Alerter.LogFlowError(ctx, config.FlowJobName, err)
590591
}
591592
}
@@ -1239,7 +1240,7 @@ func (a *FlowableActivity) GetFlowMetadata(
12391240
if err != nil {
12401241
return nil, a.Alerter.LogFlowError(ctx, input.FlowName, err)
12411242
}
1242-
logger.Info("loaded peer types for flow", slog.String("flowName", input.FlowName),
1243+
logger.Debug("loaded peer types for flow", slog.String("flowName", input.FlowName),
12431244
slog.String("sourceName", input.SourceName), slog.String("destinationName", input.DestinationName),
12441245
slog.Any("peerTypes", peerTypes))
12451246
return &protos.FlowContextMetadata{

flow/connectors/mysql/mysql.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,32 @@ func (c *MySqlConnector) connect(ctx context.Context) (*client.Conn, error) {
182182
if _, err := conn.Execute("SET sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES'"); err != nil {
183183
return nil, fmt.Errorf("failed to set sql_mode to ANSI: %w", err)
184184
}
185+
186+
// Set max_execution_time/max_statement_time to 0 (unlimited)
187+
switch c.Flavor() {
188+
case mysql.MySQLFlavor:
189+
// set max_execution_time to unlimited
190+
if _, err := conn.Execute("SET SESSION max_execution_time=0;"); err != nil {
191+
var mErr *mysql.MyError
192+
if errors.As(err, &mErr) && mErr.Code == mysql.ER_UNKNOWN_SYSTEM_VARIABLE {
193+
// max_execution_time is not supported, ignore the error
194+
c.logger.Warn("max_execution_time is not supported by the MySQL server, ignoring", slog.Any("error", err))
195+
} else {
196+
return nil, fmt.Errorf("failed to set max_execution_time to 0: %w", err)
197+
}
198+
}
199+
case mysql.MariaDBFlavor:
200+
// set max_statement_time to unlimited
201+
if _, err := conn.Execute("SET SESSION max_statement_time=0;"); err != nil {
202+
var mErr *mysql.MyError
203+
if errors.As(err, &mErr) && mErr.Code == mysql.ER_UNKNOWN_SYSTEM_VARIABLE {
204+
// max_statement_time is not supported, ignore the error
205+
c.logger.Warn("max_statement_time is not supported by the MariaDB server, ignoring", slog.Any("error", err))
206+
} else {
207+
return nil, fmt.Errorf("failed to set max_statement_time to 0: %w", err)
208+
}
209+
}
210+
}
185211
}
186212
return conn, nil
187213
}

flow/connectors/postgres/cdc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ func processMessage[Items model.Items](
720720
Prefix: msg.Prefix,
721721
Content: string(msg.Content),
722722
}, nil
723-
724723
default:
725724
if _, ok := p.hushWarnUnhandledMessageType[msg.Type()]; !ok {
726725
logger.Warn(fmt.Sprintf("Unhandled message type: %T", msg))

0 commit comments

Comments
 (0)