Skip to content

Commit

Permalink
Remove mysql statement timeout
Browse files Browse the repository at this point in the history
The mysql statement timeout just works for selects. Additionally
mysql does not support transactional rollbacks of DDL statements.
Thus there is a risk to exit in an unclean state which might cause
CC runtime errors and addtionally the timeout on selects only is not
worth much functionally.
  • Loading branch information
FloThinksPi committed Feb 20, 2024
1 parent 15045f5 commit 0a217c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
16 changes: 8 additions & 8 deletions lib/cloud_controller/db_migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def initialize(db, max_migration_duration_in_minutes=nil, max_migration_statemen
@db = db
@timeout_in_minutes = default_two_weeks(max_migration_duration_in_minutes)

@max_statement_runtime_in_seconds = if max_migration_statement_runtime_in_seconds.nil? || max_migration_statement_runtime_in_seconds <= 0
30_000
else
max_migration_statement_runtime_in_seconds * 1000
end

@db.run("SET statement_timeout TO #{@max_statement_runtime_in_seconds}") if @db.database_type == :postgres
@db.run("SET SESSION MAX_EXECUTION_TIME=#{@max_statement_runtime_in_seconds}") if @db.database_type == :mysql
@max_statement_runtime_in_milliseconds = if max_migration_statement_runtime_in_seconds.nil? || max_migration_statement_runtime_in_seconds <= 0
30_000
else
max_migration_statement_runtime_in_seconds * 1000
end

@db.run("SET statement_timeout TO #{@max_statement_runtime_in_milliseconds}") if @db.database_type == :postgres
@db.run("SET SESSION MAX_EXECUTION_TIME=#{@max_statement_runtime_in_milliseconds}") if @db.database_type == :mysql
end

def apply_migrations(opts={})
Expand Down
14 changes: 0 additions & 14 deletions spec/unit/lib/cloud_controller/db_migrator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,4 @@
DBMigrator.new(db, nil, 60)
end
end

describe 'mysql' do
it 'sets a default statement select statement timeout' do
skip if db.database_type != :mysql
expect(db).to receive(:run).with('SET SESSION MAX_EXECUTION_TIME=30000')
DBMigrator.new(db)
end

it 'sets a config provided select statement timeout' do
skip if db.database_type != :mysql
expect(db).to receive(:run).with('SET SESSION MAX_EXECUTION_TIME=60000')
DBMigrator.new(db, nil, 60)
end
end
end

0 comments on commit 0a217c2

Please sign in to comment.