maatkit-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +0 -0
- data/MIT-LICENSE +21 -0
- data/README +26 -0
- data/lib/maatkit-ruby.rb +11 -0
- data/lib/maatkit-ruby/mk-archiver.rb +473 -0
- data/lib/maatkit-ruby/mk-checksum-filter.rb +122 -0
- data/lib/maatkit-ruby/mk-deadlock-logger.rb +223 -0
- data/lib/maatkit-ruby/mk-duplicate-key-checker.rb +239 -0
- data/lib/maatkit-ruby/mk-error-log.rb +240 -0
- data/lib/maatkit-ruby/mk-fifo-split.rb +130 -0
- data/lib/maatkit-ruby/mk-find.rb +137 -0
- data/lib/maatkit-ruby/mk-heartbeat.rb +300 -0
- data/lib/maatkit-ruby/mk-index-usage.rb +164 -0
- data/lib/maatkit-ruby/mk-kill.rb +124 -0
- data/lib/maatkit-ruby/mk-loadavg.rb +313 -0
- data/lib/maatkit-ruby/mk-log-player.rb +316 -0
- data/lib/maatkit-ruby/mk-merge-mqd-results.rb +248 -0
- data/lib/maatkit-ruby/mk-parallel-dump.rb +400 -0
- data/lib/maatkit-ruby/mk-parallel-restore.rb +133 -0
- data/lib/maatkit-ruby/mk-profile-compact.rb +87 -0
- data/lib/maatkit-ruby/mk-purge-logs.rb +99 -0
- data/lib/maatkit-ruby/mk-query-advisor.rb +105 -0
- data/lib/maatkit-ruby/mk-query-digest.rb +149 -0
- data/lib/maatkit-ruby/mk-query-profiler.rb +106 -0
- data/lib/maatkit-ruby/mk-show-grants.rb +103 -0
- data/lib/maatkit-ruby/mk-slave-delay.rb +102 -0
- data/lib/maatkit-ruby/mk-slave-find.rb +98 -0
- data/lib/maatkit-ruby/mk-slave-move.rb +99 -0
- data/lib/maatkit-ruby/mk-slave-prefetch.rb +124 -0
- data/lib/maatkit-ruby/mk-slave-restart.rb +116 -0
- data/lib/maatkit-ruby/mk-table-checksum.rb +151 -0
- data/lib/maatkit-ruby/mk-table-sync.rb +468 -0
- data/lib/maatkit-ruby/mk-upgrade.rb +118 -0
- data/lib/maatkit-ruby/mk-variable-advisor.rb +99 -0
- data/lib/maatkit-ruby/mk-visual-explain.rb +98 -0
- data/lib/maatkit-ruby/version.rb +17 -0
- data/setup.rb +1585 -0
- data/test/test_helper.rb +2 -0
- data/test/test_maatkit_ruby.rb +11 -0
- metadata +105 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
# = maatkit-ruby - A maatkit gem for Ruby
|
2
|
+
#
|
3
|
+
# Homepage:: http://github.com/jjuliano/maatkit-ruby
|
4
|
+
# Author:: Joel Bryan Juliano
|
5
|
+
# Copyright:: (cc) 2011 Joel Bryan Juliano
|
6
|
+
# License:: MIT
|
7
|
+
|
8
|
+
#
|
9
|
+
# Filter checksums from mk-table-checksum.
|
10
|
+
#
|
11
|
+
# Maatkit::ChecksumFilter.new( array, str, array)
|
12
|
+
#
|
13
|
+
class Maatkit::ChecksumFilter
|
14
|
+
|
15
|
+
#
|
16
|
+
# type: Hash
|
17
|
+
# This comma-separated list of databases are equal.
|
18
|
+
# These database names are always considered to have the same tables. In other words, this makes database1.table1.chunk1 equal to database2.table1.chunk1 if they have the same checksum.
|
19
|
+
# This disables incremental processing, so you won't see any results until all input is processed.
|
20
|
+
attr_accessor :equal_databases
|
21
|
+
|
22
|
+
#
|
23
|
+
# short form: -h
|
24
|
+
# Preserves headers output by mk-table-checksum.
|
25
|
+
attr_accessor :header # FALSE
|
26
|
+
|
27
|
+
#
|
28
|
+
# Show help and exit.
|
29
|
+
attr_accessor :help # TRUE
|
30
|
+
|
31
|
+
#
|
32
|
+
# Ignore the database name when comparing lines.
|
33
|
+
# This disables incremental processing, so you won't see any results until all input is processed.
|
34
|
+
attr_accessor :ignore_databases # FALSE
|
35
|
+
|
36
|
+
#
|
37
|
+
# type: string
|
38
|
+
# The name of the master server.
|
39
|
+
# Specifies which host is the replication master, and sorts lines for that host first, so you can see the checksum values on the master server before the slave.
|
40
|
+
attr_accessor :master
|
41
|
+
|
42
|
+
#
|
43
|
+
# type: string
|
44
|
+
# Show unique differing host/db/table names.
|
45
|
+
# The argument must be one of host, db, or table.
|
46
|
+
attr_accessor :unique # (No value)
|
47
|
+
|
48
|
+
#
|
49
|
+
# short form: -v
|
50
|
+
# Output all lines, even those that have no differences, except for header lines.
|
51
|
+
attr_accessor :verbose # FALSE
|
52
|
+
|
53
|
+
#
|
54
|
+
# Show version and exit.
|
55
|
+
attr_accessor :version # FALSE
|
56
|
+
|
57
|
+
#
|
58
|
+
# Sets the executable path, otherwise the environment path will be used.
|
59
|
+
#
|
60
|
+
attr_accessor :path_to_mk_checksum_filter
|
61
|
+
|
62
|
+
#
|
63
|
+
# Returns a new ChecksumFilter Object
|
64
|
+
#
|
65
|
+
def initialize()
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Execute the command
|
70
|
+
#
|
71
|
+
def start(options = nil)
|
72
|
+
tmp = Tempfile.new('tmp')
|
73
|
+
command = option_string() + options.to_s + " 2> " + tmp.path
|
74
|
+
success = system(command)
|
75
|
+
if success
|
76
|
+
begin
|
77
|
+
while (line = tmp.readline)
|
78
|
+
line.chomp
|
79
|
+
selected_string = line
|
80
|
+
end
|
81
|
+
rescue EOFError
|
82
|
+
tmp.close
|
83
|
+
end
|
84
|
+
return selected_string
|
85
|
+
else
|
86
|
+
tmp.close!
|
87
|
+
return success
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def config
|
92
|
+
option_string()
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def option_string()
|
98
|
+
|
99
|
+
unless @path_to_mk_checksum_filter
|
100
|
+
ostring = "mk-checksum-filter "
|
101
|
+
else
|
102
|
+
ostring = @path_to_mk_checksum_filter + " "
|
103
|
+
end
|
104
|
+
|
105
|
+
self.instance_variables.each do |i|
|
106
|
+
tmp_value = self.instance_variable_get "#{i}"
|
107
|
+
tmp_string = i.gsub("_", "-").gsub("@", "--")
|
108
|
+
unless tmp_string == "--path-to-mk-checksum-filter"
|
109
|
+
if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
|
110
|
+
ostring += "#{tmp_string} "
|
111
|
+
else
|
112
|
+
ostring += "#{tmp_string} #{tmp_value} "
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
return ostring
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
@@ -0,0 +1,223 @@
|
|
1
|
+
# = maatkit-ruby - A maatkit gem for Ruby
|
2
|
+
#
|
3
|
+
# Homepage:: http://github.com/jjuliano/maatkit-ruby
|
4
|
+
# Author:: Joel Bryan Juliano
|
5
|
+
# Copyright:: (cc) 2011 Joel Bryan Juliano
|
6
|
+
# License:: MIT
|
7
|
+
|
8
|
+
#
|
9
|
+
# Extract and log MySQL deadlock information.
|
10
|
+
#
|
11
|
+
# Maatkit::DeadlockLogger.new( array, str, array)
|
12
|
+
#
|
13
|
+
class Maatkit::DeadlockLogger
|
14
|
+
|
15
|
+
#
|
16
|
+
# Prompt for a password when connecting to MySQL.
|
17
|
+
attr_accessor :ask_pass # FALSE
|
18
|
+
|
19
|
+
#
|
20
|
+
# short form: -A; type: string
|
21
|
+
# Default character set. If the value is utf8, sets Perl's binmode on STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.
|
22
|
+
attr_accessor :charset # (No value)
|
23
|
+
|
24
|
+
#
|
25
|
+
# type: string
|
26
|
+
# Use this table to create a small deadlock. This usually has the effect of clearing out a huge deadlock, which otherwise consumes the entire output of SHOW INNODB STATUS. The table must not exist. mk-deadlock-logger will create it with the following MAGIC_clear_deadlocks structure:
|
27
|
+
# CREATE TABLE test.deadlock_maker(a INT PRIMARY KEY) ENGINE=InnoDB;
|
28
|
+
# After creating the table and causing a small deadlock, the tool will drop the table again.
|
29
|
+
attr_accessor :clear_deadlocks # (No value)
|
30
|
+
|
31
|
+
#
|
32
|
+
# Collapse whitespace in queries to a single space. This might make it easier to inspect on the command line or in a query. By default, whitespace is collapsed when printing with --print, but not modified when storing to --dest. (That is, the default is different for each action).
|
33
|
+
attr_accessor :collapse # FALSE
|
34
|
+
|
35
|
+
#
|
36
|
+
# type: hash
|
37
|
+
# Output only this comma-separated list of columns. See OUTPUT for more details on columns.
|
38
|
+
attr_accessor :columns # (No value)
|
39
|
+
|
40
|
+
#
|
41
|
+
# type: Array
|
42
|
+
# Read this comma-separated list of config files; if specified, this must be the first option on the command line.
|
43
|
+
attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_deadlock_logger.conf,/home/joel/.maatkit.conf,/home/joel/.mk_deadlock_logger.conf
|
44
|
+
|
45
|
+
#
|
46
|
+
# Create the table specified by --dest.
|
47
|
+
# Normally the --dest table is expected to exist already. This option causes mk-deadlock-logger to create the table automatically using the suggested table structure.
|
48
|
+
attr_accessor :create_dest_table # FALSE
|
49
|
+
|
50
|
+
#
|
51
|
+
# Fork to the background and detach from the shell. POSIX operating systems only.
|
52
|
+
attr_accessor :daemonize # FALSE
|
53
|
+
|
54
|
+
#
|
55
|
+
# short form: -F; type: string
|
56
|
+
# Only read mysql options from the given file. You must give an absolute pathname.
|
57
|
+
attr_accessor :defaults_file # (No value)
|
58
|
+
|
59
|
+
#
|
60
|
+
# type: DSN
|
61
|
+
# DSN for where to store deadlocks; specify at least a database (D) and table (t).
|
62
|
+
# Missing values are filled in with the same values from the source host, so you can usually omit most parts of this argument if you're storing deadlocks on the same server on which they happen.
|
63
|
+
# By default, whitespace in the query column is left intact; use --[no]collapse if you want whitespace collapsed.
|
64
|
+
# The following MAGIC_dest_table is suggested if you want to store all the information mk-deadlock-logger can extract about deadlocks:
|
65
|
+
# CREATE TABLE deadlocks (
|
66
|
+
# server char(20) NOT NULL,
|
67
|
+
# ts datetime NOT NULL,
|
68
|
+
# thread int unsigned NOT NULL,
|
69
|
+
# txn_id bigint unsigned NOT NULL,
|
70
|
+
# txn_time smallint unsigned NOT NULL,
|
71
|
+
# user char(16) NOT NULL,
|
72
|
+
# hostname char(20) NOT NULL,
|
73
|
+
# ip char(15) NOT NULL, -- alternatively, ip int unsigned NOT NULL
|
74
|
+
# db char(64) NOT NULL,
|
75
|
+
# tbl char(64) NOT NULL,
|
76
|
+
# idx char(64) NOT NULL,
|
77
|
+
# lock_type char(16) NOT NULL,
|
78
|
+
# lock_mode char(1) NOT NULL,
|
79
|
+
# wait_hold char(1) NOT NULL,
|
80
|
+
# victim tinyint unsigned NOT NULL,
|
81
|
+
# query text NOT NULL,
|
82
|
+
# PRIMARY KEY (server,ts,thread)
|
83
|
+
# ) ENGINE=InnoDB
|
84
|
+
# If you use --columns, you can omit whichever columns you don't want to store.
|
85
|
+
attr_accessor :dest # (No value)
|
86
|
+
|
87
|
+
#
|
88
|
+
# Show help and exit.
|
89
|
+
attr_accessor :help # TRUE
|
90
|
+
|
91
|
+
#
|
92
|
+
# short form: -h; type: string
|
93
|
+
# Connect to host.
|
94
|
+
attr_accessor :host # (No value)
|
95
|
+
|
96
|
+
#
|
97
|
+
# type: time
|
98
|
+
# How often to check for deadlocks. If no --run-time is specified, mk-deadlock-logger runs forever, checking for deadlocks at every interval. See also --run-time.
|
99
|
+
attr_accessor :interval # (No value)
|
100
|
+
|
101
|
+
#
|
102
|
+
# type: string
|
103
|
+
# Print all output to this file when daemonized.
|
104
|
+
attr_accessor :log # (No value)
|
105
|
+
|
106
|
+
#
|
107
|
+
# Express IP addresses as integers.
|
108
|
+
attr_accessor :numeric_ip # FALSE
|
109
|
+
|
110
|
+
#
|
111
|
+
# short form: -p; type: string
|
112
|
+
# Password to use when connecting.
|
113
|
+
attr_accessor :password # (No value)
|
114
|
+
|
115
|
+
#
|
116
|
+
# type: string
|
117
|
+
# Create the given PID file when daemonized. The file contains the process ID of the daemonized instance. The PID file is removed when the daemonized instance exits. The program checks for the existence of the PID file when starting; if it exists and the process with the matching PID exists, the program exits.
|
118
|
+
attr_accessor :pid # (No value)
|
119
|
+
|
120
|
+
#
|
121
|
+
# short form: -P; type: int
|
122
|
+
# Port number to use for connection.
|
123
|
+
attr_accessor :port # (No value)
|
124
|
+
|
125
|
+
#
|
126
|
+
# Print results on standard output. See OUTPUT for more. By default, enables --[no]collapse unless you explicitly disable it.
|
127
|
+
# If --interval or --run-time is specified, only new deadlocks are printed at each interval. A fingerprint for each deadlock is created using --columns server, ts and thread (even if those columns were not specified by --columns) and if the current deadlock's fingerprint is different from the last deadlock's fingerprint, then it is printed.
|
128
|
+
attr_accessor :print # FALSE
|
129
|
+
|
130
|
+
#
|
131
|
+
# type: time
|
132
|
+
# How long to run before exiting. By default mk-deadlock-logger runs once, checks for deadlocks, and exits. If --run-time is specified but no --interval is specified, a default 1 second interval will be used.
|
133
|
+
attr_accessor :run_time # (No value)
|
134
|
+
|
135
|
+
#
|
136
|
+
# type: string; default: wait_timeout=10000
|
137
|
+
# Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed.
|
138
|
+
attr_accessor :set_vars # wait_timeout=10000
|
139
|
+
|
140
|
+
#
|
141
|
+
# short form: -S; type: string
|
142
|
+
# Socket file to use for connection.
|
143
|
+
attr_accessor :socket # (No value)
|
144
|
+
|
145
|
+
#
|
146
|
+
# Print tab-separated columns, instead of aligned.
|
147
|
+
attr_accessor :tab # FALSE
|
148
|
+
|
149
|
+
#
|
150
|
+
# short form: -u; type: string
|
151
|
+
# User for login if not current user.
|
152
|
+
attr_accessor :user # (No value)
|
153
|
+
|
154
|
+
#
|
155
|
+
# Show version and exit.
|
156
|
+
attr_accessor :version # FALSE
|
157
|
+
|
158
|
+
#
|
159
|
+
# Sets the executable path, otherwise the environment path will be used.
|
160
|
+
#
|
161
|
+
attr_accessor :path_to_mk_deadlock_logger
|
162
|
+
|
163
|
+
#
|
164
|
+
# Returns a new DeadlockLogger Object
|
165
|
+
#
|
166
|
+
def initialize()
|
167
|
+
end
|
168
|
+
|
169
|
+
#
|
170
|
+
# Execute the command
|
171
|
+
#
|
172
|
+
def start(options = nil)
|
173
|
+
tmp = Tempfile.new('tmp')
|
174
|
+
command = option_string() + options.to_s + " 2> " + tmp.path
|
175
|
+
success = system(command)
|
176
|
+
if success
|
177
|
+
begin
|
178
|
+
while (line = tmp.readline)
|
179
|
+
line.chomp
|
180
|
+
selected_string = line
|
181
|
+
end
|
182
|
+
rescue EOFError
|
183
|
+
tmp.close
|
184
|
+
end
|
185
|
+
return selected_string
|
186
|
+
else
|
187
|
+
tmp.close!
|
188
|
+
return success
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def config
|
193
|
+
option_string()
|
194
|
+
end
|
195
|
+
|
196
|
+
private
|
197
|
+
|
198
|
+
def option_string()
|
199
|
+
|
200
|
+
unless @path_to_mk_deadlock_logger
|
201
|
+
ostring = "mk-deadlock-logger "
|
202
|
+
else
|
203
|
+
ostring = @path_to_mk_deadlock_logger + " "
|
204
|
+
end
|
205
|
+
|
206
|
+
self.instance_variables.each do |i|
|
207
|
+
tmp_value = self.instance_variable_get "#{i}"
|
208
|
+
tmp_string = i.gsub("_", "-").gsub("@", "--")
|
209
|
+
unless tmp_string == "--path-to-mk-deadlock-logger"
|
210
|
+
if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
|
211
|
+
ostring += "#{tmp_string} "
|
212
|
+
else
|
213
|
+
ostring += "#{tmp_string} #{tmp_value} "
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
return ostring
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
|
@@ -0,0 +1,239 @@
|
|
1
|
+
# = maatkit-ruby - A maatkit gem for Ruby
|
2
|
+
#
|
3
|
+
# Homepage:: http://github.com/jjuliano/maatkit-ruby
|
4
|
+
# Author:: Joel Bryan Juliano
|
5
|
+
# Copyright:: (cc) 2011 Joel Bryan Juliano
|
6
|
+
# License:: MIT
|
7
|
+
|
8
|
+
#
|
9
|
+
# Find duplicate indexes and foreign keys on MySQL tables.
|
10
|
+
#
|
11
|
+
# Maatkit::DuplicateKeyChecker.new( array, str, array)
|
12
|
+
#
|
13
|
+
class Maatkit::DuplicateKeyChecker
|
14
|
+
|
15
|
+
#
|
16
|
+
# Compare indexes with different structs (BTREE, HASH, etc).
|
17
|
+
# By default this is disabled, because a BTREE index that covers the same columns as a FULLTEXT index is
|
18
|
+
# not really a duplicate, for example.
|
19
|
+
attr_accessor :all_structs # FALSE
|
20
|
+
|
21
|
+
#
|
22
|
+
# Prompt for a password when connecting to MySQL.
|
23
|
+
attr_accessor :ask_pass # FALSE
|
24
|
+
|
25
|
+
#
|
26
|
+
# short form: -A; type: string
|
27
|
+
# Default character set. If the value is utf8, sets Perl's binmode on STDOUT to utf8, passes the
|
28
|
+
# mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other
|
29
|
+
# value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.
|
30
|
+
attr_accessor :charset # (No value)
|
31
|
+
|
32
|
+
#
|
33
|
+
# default: yes
|
34
|
+
# PK columns appended to secondary key is duplicate.
|
35
|
+
# Detects when a suffix of a secondary key is a leftmost prefix of the primary key, and treats it as a
|
36
|
+
# duplicate key. Only detects this condition on storage engines whose primary keys are clustered
|
37
|
+
# (currently InnoDB and solidDB).
|
38
|
+
# Clustered storage engines append the primary key columns to the leaf nodes of all secondary keys
|
39
|
+
# anyway, so you might consider it redundant to have them appear in the internal nodes as well. Of
|
40
|
+
# course, you may also want them in the internal nodes, because just having them at the leaf nodes won't
|
41
|
+
# help for some queries. It does help for covering index queries, however.
|
42
|
+
# Here's an example of a key that is considered redundant with this option:
|
43
|
+
# PRIMARY KEY (`a`)
|
44
|
+
# KEY `b` (`b`,`a`)
|
45
|
+
# The use of such indexes is rather subtle. For example, suppose you have the following query:
|
46
|
+
# SELECT ... WHERE b=1 ORDER BY a;
|
47
|
+
# This query will do a filesort if we remove the index on "b,a". But if we shorten the index on "b,a" to
|
48
|
+
# just "b" and also remove the ORDER BY, the query should return the same results.
|
49
|
+
# The tool suggests shortening duplicate clustered keys by dropping the key and re-adding it without the
|
50
|
+
# primary key prefix. The shortened clustered key may still duplicate another key, but the tool cannot
|
51
|
+
# currently detect when this happens without being ran a second time to re-check the newly shortened
|
52
|
+
# clustered keys. Therefore, if you shorten any duplicate clusterted keys, you should run the tool
|
53
|
+
# again.
|
54
|
+
attr_accessor :clustered # TRUE
|
55
|
+
|
56
|
+
#
|
57
|
+
# type: Array
|
58
|
+
# Read this comma-separated list of config files; if specified, this must be the first option on the
|
59
|
+
# command line.
|
60
|
+
attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_duplicate_key_checker.conf,/home/joel/.maatkit.conf,/home/joel/.mk_duplicate_key_checker.conf
|
61
|
+
|
62
|
+
#
|
63
|
+
# short form: -d; type: hash
|
64
|
+
# Check only this comma-separated list of databases.
|
65
|
+
attr_accessor :databases # (No value)
|
66
|
+
|
67
|
+
#
|
68
|
+
# short form: -F; type: string
|
69
|
+
# Only read mysql options from the given file. You must give an absolute pathname.
|
70
|
+
attr_accessor :defaults_file # (No value)
|
71
|
+
|
72
|
+
#
|
73
|
+
# short form: -e; type: hash
|
74
|
+
# Check only tables whose storage engine is in this comma-separated list.
|
75
|
+
attr_accessor :engines # (No value)
|
76
|
+
|
77
|
+
#
|
78
|
+
# Show help and exit.
|
79
|
+
attr_accessor :help # TRUE
|
80
|
+
|
81
|
+
#
|
82
|
+
# short form: -h; type: string
|
83
|
+
# Connect to host.
|
84
|
+
attr_accessor :host # (No value)
|
85
|
+
|
86
|
+
#
|
87
|
+
# type: Hash
|
88
|
+
# Ignore this comma-separated list of databases.
|
89
|
+
attr_accessor :ignore_databases #
|
90
|
+
|
91
|
+
#
|
92
|
+
# type: Hash
|
93
|
+
# Ignore this comma-separated list of storage engines.
|
94
|
+
attr_accessor :ignore_engines #
|
95
|
+
|
96
|
+
#
|
97
|
+
# Ignore index order so KEY(a,b) duplicates KEY(b,a).
|
98
|
+
attr_accessor :ignore_order # FALSE
|
99
|
+
|
100
|
+
#
|
101
|
+
# type: Hash
|
102
|
+
# Ignore this comma-separated list of tables. Table names may be qualified with the database name.
|
103
|
+
attr_accessor :ignore_tables #
|
104
|
+
|
105
|
+
#
|
106
|
+
# type: string; default: fk
|
107
|
+
# Check for duplicate f=foreign keys, k=keys or fk=both.
|
108
|
+
attr_accessor :key_types # fk
|
109
|
+
|
110
|
+
#
|
111
|
+
# short form: -p; type: string
|
112
|
+
# Password to use when connecting.
|
113
|
+
attr_accessor :password # (No value)
|
114
|
+
|
115
|
+
#
|
116
|
+
# type: string
|
117
|
+
# Create the given PID file. The file contains the process ID of the script. The PID file is removed
|
118
|
+
# when the script exits. Before starting, the script checks if the PID file already exists. If it does
|
119
|
+
# not, then the script creates and writes its own PID to it. If it does, then the script checks the
|
120
|
+
# following: if the file contains a PID and a process is running with that PID, then the script dies; or,
|
121
|
+
# if there is no process running with that PID, then the script overwrites the file with its own PID and
|
122
|
+
# starts; else, if the file contains no PID, then the script dies.
|
123
|
+
attr_accessor :pid # (No value)
|
124
|
+
|
125
|
+
#
|
126
|
+
# short form: -P; type: int
|
127
|
+
# Port number to use for connection.
|
128
|
+
attr_accessor :port # (No value)
|
129
|
+
|
130
|
+
#
|
131
|
+
# type: string; default: wait_timeout=10000
|
132
|
+
# Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET
|
133
|
+
# and executed.
|
134
|
+
attr_accessor :set_vars # wait_timeout=10000
|
135
|
+
|
136
|
+
#
|
137
|
+
# short form: -S; type: string
|
138
|
+
# Socket file to use for connection.
|
139
|
+
attr_accessor :socket # (No value)
|
140
|
+
|
141
|
+
#
|
142
|
+
# default: yes
|
143
|
+
# Print DROP KEY statement for each duplicate key. By default an ALTER TABLE DROP KEY statement is
|
144
|
+
# printed below each duplicate key so that, if you want to remove the duplicate key, you can copy-paste
|
145
|
+
# the statement into MySQL.
|
146
|
+
# To disable printing these statements, specify --nosql.
|
147
|
+
attr_accessor :sql # TRUE
|
148
|
+
|
149
|
+
#
|
150
|
+
# default: yes
|
151
|
+
# Print summary of indexes at end of output.
|
152
|
+
attr_accessor :summary # TRUE
|
153
|
+
|
154
|
+
#
|
155
|
+
# short form: -t; type: hash
|
156
|
+
# Check only this comma-separated list of tables.
|
157
|
+
# Table names may be qualified with the database name.
|
158
|
+
attr_accessor :tables # (No value)
|
159
|
+
|
160
|
+
#
|
161
|
+
# short form: -u; type: string
|
162
|
+
# User for login if not current user.
|
163
|
+
attr_accessor :user # (No value)
|
164
|
+
|
165
|
+
#
|
166
|
+
# short form: -v
|
167
|
+
# Output all keys and/or foreign keys found, not just redundant ones.
|
168
|
+
attr_accessor :verbose # FALSE
|
169
|
+
|
170
|
+
#
|
171
|
+
# Show version and exit.
|
172
|
+
attr_accessor :version # FALSE
|
173
|
+
|
174
|
+
#
|
175
|
+
# Sets the executable path, otherwise the environment path will be used.
|
176
|
+
#
|
177
|
+
attr_accessor :path_to_mk_duplicate_key_checker
|
178
|
+
|
179
|
+
#
|
180
|
+
# Returns a new DuplicateKeyChecker Object
|
181
|
+
#
|
182
|
+
def initialize()
|
183
|
+
end
|
184
|
+
|
185
|
+
#
|
186
|
+
# Execute the command
|
187
|
+
#
|
188
|
+
def start(options = nil)
|
189
|
+
tmp = Tempfile.new('tmp')
|
190
|
+
command = option_string() + options.to_s + " 2> " + tmp.path
|
191
|
+
success = system(command)
|
192
|
+
if success
|
193
|
+
begin
|
194
|
+
while (line = tmp.readline)
|
195
|
+
line.chomp
|
196
|
+
selected_string = line
|
197
|
+
end
|
198
|
+
rescue EOFError
|
199
|
+
tmp.close
|
200
|
+
end
|
201
|
+
return selected_string
|
202
|
+
else
|
203
|
+
tmp.close!
|
204
|
+
return success
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def config
|
209
|
+
option_string()
|
210
|
+
end
|
211
|
+
|
212
|
+
private
|
213
|
+
|
214
|
+
def option_string()
|
215
|
+
|
216
|
+
unless @path_to_mk_duplicate_key_checker
|
217
|
+
ostring = "mk-duplicate-key-checker "
|
218
|
+
else
|
219
|
+
ostring = @path_to_mk_duplicate_key_checker + " "
|
220
|
+
end
|
221
|
+
|
222
|
+
self.instance_variables.each do |i|
|
223
|
+
tmp_value = self.instance_variable_get "#{i}"
|
224
|
+
tmp_string = i.gsub("_", "-").gsub("@", "--")
|
225
|
+
unless tmp_string == "--path-to-mk-duplicate-key-checker"
|
226
|
+
if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
|
227
|
+
ostring += "#{tmp_string} "
|
228
|
+
else
|
229
|
+
ostring += "#{tmp_string} #{tmp_value} "
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
return ostring
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|