maatkit-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Changelog +0 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +26 -0
  4. data/lib/maatkit-ruby.rb +11 -0
  5. data/lib/maatkit-ruby/mk-archiver.rb +473 -0
  6. data/lib/maatkit-ruby/mk-checksum-filter.rb +122 -0
  7. data/lib/maatkit-ruby/mk-deadlock-logger.rb +223 -0
  8. data/lib/maatkit-ruby/mk-duplicate-key-checker.rb +239 -0
  9. data/lib/maatkit-ruby/mk-error-log.rb +240 -0
  10. data/lib/maatkit-ruby/mk-fifo-split.rb +130 -0
  11. data/lib/maatkit-ruby/mk-find.rb +137 -0
  12. data/lib/maatkit-ruby/mk-heartbeat.rb +300 -0
  13. data/lib/maatkit-ruby/mk-index-usage.rb +164 -0
  14. data/lib/maatkit-ruby/mk-kill.rb +124 -0
  15. data/lib/maatkit-ruby/mk-loadavg.rb +313 -0
  16. data/lib/maatkit-ruby/mk-log-player.rb +316 -0
  17. data/lib/maatkit-ruby/mk-merge-mqd-results.rb +248 -0
  18. data/lib/maatkit-ruby/mk-parallel-dump.rb +400 -0
  19. data/lib/maatkit-ruby/mk-parallel-restore.rb +133 -0
  20. data/lib/maatkit-ruby/mk-profile-compact.rb +87 -0
  21. data/lib/maatkit-ruby/mk-purge-logs.rb +99 -0
  22. data/lib/maatkit-ruby/mk-query-advisor.rb +105 -0
  23. data/lib/maatkit-ruby/mk-query-digest.rb +149 -0
  24. data/lib/maatkit-ruby/mk-query-profiler.rb +106 -0
  25. data/lib/maatkit-ruby/mk-show-grants.rb +103 -0
  26. data/lib/maatkit-ruby/mk-slave-delay.rb +102 -0
  27. data/lib/maatkit-ruby/mk-slave-find.rb +98 -0
  28. data/lib/maatkit-ruby/mk-slave-move.rb +99 -0
  29. data/lib/maatkit-ruby/mk-slave-prefetch.rb +124 -0
  30. data/lib/maatkit-ruby/mk-slave-restart.rb +116 -0
  31. data/lib/maatkit-ruby/mk-table-checksum.rb +151 -0
  32. data/lib/maatkit-ruby/mk-table-sync.rb +468 -0
  33. data/lib/maatkit-ruby/mk-upgrade.rb +118 -0
  34. data/lib/maatkit-ruby/mk-variable-advisor.rb +99 -0
  35. data/lib/maatkit-ruby/mk-visual-explain.rb +98 -0
  36. data/lib/maatkit-ruby/version.rb +17 -0
  37. data/setup.rb +1585 -0
  38. data/test/test_helper.rb +2 -0
  39. data/test/test_maatkit_ruby.rb +11 -0
  40. metadata +105 -0
File without changes
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Joel Bryan Juliano <joelbryan.juliano@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,26 @@
1
+ README for Maatkit-Ruby
2
+ =======================
3
+
4
+ Maatkit-Ruby is a gem providing a ruby interface to Maatkit open-source database utilities.
5
+
6
+ To install, type 'gem install maatkit-ruby'
7
+
8
+ Usage:
9
+
10
+ require 'rubygems'
11
+ require 'maatkit-ruby'
12
+
13
+ mkarchiver = Maatkit::Archiver.new
14
+ mkarchiver.source="h=oltp_server,D=test,t=tbl"
15
+ mkarchiver.dest="h=olap_server"
16
+ mkarchiver.file="/var/log/archive/%Y-%m-%d-%D.%t"
17
+ mkarchiver.where="1=1"
18
+ mkarchiver.limit=1000
19
+ mkarchiver.commit_each=true
20
+ mkarchiver.config
21
+ => "mk-archiver --source h=oltp_server,D=test,t=tbl --commit-each --limit 1000 --file /var/log/archive/%Y-%m-%d-%D.%t --where 1=1 --dest h=olap_server "
22
+ mkarchiver.start
23
+
24
+ mkerrorlog = Maatkit::ErrorLog.new
25
+ mkerrorlog.start("/var/log/mysql/mysqld.err")
26
+
@@ -0,0 +1,11 @@
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
+ require 'tempfile'
9
+
10
+ Dir[File.join(File.dirname(__FILE__), 'maatkit-ruby/**/*.rb')].sort.reverse.each { |lib| require lib }
11
+
@@ -0,0 +1,473 @@
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
+ # Archive rows from a MySQL table into another table or a file.
10
+ #
11
+ # Maatkit::Archiver.new( array, str, array)
12
+ #
13
+ class Maatkit::Archiver
14
+
15
+ #
16
+ # type: string
17
+ # Run ANALYZE TABLE afterwards on --source and/or --dest.
18
+ # Runs ANALYZE TABLE after finishing. The argument is an arbitrary string. If it contains the letter 's', the source will be analyzed. If it contains 'd', the destination will be analyzed. You can specify either or both. For example, the following will analyze both:
19
+ # --analyze=ds
20
+ # See http://dev.mysql.com/doc/en/analyze-table.html for details on ANALYZE TABLE.
21
+ attr_accessor :analyze # (No value)
22
+
23
+ #
24
+ # Ascend only first column of index.
25
+ # If you do want to use the ascending index optimization (see --no-ascend), but do not want to incur the overhead of ascending a large multi-column index, you can use this option to tell mk-archiver to ascend only the leftmost column of the index. This can provide a significant performance boost over not ascending the index at all, while avoiding the cost of ascending the whole index.
26
+ # See EXTENDING for a discussion of how this interacts with plugins.
27
+ attr_accessor :ascend_first # FALSE
28
+
29
+ #
30
+ # Prompt for a password when connecting to MySQL.
31
+ attr_accessor :ask_pass # FALSE
32
+
33
+ #
34
+ # Buffer output to --file and flush at commit.
35
+ # Disables autoflushing to --file and flushes --file to disk only when a transaction commits. This typically means the file is block-flushed by the operating system, so there may be some implicit flushes to disk between commits as well. The default is to flush --file to disk after every row.
36
+ # The danger is that a crash might cause lost data.
37
+ # The performance increase I have seen from using --buffer is around 5 to 15 percent. Your mileage may vary.
38
+ attr_accessor :buffer # FALSE
39
+
40
+ #
41
+ # Delete each chunk with a single statement (implies --commit-each).
42
+ # Delete each chunk of rows in bulk with a single DELETE statement. The statement deletes every row between the first and last row of the chunk, inclusive. It implies --commit-each, since it would be a bad idea to INSERT rows one at a time and commit them before the bulk DELETE.
43
+ # The normal method is to delete every row by its primary key. Bulk deletes might be a lot faster. They also might not be faster if you have a complex WHERE clause.
44
+ # This option completely defers all DELETE processing until the chunk of rows is finished. If you have a plugin on the source, its before_delete method will not be called. Instead, its before_bulk_delete method is called later.
45
+ # WARNING: if you have a plugin on the source that sometimes doesn't return true from is_archivable(), you should use this option only if you understand what it does. If the plugin instructs mk-archiver not to archive a row, it will still be deleted by the bulk delete!
46
+ attr_accessor :bulk_delete # FALSE
47
+
48
+ #
49
+ # default: yes
50
+ # Add --limit to --bulk-delete statement.
51
+ # This is an advanced option and you should not disable it unless you know what you are doing and why! By default, --bulk-delete appends a --limit clause to the bulk delete SQL statement. In certain cases, this clause can be omitted by specifying --no-bulk-delete-limit. --limit must still be specified.
52
+ attr_accessor :nobulk_delete_limit
53
+
54
+ #
55
+ # Insert each chunk with LOAD DATA INFILE (implies --bulk-delete --commit-each).
56
+ # Insert each chunk of rows with LOAD DATA LOCAL INFILE. This may be much faster than inserting a row at a time with INSERT statements. It is implemented by creating a temporary file for each chunk of rows, and writing the rows to this file instead of inserting them. When the chunk is finished, it uploads the rows.
57
+ # To protect the safety of your data, this option forces bulk deletes to be used. It would be unsafe to delete each row as it is found, before inserting the rows into the destination first. Forcing bulk deletes guarantees that the deletion waits until the insertion is successful.
58
+ # The --low-priority-insert, --replace, and --ignore options work with this option, but --delayed-insert does not.
59
+ attr_accessor :bulk_insert # FALSE
60
+
61
+ #
62
+ # short form: -A; type: string
63
+ # 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.
64
+ attr_accessor :charset # (No value)
65
+
66
+ #
67
+ # default: yes
68
+ # Ensure --source and --dest have same columns.
69
+ # Enabled by default; causes mk-archiver to check that the source and destination tables have the same columns. It does not check column order, data type, etc. It just checks that all columns in the source exist in the destination and vice versa. If there are any differences, mk-archiver will exit with an error.
70
+ # To disable this check, specify --no-check-columns.
71
+ attr_accessor :check_columns # TRUE
72
+
73
+ #
74
+ # type: time; default: 1s
75
+ # How often to check for slave lag if --check-slave-lag is given.
76
+ attr_accessor :check_interval # 1
77
+
78
+ #
79
+ # type: string
80
+ # Pause archiving until the specified DSN's slave lag is less than --max-lag.
81
+ attr_accessor :check_slave_lag # (No value)
82
+
83
+ #
84
+ # short form: -c; type: array
85
+ # Comma-separated list of columns to archive.
86
+ # Specify a comma-separated list of columns to fetch, write to the file, and insert into the destination table. If specified, mk-archiver ignores other columns unless it needs to add them to the SELECT statement for ascending an index or deleting rows. It fetches and uses these extra columns internally, but does not write them to the file or to the destination table. It does pass them to plugins.
87
+ # See also --primary-key-only.
88
+ attr_accessor :columns # (No value)
89
+
90
+ #
91
+ # Commit each set of fetched and archived rows (disables --txn-size).
92
+ # Commits transactions and flushes --file after each set of rows has been archived, before fetching the next set of rows, and before sleeping if --sleep is specified. Disables --txn-size; use --limit to control the transaction size with --commit-each.
93
+ # This option is useful as a shortcut to make --limit and --txn-size the same value, but more importantly it avoids transactions being held open while searching for more rows. For example, imagine you are archiving old rows from the beginning of a very large table, with --limit 1000 and --txn-size 1000. After some period of finding and archiving 1000 rows at a time, mk-archiver finds the last 999 rows and archives them, then executes the next SELECT to find more rows. This scans the rest of the table, but never finds any more rows. It has held open a transaction for a very long time, only to determine it is finished anyway. You can use --commit-each to avoid this.
94
+ attr_accessor :commit_each # FALSE
95
+
96
+ #
97
+ # type: Array
98
+ # Read this comma-separated list of config files; if specified, this must be the first option on the command line.
99
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_archiver.conf,/home/joel/.maatkit.conf,/home/joel/.mk_archiver.conf
100
+
101
+ #
102
+ # Add the DELAYED modifier to INSERT statements.
103
+ # Adds the DELAYED modifier to INSERT or REPLACE statements. See http://dev.mysql.com/doc/en/insert.html for details.
104
+ attr_accessor :delayed_insert # FALSE
105
+
106
+ #
107
+ # type: DSN
108
+ # DSN specifying the table to archive to.
109
+ # This item specifies a table into which mk-archiver will insert rows archived from --source. It uses the same key=val argument format as --source. Most missing values default to the same values as --source, so you don't have to repeat options that are the same in --source and --dest. Use the --help option to see which values are copied from --source.
110
+ # WARNING: Using a default options file (F) DSN option that defines a socket for --source causes mk-archiver to connect to --dest using that socket unless another socket for --dest is specified. This means that mk-archiver may incorrectly connect to --source when it connects to --dest. For example:
111
+ # --source F=host1.cnf,D=db,t=tbl --dest h=host2
112
+ # When mk-archiver connects to --dest, host2, it will connect via the --source, host1, socket defined in host1.cnf.
113
+ attr_accessor :dest # (No value)
114
+
115
+ #
116
+ # Print queries and exit without doing anything.
117
+ # Causes mk-archiver to exit after printing the filename and SQL statements it will use.
118
+ attr_accessor :dry_run # FALSE
119
+
120
+ #
121
+ # type: string
122
+ # File to archive to, with DATE_FORMAT()-like formatting.
123
+ # Filename to write archived rows to. A subset of MySQL's DATE_FORMAT() formatting codes are allowed in the filename, as follows:
124
+ # %d# Day of the month, numeric (01..31)
125
+ # %H# Hour (00..23)
126
+ # %i# Minutes, numeric (00..59)
127
+ # %m# Month, numeric (01..12)
128
+ # %s# Seconds (00..59)
129
+ # %Y# Year, numeric, four digits
130
+ # You can use the following extra format codes too:
131
+ # %D# Database name
132
+ # %t# Table name
133
+ # Example:
134
+ # --file '/var/log/archive/%Y-%m-%d-%D.%t'
135
+ # The file's contents are in the same format used by SELECT INTO OUTFILE, as documented in the MySQL manual: rows terminated by newlines, columns terminated by tabs, NULL characters are represented by \N, and special characters are escaped by \. This lets you reload a file with LOAD DATA INFILE's default settings.
136
+ # If you want a column header at the top of the file, see --header. The file is auto-flushed by default; see --buffer.
137
+ attr_accessor :file # (No value)
138
+
139
+ #
140
+ # Adds the FOR UPDATE modifier to SELECT statements.
141
+ # For details, see http://dev.mysql.com/doc/en/innodb-locking-reads.html.
142
+ attr_accessor :for_update # FALSE
143
+
144
+ #
145
+ # Print column header at top of --file.
146
+ # Writes column names as the first line in the file given by --file. If the file exists, does not write headers; this keeps the file loadable with LOAD DATA INFILE in case you append more output to it.
147
+ attr_accessor :header # FALSE
148
+
149
+ #
150
+ # Show help and exit.
151
+ attr_accessor :help # TRUE
152
+
153
+ #
154
+ # Adds the HIGH_PRIORITY modifier to SELECT statements.
155
+ # See http://dev.mysql.com/doc/en/select.html for details.
156
+ attr_accessor :high_priority_select # FALSE
157
+
158
+ #
159
+ # short form: -h; type: string
160
+ # Connect to host.
161
+ attr_accessor :host # (No value)
162
+
163
+ #
164
+ # Use IGNORE for INSERT statements.
165
+ # Causes INSERTs into --dest to be INSERT IGNORE.
166
+ attr_accessor :ignore # FALSE
167
+
168
+ #
169
+ # type: int; default: 1
170
+ # Number of rows to fetch and archive per statement.
171
+ # Limits the number of rows returned by the SELECT statements that retrieve rows to archive. Default is one row. It may be more efficient to increase the limit, but be careful if you are archiving sparsely, skipping over many rows; this can potentially cause more contention with other queries, depending on the storage engine, transaction isolation level, and options such as --for-update.
172
+ attr_accessor :limit # 1
173
+
174
+ #
175
+ # Do not write OPTIMIZE or ANALYZE queries to binlog.
176
+ # Adds the NO_WRITE_TO_BINLOG modifier to ANALYZE and OPTIMIZE queries. See --analyze for details.
177
+ attr_accessor :local # FALSE
178
+
179
+ #
180
+ # Adds the LOW_PRIORITY modifier to DELETE statements.
181
+ # See http://dev.mysql.com/doc/en/delete.html for details.
182
+ attr_accessor :low_priority_delete # FALSE
183
+
184
+ #
185
+ # Adds the LOW_PRIORITY modifier to INSERT or REPLACE statements.
186
+ # See http://dev.mysql.com/doc/en/insert.html for details.
187
+ attr_accessor :low_priority_insert # FALSE
188
+
189
+ #
190
+ # type: time; default: 1s
191
+ # Pause archiving if the slave given by --check-slave-lag lags.
192
+ # This option causes mk-archiver to look at the slave every time it's about to fetch another row. If the slave's lag is greater than the option's value, or if the slave isn't running (so its lag is NULL), mk-table-checksum sleeps for --check-interval seconds and then looks at the lag again. It repeats until the slave is caught up, then proceeds to fetch and archive the row.
193
+ # This option may eliminate the need for --sleep or --sleep-coef.
194
+ attr_accessor :max_lag # 1
195
+
196
+ #
197
+ # Do not use ascending index optimization.
198
+ # The default ascending-index optimization causes mk-archiver to optimize repeated SELECT queries so they seek into the index where the previous query ended, then scan along it, rather than scanning from the beginning of the table every time. This is enabled by default because it is generally a good strategy for repeated accesses.
199
+ # Large, multiple-column indexes may cause the WHERE clause to be complex enough that this could actually be less efficient. Consider for example a four-column PRIMARY KEY on (a, b, c, d). The WHERE clause to start where the last query ended is as follows:
200
+ # WHERE (a > ?)
201
+ # # OR (a = ? AND b > ?)
202
+ # # OR (a = ? AND b = ? AND c > ?)
203
+ # # OR (a = ? AND b = ? AND c = ? AND d >= ?)
204
+ # Populating the placeholders with values uses memory and CPU, adds network traffic and parsing overhead, and may make the query harder for MySQL to optimize. A four-column key isn't a big deal, but a ten-column key in which every column allows NULL might be.
205
+ # Ascending the index might not be necessary if you know you are simply removing rows from the beginning of the table in chunks, but not leaving any holes, so starting at the beginning of the table is actually the most efficient thing to do.
206
+ # See also --ascend-first. See EXTENDING for a discussion of how this interacts with plugins.
207
+ attr_accessor :no_ascend # FALSE
208
+
209
+ #
210
+ # Do not delete archived rows.
211
+ # Causes mk-archiver not to delete rows after processing them. This disallows --no-ascend, because enabling them both would cause an infinite loop.
212
+ # If there is a plugin on the source DSN, its before_delete method is called anyway, even though mk-archiver will not execute the delete. See EXTENDING for more on plugins.
213
+ attr_accessor :no_delete # FALSE
214
+
215
+ #
216
+ # type: string
217
+ # Run OPTIMIZE TABLE afterwards on --source and/or --dest.
218
+ # Runs OPTIMIZE TABLE after finishing. See --analyze for the option syntax and http://dev.mysql.com/doc/en/optimize-table.html for details on OPTIMIZE TABLE.
219
+ attr_accessor :optimize # (No value)
220
+
221
+ #
222
+ # short form: -p; type: string
223
+ # Password to use when connecting.
224
+ attr_accessor :password # (No value)
225
+
226
+ #
227
+ # type: string
228
+ # 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.
229
+ attr_accessor :pid # (No value)
230
+
231
+ #
232
+ # type: string
233
+ # Perl module name to use as a generic plugin.
234
+ # Specify the Perl module name of a general-purpose plugin. It is currently used only for statistics (see --statistics) and must have new() and a statistics() method.
235
+ # The new( src = $src, dst => $dst, opts => $o )> method gets the source and destination DSNs, and their database connections, just like the connection-specific plugins do. It also gets an OptionParser object ($o) for accessing command-line options (example: $o-get('purge');>).
236
+ # The statistics(\%stats, $time) method gets a hashref of the statistics collected by the archiving job, and the time the whole job started.
237
+ attr_accessor :plugin # (No value)
238
+
239
+ #
240
+ # short form: -P; type: int
241
+ # Port number to use for connection.
242
+ attr_accessor :port # (No value)
243
+
244
+ #
245
+ # Primary key columns only.
246
+ # A shortcut for specifying --columns with the primary key columns. This is an efficiency if you just want to purge rows; it avoids fetching the entire row, when only the primary key columns are needed for DELETE statements. See also --purge.
247
+ attr_accessor :primary_key_only # FALSE
248
+
249
+ #
250
+ # type: int
251
+ # Print progress information every X rows.
252
+ # Prints current time, elapsed time, and rows archived every X rows.
253
+ attr_accessor :progress # (No value)
254
+
255
+ #
256
+ # Purge instead of archiving; allows omitting --file and --dest.
257
+ # Allows archiving without a --file or --dest argument, which is effectively a purge since the rows are just deleted.
258
+ # If you just want to purge rows, consider specifying the table's primary key columns with --primary-key-only. This will prevent fetching all columns from the server for no reason.
259
+ attr_accessor :purge # FALSE
260
+
261
+ #
262
+ # Adds the QUICK modifier to DELETE statements.
263
+ # See http://dev.mysql.com/doc/en/delete.html for details. As stated in the documentation, in some cases it may be faster to use DELETE QUICK followed by OPTIMIZE TABLE. You can use --optimize for this.
264
+ attr_accessor :quick_delete # FALSE
265
+
266
+ #
267
+ # short form: -q
268
+ # Do not print any output, such as for --statistics.
269
+ # Suppresses normal output, including the output of --statistics, but doesn't suppress the output from --why-quit.
270
+ attr_accessor :quiet # FALSE
271
+
272
+ #
273
+ # Causes INSERTs into --dest to be written as REPLACE.
274
+ attr_accessor :replace # FALSE
275
+
276
+ #
277
+ # type: int; default: 1
278
+ # Number of retries per timeout or deadlock.
279
+ # Specifies the number of times mk-archiver should retry when there is an InnoDB lock wait timeout or deadlock. When retries are exhausted, mk-archiver will exit with an error.
280
+ # Consider carefully what you want to happen when you are archiving between a mixture of transactional and non-transactional storage engines. The INSERT to --dest and DELETE from --source are on separate connections, so they do not actually participate in the same transaction even if they're on the same server. However, mk-archiver implements simple distributed transactions in code, so commits and rollbacks should happen as desired across the two connections.
281
+ # At this time I have not written any code to handle errors with transactional storage engines other than InnoDB. Request that feature if you need it.
282
+ attr_accessor :retries # 1
283
+
284
+ #
285
+ # type: time
286
+ # Time to run before exiting.
287
+ # Optional suffix s=seconds, m=minutes, h=hours, d=days; if no suffix, s is used.
288
+ attr_accessor :run_time # (No value)
289
+
290
+ #
291
+ # default: yes
292
+ # Do not archive row with max AUTO_INCREMENT.
293
+ # Adds an extra WHERE clause to prevent mk-archiver from removing the newest row when ascending a single-column AUTO_INCREMENT key. This guards against re-using AUTO_INCREMENT values if the server restarts, and is enabled by default.
294
+ # The extra WHERE clause contains the maximum value of the auto-increment column as of the beginning of the archive or purge job. If new rows are inserted while mk-archiver is running, it will not see them.
295
+ attr_accessor :safe_auto_increment # TRUE
296
+
297
+ #
298
+ # type: string; default: /tmp/mk-archiver-sentinel
299
+ # Exit if this file exists.
300
+ # The presence of the file specified by --sentinel will cause mk-archiver to stop archiving and exit. The default is /tmp/mk-archiver-sentinel. You might find this handy to stop cron jobs gracefully if necessary. See also --stop.
301
+ attr_accessor :sentinel # /tmp/mk_archiver_sentinel
302
+
303
+ #
304
+ # type: string; default: wait_timeout=10000
305
+ # Set these MySQL variables.
306
+ # Specify any variables you want to be set immediately after connecting to MySQL. These will be included in a SET command.
307
+ attr_accessor :set_vars # wait_timeout=10000
308
+
309
+ #
310
+ # Adds the LOCK IN SHARE MODE modifier to SELECT statements.
311
+ # See http://dev.mysql.com/doc/en/innodb-locking-reads.html.
312
+ attr_accessor :share_lock # FALSE
313
+
314
+ #
315
+ # Disables foreign key checks with SET FOREIGN_KEY_CHECKS=0.
316
+ attr_accessor :skip_foreign_key_checks # FALSE
317
+
318
+ #
319
+ # type: int
320
+ # Sleep time between fetches.
321
+ # Specifies how long to sleep between SELECT statements. Default is not to sleep at all. Transactions are NOT committed, and the --file file is NOT flushed, before sleeping. See --txn-size to control that.
322
+ # If --commit-each is specified, committing and flushing happens before sleeping.
323
+ attr_accessor :sleep # (No value)
324
+
325
+ #
326
+ # type: float
327
+ # Calculate --sleep as a multiple of the last SELECT time.
328
+ # If this option is specified, mk-archiver will sleep for the query time of the last SELECT multiplied by the specified coefficient. This option is ignored if --sleep is specified.
329
+ # This is a slightly more sophisticated way to throttle the SELECTs: sleep a varying amount of time between each SELECT, depending on how long the SELECTs are taking.
330
+ attr_accessor :sleep_coef # (No value)
331
+
332
+ #
333
+ # short form: -S; type: string
334
+ # Socket file to use for connection.
335
+ attr_accessor :socket # (No value)
336
+
337
+ #
338
+ # type: DSN
339
+ # DSN specifying the table to archive from (required). This argument is a DSN. See DSN OPTIONS for the syntax. Most options control how mk-archiver connects to MySQL, but there are some extended DSN options in this tool's syntax. The D, t, and i options select a table to archive:
340
+ # --source h=my_server,D=my_database,t=my_tbl
341
+ # The a option specifies the database to set as the connection's default with USE. If the b option is true, it disables binary logging with SQL_LOG_BIN. The m option specifies pluggable actions, which an external Perl module can provide. The only required part is the table; other parts may be read from various places in the environment (such as options files).
342
+ # The 'i' part deserves special mention. This tells mk-archiver which index it should scan to archive. This appears in a FORCE INDEX or USE INDEX hint in the SELECT statements used to fetch archivable rows. If you don't specify anything, mk-archiver will auto-discover a good index, preferring a PRIMARY KEY if one exists. In my experience this usually works well, so most of the time you can probably just omit the 'i' part.
343
+ # The index is used to optimize repeated accesses to the table; mk-archiver remembers the last row it retrieves from each SELECT statement, and uses it to construct a WHERE clause, using the columns in the specified index, that should allow MySQL to start the next SELECT where the last one ended, rather than potentially scanning from the beginning of the table with each successive SELECT. If you are using external plugins, please see EXTENDING for a discussion of how they interact with ascending indexes.
344
+ # The 'a' and 'b' options allow you to control how statements flow through the binary log. If you specify the 'b' option, binary logging will be disabled on the specified connection. If you specify the 'a' option, the connection will USE the specified database, which you can use to prevent slaves from executing the binary log events with --replicate-ignore-db options. These two options can be used as different methods to achieve the same goal: archive data off the master, but leave it on the slave. For example, you can run a purge job on the master and prevent it from happening on the slave using your method of choice.
345
+ # WARNING: Using a default options file (F) DSN option that defines a socket for --source causes mk-archiver to connect to --dest using that socket unless another socket for --dest is specified. This means that mk-archiver may incorrectly connect to --source when it is meant to connect to --dest. For example:
346
+ # --source F=host1.cnf,D=db,t=tbl --dest h=host2
347
+ # When mk-archiver connects to --dest, host2, it will connect via the --source, host1, socket defined in host1.cnf.
348
+ attr_accessor :source # (No value)
349
+
350
+ #
351
+ # Collect and print timing statistics.
352
+ # Causes mk-archiver to collect timing statistics about what it does. These statistics are available to the plugin specified by --plugin
353
+ # Unless you specify --quiet, mk-archiver prints the statistics when it exits. The statistics look like this:
354
+ # Started at 2008-07-18T07:18:53, ended at 2008-07-18T07:18:53
355
+ # Source: D=db,t=table
356
+ # SELECT 4
357
+ # INSERT 4
358
+ # DELETE 4
359
+ # Action# # Count# Time# # Pct
360
+ # commit# # # 10# 0.1079# 88.27
361
+ # select# # # 5# 0.0047# 3.87
362
+ # deleting# # 4# 0.0028# 2.29
363
+ # inserting# # 4# 0.0028# 2.28
364
+ # other# # # 0# 0.0040# 3.29
365
+ # The first two (or three) lines show times and the source and destination tables. The next three lines show how many rows were fetched, inserted, and deleted.
366
+ # The remaining lines show counts and timing. The columns are the action, the total number of times that action was timed, the total time it took, and the percent of the program's total runtime. The rows are sorted in order of descending total time. The last row is the rest of the time not explicitly attributed to anything. Actions will vary depending on command-line options.
367
+ # If --why-quit is given, its behavior is changed slightly. This option causes it to print the reason for exiting even when it's just because there are no more rows.
368
+ # This option requires the standard Time::HiRes module, which is part of core Perl on reasonably new Perl releases.
369
+ attr_accessor :statistics # FALSE
370
+
371
+ #
372
+ # Stop running instances by creating the sentinel file.
373
+ # Causes mk-archiver to create the sentinel file specified by --sentinel and exit. This should have the effect of stopping all running instances which are watching the same sentinel file.
374
+ attr_accessor :stop # FALSE
375
+
376
+ #
377
+ # type: int; default: 1
378
+ # Number of rows per transaction.
379
+ # Specifies the size, in number of rows, of each transaction. Zero disables transactions altogether. After mk-archiver processes this many rows, it commits both the --source and the --dest if given, and flushes the file given by --file.
380
+ # This parameter is critical to performance. If you are archiving from a live server, which for example is doing heavy OLTP work, you need to choose a good balance between transaction size and commit overhead. Larger transactions create the possibility of more lock contention and deadlocks, but smaller transactions cause more frequent commit overhead, which can be significant. To give an idea, on a small test set I worked with while writing mk-archiver, a value of 500 caused archiving to take about 2 seconds per 1000 rows on an otherwise quiet MySQL instance on my desktop machine, archiving to disk and to another table. Disabling transactions with a value of zero, which turns on autocommit, dropped performance to 38 seconds per thousand rows.
381
+ # If you are not archiving from or to a transactional storage engine, you may want to disable transactions so mk-archiver doesn't try to commit.
382
+ attr_accessor :txn_size # 1
383
+
384
+ #
385
+ # short form: -u; type: string
386
+ # User for login if not current user.
387
+ attr_accessor :user # (No value)
388
+
389
+ #
390
+ # Show version and exit.
391
+ attr_accessor :version # FALSE
392
+
393
+ #
394
+ # type: string
395
+ # WHERE clause to limit which rows to archive (required).
396
+ # Specifies a WHERE clause to limit which rows are archived. Do not include the word WHERE. You may need to quote the argument to prevent your shell from interpreting it. For example:
397
+ # --where 'ts < current_date - interval 90 day'
398
+ # For safety, --where is required. If you do not require a WHERE clause, use --where 1=1.
399
+ attr_accessor :where # (No value)
400
+
401
+ #
402
+ # Print reason for exiting unless rows exhausted.
403
+ # Causes mk-archiver to print a message if it exits for any reason other than running out of rows to archive. This can be useful if you have a cron job with --run-time specified, for example, and you want to be sure mk-archiver is finishing before running out of time.
404
+ # If --statistics is given, the behavior is changed slightly. It will print the reason for exiting even when it's just because there are no more rows.
405
+ # This output prints even if --quiet is given. That's so you can put mk-archiver in a cron job and get an email if there's an abnormal exit.
406
+ attr_accessor :why_quit # FALSE
407
+
408
+ #
409
+ # Sets the executable path, otherwise the environment path will be used.
410
+ #
411
+ attr_accessor :path_to_mk_archiver
412
+
413
+ #
414
+ # Returns a new Archiver Object
415
+ #
416
+ def initialize()
417
+ end
418
+
419
+ #
420
+ # Execute the command
421
+ #
422
+ def start(options = nil)
423
+ tmp = Tempfile.new('tmp')
424
+ command = option_string() + options.to_s + " 2> " + tmp.path
425
+ success = system(command)
426
+ if success
427
+ begin
428
+ while (line = tmp.readline)
429
+ line.chomp
430
+ selected_string = line
431
+ end
432
+ rescue EOFError
433
+ tmp.close
434
+ end
435
+ return selected_string
436
+ else
437
+ tmp.close!
438
+ return success
439
+ end
440
+ end
441
+
442
+ def config
443
+ option_string()
444
+ end
445
+
446
+ private
447
+
448
+ def option_string()
449
+
450
+ unless @path_to_mk_archiver
451
+ ostring = "mk-archiver "
452
+ else
453
+ ostring = @path_to_mk_archiver + " "
454
+ end
455
+
456
+ self.instance_variables.each do |i|
457
+ tmp_value = self.instance_variable_get "#{i}"
458
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
459
+ unless tmp_string == "--path-to-mk-archiver"
460
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
461
+ ostring += "#{tmp_string} "
462
+ else
463
+ ostring += "#{tmp_string} #{tmp_value} "
464
+ end
465
+ end
466
+ end
467
+
468
+ return ostring
469
+
470
+ end
471
+
472
+ end
473
+