Class: PoolLint::Inspectors::MySQL

Inherits:
Object
  • Object
show all
Defined in:
lib/poollint/inspectors/mysql.rb

Defined Under Namespace

Classes: PerformanceSchemaUnavailable, Snapshot

Constant Summary collapse

SETTING_NAME =
/\A[a-z_][a-z0-9_]*\z/
INSTRUMENT_SQL =
<<~SQL
  SELECT /*+ MAX_EXECUTION_TIME(%<timeout_ms>d) */ COUNT(*)
    FROM performance_schema.setup_instruments
   WHERE NAME = 'wait/lock/metadata/sql/mdl'
     AND ENABLED = 'YES'
SQL
USER_LOCKS_SQL =
<<~SQL
  SELECT /*+ MAX_EXECUTION_TIME(%<timeout_ms>d) */
         ml.OBJECT_NAME AS name,
         ml.LOCK_TYPE AS mode,
         ml.LOCK_STATUS AS status
    FROM performance_schema.metadata_locks ml
    JOIN performance_schema.threads t
      ON t.THREAD_ID = ml.OWNER_THREAD_ID
   WHERE ml.OBJECT_TYPE = 'USER LEVEL LOCK'
     AND ml.LOCK_STATUS = 'GRANTED'
     AND t.PROCESSLIST_ID = CONNECTION_ID()
   ORDER BY ml.OBJECT_NAME
SQL

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ MySQL

Returns a new instance of MySQL.



32
33
34
35
# File 'lib/poollint/inspectors/mysql.rb', line 32

def initialize(configuration)
  @configuration = configuration
  @allowed_settings = AllowedSettings.new(configuration.allowed_settings)
end

Instance Method Details

#establish_baseline(connection, state) ⇒ Object



37
38
39
40
41
42
# File 'lib/poollint/inspectors/mysql.rb', line 37

def establish_baseline(connection, state)
  snapshot = capture_snapshot(connection, state)
  state.capture_baseline(snapshot)
  ConnectionState.attach(connection, state)
  snapshot
end

#inspect(connection, state, inspection_point:) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/poollint/inspectors/mysql.rb', line 44

def inspect(connection, state, inspection_point:)
  baseline = state.baseline
  return establish_baseline(connection, state) unless baseline
  return unless state.dirty?

  snapshot = capture_snapshot(connection, state)
  unless state_attached?(connection, state)
    return reattach_after_reconnect(connection, state, snapshot)
  end

  report = build_report(baseline, snapshot, state, inspection_point)
  state.finish_inspection(
    snapshot: snapshot,
    rebaseline: report.leak? && @configuration.rebaseline_after_report
  )
  report if report.leak?
end