Skip to content

Commit

Permalink
Merge pull request #28238 from code-dot-org/increase-query-timeout-in…
Browse files Browse the repository at this point in the history
…-contactrollups

Increase query timeout in Contact Rollups multi-statement connection
  • Loading branch information
sureshc committed Apr 29, 2019
2 parents 3b62434 + 5a56399 commit 6e611cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/cdo/contact_rollups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ class ContactRollups
query_timeout: MAX_EXECUTION_TIME_SEC
)

def self.mysql_multi_connection
# return a connection with the MULTI_STATEMENTS flag set that allows multiple statements in one DB call
sequel_connect(
CDO.pegasus_reporting_db_writer,
CDO.pegasus_reporting_db_writer,
query_timeout: MAX_EXECUTION_TIME_SEC,
multi_statements: true
)
end

# Columns to disregard
EXCLUDED_COLUMNS = %w(id pardot_id pardot_sync_at updated_at).freeze

Expand Down Expand Up @@ -680,11 +690,6 @@ def self.update_professional_learning_attendance_for_course_from_sections(course
WHERE #{DEST_TABLE_NAME}.email = src.email"
end

def self.mysql_multi_connection
# return a connection with the MULTI_STATEMENTS flag set that allows multiple statements in one DB call
Sequel.connect(CDO.pegasus_reporting_db_writer.sub('mysql:', 'mysql2:'), flags: ::Mysql2::Client::MULTI_STATEMENTS)
end

# Extracts and formats address data from form data
# @param form_data [Hash] data from a form
# @return [Hash] hash of extracted address data. Note it may be empty if no address fields were found.
Expand Down
7 changes: 6 additions & 1 deletion lib/cdo/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# @param validation_frequency [number] How often to validate the connection. If set to -1,
# validate each time a request is made.
# @param query_timeout [number] The execution timeout for SELECT statements, in seconds.
def sequel_connect(writer, reader, validation_frequency: nil, query_timeout: nil)
def sequel_connect(writer, reader, validation_frequency: nil, query_timeout: nil, multi_statements: false)
reader = reader.gsub 'mysql:', 'mysql2:'
writer = writer.gsub 'mysql:', 'mysql2:'

Expand Down Expand Up @@ -62,6 +62,11 @@ def sequel_connect(writer, reader, validation_frequency: nil, query_timeout: nil
db_options[:init_command] = "SET SESSION MAX_EXECUTION_TIME = #{query_timeout * 1000}"
end

if multi_statements
# Configure connection with the MULTI_STATEMENTS flag set that allows multiple statements in one database call.
db_options[:flags] = ::Mysql2::Client::MULTI_STATEMENTS
end

if (reader_uri = URI(reader)).host != URI(writer).host
db_options[:servers] = {read_only: {host: reader_uri.host}}
end
Expand Down

0 comments on commit 6e611cc

Please sign in to comment.