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
@@ -0,0 +1,124 @@
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
+ # Pipeline relay logs on a MySQL slave to pre-warm caches.
10
+ #
11
+ # Maatkit::SlavePrefetch.new( array, str, array)
12
+ #
13
+ class Maatkit::SlavePrefetch
14
+
15
+ attr_accessor :ask_pass # FALSE
16
+ attr_accessor :charset # (No # value)
17
+ attr_accessor :check_interval # 16,1,1024
18
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_slave_prefetch.conf,/home/joel/.maatkit.conf,/home/joel/.mk_slave_prefetch.conf
19
+ attr_accessor :continue_on_error # TRUE
20
+ attr_accessor :daemonize # FALSE
21
+ attr_accessor :database # (No # value)
22
+ attr_accessor :defaults_file # (No # value)
23
+ attr_accessor :dry_run # FALSE
24
+ attr_accessor :errors # 0
25
+ attr_accessor :execute # FALSE
26
+ attr_accessor :help # TRUE
27
+ attr_accessor :host # (No # value)
28
+ attr_accessor :inject_columns # TRUE
29
+ attr_accessor :io_lag # 1024
30
+ attr_accessor :log # (No # value)
31
+ attr_accessor :max_query_time # 1
32
+ attr_accessor :num_prefix # FALSE
33
+ attr_accessor :offset # 128
34
+ attr_accessor :password # (No # value)
35
+ attr_accessor :permit_regexp # (No # value)
36
+ attr_accessor :pid # (No # value)
37
+ attr_accessor :port # (No # value)
38
+ attr_accessor :print # FALSE
39
+ attr_accessor :print_nonrewritten # FALSE
40
+ attr_accessor :progress # (No # value)
41
+ attr_accessor :query_sample_size # 4
42
+ attr_accessor :reject_regexp # (No # value)
43
+ attr_accessor :relay_log # (No # value)
44
+ attr_accessor :relay_log_dir # (No # value)
45
+ attr_accessor :run_time # (No # value)
46
+ attr_accessor :secondary_indexes # FALSE
47
+ attr_accessor :sentinel # /tmp/mk_slave_prefetch_sentinel
48
+ attr_accessor :set_vars # wait_timeout=10000
49
+ attr_accessor :sleep # 1
50
+ attr_accessor :socket # (No # value)
51
+ attr_accessor :statistics # FALSE
52
+ attr_accessor :stop # FALSE
53
+ attr_accessor :threads # 2
54
+ attr_accessor :tmpdir # /dev/null
55
+ attr_accessor :user # (No # value)
56
+ attr_accessor :version # FALSE
57
+ attr_accessor :window # 4096
58
+
59
+ #
60
+ # Sets the executable path, otherwise the environment path will be used.
61
+ #
62
+ attr_accessor :path_to_mk_slave_prefetch
63
+
64
+ #
65
+ # Returns a new SlavePrefetch Object
66
+ #
67
+ def initialize()
68
+ end
69
+
70
+ #
71
+ # Execute the command
72
+ #
73
+ def start(options = nil)
74
+ tmp = Tempfile.new('tmp')
75
+ command = option_string() + options.to_s + " 2> " + tmp.path
76
+ success = system(command)
77
+ if success
78
+ begin
79
+ while (line = tmp.readline)
80
+ line.chomp
81
+ selected_string = line
82
+ end
83
+ rescue EOFError
84
+ tmp.close
85
+ end
86
+ return selected_string
87
+ else
88
+ tmp.close!
89
+ return success
90
+ end
91
+ end
92
+
93
+ def config
94
+ option_string()
95
+ end
96
+
97
+ private
98
+
99
+ def option_string()
100
+
101
+ unless @path_to_mk_slave_prefetch
102
+ ostring = "mk-slave-prefetch "
103
+ else
104
+ ostring = @path_to_mk_slave_prefetch + " "
105
+ end
106
+
107
+ self.instance_variables.each do |i|
108
+ tmp_value = self.instance_variable_get "#{i}"
109
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
110
+ unless tmp_string == "--path-to-mk-slave-prefetch"
111
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
112
+ ostring += "#{tmp_string} "
113
+ else
114
+ ostring += "#{tmp_string} #{tmp_value} "
115
+ end
116
+ end
117
+ end
118
+
119
+ return ostring
120
+
121
+ end
122
+
123
+ end
124
+
@@ -0,0 +1,116 @@
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
+ # Watch and restart MySQL replication after errors.
10
+ #
11
+ # Maatkit::SlaveRestart.new( array, str, array)
12
+ #
13
+ class Maatkit::SlaveRestart
14
+
15
+ attr_accessor :always # FALSE
16
+ attr_accessor :ask_pass # FALSE
17
+ attr_accessor :charset # (No # value)
18
+ attr_accessor :check_relay_log # TRUE
19
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_slave_restart.conf,/home/joel/.maatkit.conf,/home/joel/.mk_slave_restart.conf
20
+ attr_accessor :daemonize # FALSE
21
+ attr_accessor :database # (No # value)
22
+ attr_accessor :defaults_file # (No # value)
23
+ attr_accessor :error_length # (No # value)
24
+ attr_accessor :error_numbers # (No # value)
25
+ attr_accessor :error_text # (No # value)
26
+ attr_accessor :help # TRUE
27
+ attr_accessor :host # (No # value)
28
+ attr_accessor :log # (No # value)
29
+ attr_accessor :max_sleep # 64
30
+ attr_accessor :min_sleep # 0.015625
31
+ attr_accessor :monitor # TRUE
32
+ attr_accessor :password # (No # value)
33
+ attr_accessor :pid # (No # value)
34
+ attr_accessor :port # (No # value)
35
+ attr_accessor :quiet # FALSE
36
+ attr_accessor :recurse # (No # value)
37
+ attr_accessor :recursion_method # (No # value)
38
+ attr_accessor :run_time # (No # value)
39
+ attr_accessor :sentinel # /tmp/mk_slave_restart_sentinel
40
+ attr_accessor :set_vars # wait_timeout=10000
41
+ attr_accessor :skip_count # 1
42
+ attr_accessor :sleep # 1
43
+ attr_accessor :socket # (No # value)
44
+ attr_accessor :stop # FALSE
45
+ attr_accessor :until_master # (No # value)
46
+ attr_accessor :until_relay # (No # value)
47
+ attr_accessor :user # (No # value)
48
+ attr_accessor :verbose # 1
49
+ attr_accessor :version # FALSE
50
+
51
+ #
52
+ # Sets the executable path, otherwise the environment path will be used.
53
+ #
54
+ attr_accessor :path_to_mk_slave_restart
55
+
56
+ #
57
+ # Returns a new SlaveRestart Object
58
+ #
59
+ def initialize()
60
+ end
61
+
62
+ #
63
+ # Execute the command
64
+ #
65
+ def start(options = nil)
66
+ tmp = Tempfile.new('tmp')
67
+ command = option_string() + options.to_s + " 2> " + tmp.path
68
+ success = system(command)
69
+ if success
70
+ begin
71
+ while (line = tmp.readline)
72
+ line.chomp
73
+ selected_string = line
74
+ end
75
+ rescue EOFError
76
+ tmp.close
77
+ end
78
+ return selected_string
79
+ else
80
+ tmp.close!
81
+ return success
82
+ end
83
+ end
84
+
85
+ def config
86
+ option_string()
87
+ end
88
+
89
+ private
90
+
91
+ def option_string()
92
+
93
+ unless @path_to_mk_slave_restart
94
+ ostring = "mk-slave-restart "
95
+ else
96
+ ostring = @path_to_mk_slave_restart + " "
97
+ end
98
+
99
+ self.instance_variables.each do |i|
100
+ tmp_value = self.instance_variable_get "#{i}"
101
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
102
+ unless tmp_string == "--path-to-mk-slave-restart"
103
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
104
+ ostring += "#{tmp_string} "
105
+ else
106
+ ostring += "#{tmp_string} #{tmp_value} "
107
+ end
108
+ end
109
+ end
110
+
111
+ return ostring
112
+
113
+ end
114
+
115
+ end
116
+
@@ -0,0 +1,151 @@
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
+ # Perform an online replication consistency check, or checksum MySQL tables efficiently on one or many servers.
10
+ #
11
+ # Maatkit::TableChecksum.new( array, str, array)
12
+ #
13
+ class Maatkit::TableChecksum
14
+
15
+ attr_accessor :algorithm # (No # value)
16
+ attr_accessor :arg_table # (No # value)
17
+ attr_accessor :ask_pass # FALSE
18
+ attr_accessor :check_interval # 1
19
+ attr_accessor :check_replication_filters # TRUE
20
+ attr_accessor :check_slave_lag # (No # value)
21
+ attr_accessor :checksum # FALSE
22
+ attr_accessor :chunk_column # (No # value)
23
+ attr_accessor :chunk_index # (No # value)
24
+ attr_accessor :chunk_size # (No # value)
25
+ attr_accessor :chunk_size_limit # (No # value)
26
+ attr_accessor :columns # (No # value)
27
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_table_checksum.conf,/home/joel/.maatkit.conf,/home/joel/.mk_table_checksum.conf
28
+ attr_accessor :count # FALSE
29
+ attr_accessor :crc # TRUE
30
+ attr_accessor :create_replicate_table # FALSE
31
+ attr_accessor :databases # (No # value)
32
+ attr_accessor :defaults_file # (No # value)
33
+ attr_accessor :empty_replicate_table # FALSE
34
+ attr_accessor :engines # (No # value)
35
+ attr_accessor :explain # FALSE
36
+ attr_accessor :explain_hosts # FALSE
37
+ attr_accessor :float_precision # (No # value)
38
+ attr_accessor :function # (No # value)
39
+ attr_accessor :help # TRUE
40
+ attr_accessor :ignore_columns # (No # value)
41
+ attr_accessor :ignore_databases # (No # value)
42
+ attr_accessor :ignore_engines # FEDERATED,MRG_MyISAM
43
+ attr_accessor :ignore_tables # (No # value)
44
+ attr_accessor :lock # FALSE
45
+ attr_accessor :max_lag # 1
46
+ attr_accessor :modulo # (No # value)
47
+ attr_accessor :offset # (No # value)
48
+ attr_accessor :optimize_xor # TRUE
49
+ attr_accessor :password # (No # value)
50
+ attr_accessor :pid # (No # value)
51
+ attr_accessor :port # (No # value)
52
+ attr_accessor :probability # 100
53
+ attr_accessor :quiet # FALSE
54
+ attr_accessor :recheck # FALSE
55
+ attr_accessor :recurse # FALSE
56
+ attr_accessor :recursion_method # (No # value)
57
+ attr_accessor :replicate # (No # value)
58
+ attr_accessor :replicate_check # (No # value)
59
+ attr_accessor :replicate_database # (No # value)
60
+ attr_accessor :resume # (No # value)
61
+ attr_accessor :resume_replicate # FALSE
62
+ attr_accessor :save_since # FALSE
63
+ attr_accessor :schema # FALSE
64
+ attr_accessor :separator # #
65
+ attr_accessor :set_vars # wait_timeout=10000
66
+ attr_accessor :since # (No # value)
67
+ attr_accessor :since_column # (No # value)
68
+ attr_accessor :single_chunk # FALSE
69
+ attr_accessor :slave_lag # FALSE
70
+ attr_accessor :sleep # (No # value)
71
+ attr_accessor :sleep_coef # (No # value)
72
+ attr_accessor :socket # (No # value)
73
+ attr_accessor :tab # FALSE
74
+ attr_accessor :tables # (No # value)
75
+ attr_accessor :throttle_method # none
76
+ attr_accessor :trim # FALSE
77
+ attr_accessor :unchunkable_tables # TRUE
78
+ attr_accessor :use_index # TRUE
79
+ attr_accessor :user # (No # value)
80
+ attr_accessor :verify # TRUE
81
+ attr_accessor :version # FALSE
82
+ attr_accessor :wait # (No # value)
83
+ attr_accessor :where # (No # value)
84
+ attr_accessor :zero_chunk # TRUE
85
+
86
+ #
87
+ # Sets the executable path, otherwise the environment path will be used.
88
+ #
89
+ attr_accessor :path_to_mk_table_checksum
90
+
91
+ #
92
+ # Returns a new TableChecksum Object
93
+ #
94
+ def initialize()
95
+ end
96
+
97
+ #
98
+ # Execute the command
99
+ #
100
+ def start(options = nil)
101
+ tmp = Tempfile.new('tmp')
102
+ command = option_string() + options.to_s + " 2> " + tmp.path
103
+ success = system(command)
104
+ if success
105
+ begin
106
+ while (line = tmp.readline)
107
+ line.chomp
108
+ selected_string = line
109
+ end
110
+ rescue EOFError
111
+ tmp.close
112
+ end
113
+ return selected_string
114
+ else
115
+ tmp.close!
116
+ return success
117
+ end
118
+ end
119
+
120
+ def config
121
+ option_string()
122
+ end
123
+
124
+ private
125
+
126
+ def option_string()
127
+
128
+ unless @path_to_mk_table_checksum
129
+ ostring = "mk-table-checksum "
130
+ else
131
+ ostring = @path_to_mk_table_checksum + " "
132
+ end
133
+
134
+ self.instance_variables.each do |i|
135
+ tmp_value = self.instance_variable_get "#{i}"
136
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
137
+ unless tmp_string == "--path-to-mk-table-checksum"
138
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
139
+ ostring += "#{tmp_string} "
140
+ else
141
+ ostring += "#{tmp_string} #{tmp_value} "
142
+ end
143
+ end
144
+ end
145
+
146
+ return ostring
147
+
148
+ end
149
+
150
+ end
151
+
@@ -0,0 +1,468 @@
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
+ # Synchronize MySQL table data efficiently.
10
+ #
11
+ # Maatkit::TableSync.new( array, str, array)
12
+ #
13
+ class Maatkit::TableSync
14
+
15
+ #
16
+ # type: string; default: Chunk,Nibble,GroupBy,Stream
17
+ # Algorithm to use when comparing the tables, in order of preference.
18
+ # For each table, mk-table-sync will check if the table can be synced with the given algorithms in the order that they're given. The first algorithm that can sync the table is used. See ALGORITHMS.
19
+ #
20
+ attr_accessor :algorithms # Chunk,Nibble,GroupBy,Stream
21
+
22
+ #
23
+ # Prompt for a password when connecting to MySQL.
24
+ #
25
+ attr_accessor :ask_pass # FALSE
26
+
27
+ #
28
+ # Enable bidirectional sync between first and subsequent hosts.
29
+ #
30
+ attr_accessor :bidirectional # FALSE
31
+
32
+ #
33
+ # default: yes
34
+ # Log to the binary log (SET SQL_LOG_BIN=1).
35
+ # Specifying --no-bin-log will SET SQL_LOG_BIN=0.
36
+ #
37
+ attr_accessor :bin_log # TRUE
38
+
39
+ #
40
+ # Instruct MySQL to buffer queries in its memory.
41
+ # This option adds the SQL_BUFFER_RESULT option to the comparison queries. This causes MySQL to execute the queries and place them in a temporary table internally before sending the results back to mk-table-sync. The advantage of this strategy is that mk-table-sync can fetch rows as desired without using a lot of memory inside the Perl process, while releasing locks on the MySQL table (to reduce contention with other queries). The disadvantage is that it uses more memory on the MySQL server instead.
42
+ # You probably want to leave --[no]buffer-to-client enabled too, because buffering into a temp table and then fetching it all into Perl's memory is probably a silly thing to do. This option is most useful for the GroupBy and Stream algorithms, which may fetch a lot of data from the server.
43
+ #
44
+ attr_accessor :buffer_in_mysql # FALSE
45
+
46
+ #
47
+ # default: yes
48
+ # Fetch rows one-by-one from MySQL while comparing.
49
+ # This option enables mysql_use_result which causes MySQL to hold the selected rows on the server until the tool fetches them. This allows the tool to use less memory but may keep the rows locked on the server longer.
50
+ # If this option is disabled by specifying --no-buffer-to-client then mysql_store_result is used which causes MySQL to send all selected rows to the tool at once. This may result in the results "cursor" being held open for a shorter time on the server, but if the tables are large, it could take a long time anyway, and use all your memory.
51
+ # For most non-trivial data sizes, you want to leave this option enabled.
52
+ # This option is disabled when --bidirectional is used.
53
+ #
54
+ attr_accessor :buffer_to_client # TRUE
55
+
56
+ #
57
+ # short form: -A; type: string
58
+ # 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.
59
+ #
60
+ attr_accessor :charset # (No value)
61
+
62
+ #
63
+ # default: yes
64
+ # With --sync-to-master, try to verify that the detected master is the real master.
65
+ #
66
+ attr_accessor :check_master # TRUE
67
+
68
+ #
69
+ # default: yes
70
+ # Check that user has all necessary privileges on source and destination table.
71
+ attr_accessor :check_privileges # TRUE
72
+
73
+ #
74
+ # default: yes
75
+ # Check whether the destination server is a slave.
76
+ # If the destination server is a slave, it's generally unsafe to make changes on it. However, sometimes you have to; --replace won't work unless there's a unique index, for example, so you can't make changes on the master in that scenario. By default mk-table-sync will complain if you try to change data on a slave. Specify --no-slave-check to disable this check. Use it at your own risk.
77
+ attr_accessor :check_slave # TRUE
78
+
79
+ #
80
+ # default: yes
81
+ # Check that no triggers are defined on the destination table.
82
+ # Triggers were introduced in MySQL v5.0.2, so for older versions this option has no effect because triggers will not be checked.
83
+ attr_accessor :check_triggers # TRUE
84
+
85
+ #
86
+ # type: string
87
+ # Chunk the table on this column.
88
+ attr_accessor :chunk_column # (No value)
89
+
90
+ #
91
+ # type: string
92
+ # Chunk the table using this index.
93
+ attr_accessor :chunk_index # (No value)
94
+
95
+ #
96
+ # type: string; default: 1000
97
+ # Number of rows or data size per chunk.
98
+ # The size of each chunk of rows for the Chunk and Nibble algorithms. The size can be either a number of rows, or a data size. Data sizes are specified with a suffix of k=kibibytes, M=mebibytes, G=gibibytes. Data sizes are converted to a number of rows by dividing by the average row length.
99
+ attr_accessor :chunk_size # 1000
100
+
101
+ #
102
+ # short form: -c; type: array
103
+ # Compare this comma-separated list of columns.
104
+ attr_accessor :columns # (No value)
105
+
106
+ #
107
+ # type: Array
108
+ # Read this comma-separated list of config files; if specified, this must be the first option on the command line.
109
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_table_sync.conf,/home/user/.maatkit.conf,/home/user/.mk_table_sync.conf
110
+
111
+ #
112
+ # type: string
113
+ # Compare this column when rows conflict during a --bidirectional sync.
114
+ # When a same but differing row is found the value of this column from each row is compared according to --conflict-comparison, --conflict-value and --conflict-threshold to determine which row has the correct data and becomes the source. The column can be any type for which there is an appropriate --conflict-comparison (this is almost all types except, for example, blobs).
115
+ # This option only works with --bidirectional. See BIDIRECTIONAL SYNCING for more information.
116
+ attr_accessor :conflict_column # (No value)
117
+
118
+ #
119
+ # type: string
120
+ # Choose the --conflict-column with this property as the source.
121
+ # The option affects how the --conflict-column values from the conflicting rows are compared. Possible comparisons are one of these MAGIC_comparisons:
122
+ #newest|oldest|greatest|least|equals|matches
123
+ #COMPARISON CHOOSES ROW WITH
124
+ #========== =========================================================
125
+ #newest #Newest temporal L<--conflict-column> value
126
+ #oldest #Oldest temporal L<--conflict-column> value
127
+ #greatest # Greatest numerical L<--conflict-column> value
128
+ #least # Least numerical L<--conflict-column> value
129
+ #equals #L<--conflict-column> value equal to L<--conflict-value>
130
+ #matches #L<--conflict-column> value matching Perl regex pattern
131
+ # # #L<--conflict-value>
132
+ # This option only works with --bidirectional. See BIDIRECTIONAL SYNCING for more information.
133
+ attr_accessor :conflict_comparison # (No value)
134
+
135
+ #
136
+ # type: string; default: warn
137
+ # How to report unresolvable conflicts and conflict errors
138
+ # This option changes how the user is notified when a conflict cannot be resolved or causes some kind of error. Possible values are:
139
+ #* warn: Print a warning to STDERR about the unresolvable conflict
140
+ #* die: Die, stop syncing, and print a warning to STDERR
141
+ # This option only works with --bidirectional. See BIDIRECTIONAL SYNCING for more information.
142
+ attr_accessor :conflict_error # warn
143
+
144
+ #
145
+ # type: string
146
+ # Amount by which one --conflict-column must exceed the other.
147
+ # The --conflict-threshold prevents a conflict from being resolved if the absolute difference between the two --conflict-column values is less than this amount. For example, if two --conflict-column have timestamp values "2009-12-01 12:00:00" and "2009-12-01 12:05:00" the difference is 5 minutes. If --conflict-threshold is set to "5m" the conflict will be resolved, but if --conflict-threshold is set to "6m" the conflict will fail to resolve because the difference is not greater than or equal to 6 minutes. In this latter case, --conflict-error will report the failure.
148
+ # This option only works with --bidirectional. See BIDIRECTIONAL SYNCING for more information.
149
+ attr_accessor :conflict_threshold # (No value)
150
+
151
+ #
152
+ # type: string
153
+ # Use this value for certain --conflict-comparison.
154
+ # This option gives the value for equals and matches --conflict-comparison.
155
+ # This option only works with --bidirectional. See BIDIRECTIONAL SYNCING for more information.
156
+ attr_accessor :conflict_value # (No value)
157
+
158
+ #
159
+ # short form: -d; type: hash
160
+ # Sync only this comma-separated list of databases.
161
+ # A common request is to sync tables from one database with tables from another database on the same or different server. This is not yet possible. --databases will not do it, and you can't do it with the D part of the DSN either because in the absence of a table name it assumes the whole server should be synced and the D part controls only the connection's default database.
162
+ attr_accessor :databases # (No value)
163
+
164
+ #
165
+ # short form: -F; type: string
166
+ # Only read mysql options from the given file. You must give an absolute pathname.
167
+ attr_accessor :defaults_file # (No value)
168
+
169
+ #
170
+ # Analyze, decide the sync algorithm to use, print and exit.
171
+ # Implies --verbose so you can see the results. The results are in the same output format that you'll see from actually running the tool, but there will be zeros for rows affected. This is because the tool actually executes, but stops before it compares any data and just returns zeros. The zeros do not mean there are no changes to be made.
172
+ attr_accessor :dry_run # FALSE
173
+
174
+ #
175
+ # short form: -e; type: hash
176
+ # Sync only this comma-separated list of storage engines.
177
+ attr_accessor :engines # (No value)
178
+
179
+ #
180
+ # Execute queries to make the tables have identical data.
181
+ # This option makes mk-table-sync actually sync table data by executing all the queries that it created to resolve table differences. Therefore, the tables will be changed! And unless you also specify --verbose, the changes will be made silently. If this is not what you want, see --print or --dry-run.
182
+ attr_accessor :execute # FALSE
183
+
184
+ #
185
+ # Print connection information and exit.
186
+ # Print out a list of hosts to which mk-table-sync will connect, with all the various connection options, and exit.
187
+ attr_accessor :explain_hosts # FALSE
188
+
189
+ #
190
+ # type: int
191
+ # Precision for FLOAT and DOUBLE number-to-string conversion. Causes FLOAT and DOUBLE values to be rounded to the specified number of digits after the decimal point, with the ROUND() function in MySQL. This can help avoid checksum mismatches due to different floating-point representations of the same values on different MySQL versions and hardware. The default is no rounding; the values are converted to strings by the CONCAT() function, and MySQL chooses the string representation. If you specify a value of 2, for example, then the values 1.008 and 1.009 will be rounded to 1.01, and will checksum as equal.
192
+ attr_accessor :float_precision # (No value)
193
+
194
+ #
195
+ # default: yes
196
+ # Enable foreign key checks (SET FOREIGN_KEY_CHECKS=1).
197
+ # Specifying --no-foreign-key-checks will SET FOREIGN_KEY_CHECKS=0.
198
+ attr_accessor :foreign_key_checks # TRUE
199
+
200
+ #
201
+ # type: string
202
+ # Which hash function you'd like to use for checksums.
203
+ # The default is CRC32. Other good choices include MD5 and SHA1. If you have installed the FNV_64 user-defined function, mk-table-sync will detect it and prefer to use it, because it is much faster than the built-ins. You can also use MURMUR_HASH if you've installed that user-defined function. Both of these are distributed with Maatkit. See mk-table-checksum for more information and benchmarks.
204
+ attr_accessor :function # (No value)
205
+
206
+ #
207
+ # Show help and exit.
208
+ attr_accessor :help # TRUE
209
+
210
+ #
211
+ # default: yes
212
+ # HEX() BLOB, TEXT and BINARY columns.
213
+ # When row data from the source is fetched to create queries to sync the data (i.e. the queries seen with --print and executed by --execute), binary columns are wrapped in HEX() so the binary data does not produce an invalid SQL statement. You can disable this option but you probably shouldn't.
214
+ attr_accessor :hex_blob # TRUE
215
+
216
+ #
217
+ # short form: -h; type: string
218
+ # Connect to host.
219
+ attr_accessor :host # (No value)
220
+
221
+ #
222
+ # type: Hash
223
+ # Ignore this comma-separated list of column names in comparisons.
224
+ # This option causes columns not to be compared. However, if a row is determined to differ between tables, all columns in that row will be synced, regardless. (It is not currently possible to exclude columns from the sync process itself, only from the comparison.)
225
+ attr_accessor :ignore_columns #
226
+
227
+ #
228
+ # type: Hash
229
+ # Ignore this comma-separated list of databases.
230
+ attr_accessor :ignore_databases #
231
+
232
+ #
233
+ # type: Hash; default: FEDERATED,MRG_MyISAM
234
+ # Ignore this comma-separated list of storage engines.
235
+ attr_accessor :ignore_engines # FEDERATED,MRG_MyISAM
236
+
237
+ #
238
+ # type: Hash
239
+ # Ignore this comma-separated list of tables.
240
+ # Table names may be qualified with the database name.
241
+ attr_accessor :ignore_tables #
242
+
243
+ #
244
+ # default: yes
245
+ # Add FORCE/USE INDEX hints to the chunk and row queries.
246
+ # By default mk-table-sync adds a FORCE/USE INDEX hint to each SQL statement to coerce MySQL into using the index chosen by the sync algorithm or specified by --chunk-index. This is usually a good thing, but in rare cases the index may not be the best for the query so you can suppress the index hint by specifying --no-index-hint and let MySQL choose the index.
247
+ # This does not affect the queries printed by --print; it only affects the chunk and row queries that mk-table-sync uses to select and compare rows.
248
+ attr_accessor :index_hint # TRUE
249
+
250
+ #
251
+ # type: int
252
+ # Lock tables: 0=none, 1=per sync cycle, 2=per table, or 3=globally.
253
+ # This uses LOCK TABLES. This can help prevent tables being changed while you're examining them. The possible values are as follows:
254
+ #VALUE MEANING
255
+ #===== =======================================================
256
+ #0 #Never lock tables.
257
+ #1 #Lock and unlock one time per sync cycle (as implemented
258
+ # # by the syncing algorithm). This is the most granular
259
+ # # level of locking available. For example, the Chunk
260
+ # # algorithm will lock each chunk of C<N> rows, and then
261
+ # # unlock them if they are the same on the source and the
262
+ # # destination, before moving on to the next chunk.
263
+ #2 #Lock and unlock before and after each table.
264
+ #3 #Lock and unlock once for every server (DSN) synced, with
265
+ # # C<FLUSH TABLES WITH READ LOCK>.
266
+ # A replication slave is never locked if --replicate or --sync-to-master is specified, since in theory locking the table on the master should prevent any changes from taking place. (You are not changing data on your slave, right?) If --wait is given, the master (source) is locked and then the tool waits for the slave to catch up to the master before continuing.
267
+ # If --transaction is specified, LOCK TABLES is not used. Instead, lock and unlock are implemented by beginning and committing transactions. The exception is if --lock is 3.
268
+ # If --no-transaction is specified, then LOCK TABLES is used for any value of --lock. See --[no]transaction.
269
+ attr_accessor :lock # (No value)
270
+
271
+ #
272
+ # Lock the source and destination table, sync, then swap names. This is useful as a less-blocking ALTER TABLE, once the tables are reasonably in sync with each other (which you may choose to accomplish via any number of means, including dump and reload or even something like mk-archiver). It requires exactly two DSNs and assumes they are on the same server, so it does no waiting for replication or the like. Tables are locked with LOCK TABLES.
273
+ attr_accessor :lock_and_rename # FALSE
274
+
275
+ #
276
+ # short form: -p; type: string
277
+ # Password to use when connecting.
278
+ attr_accessor :password # (No value)
279
+
280
+ #
281
+ # type: string
282
+ # Create the given PID file. The file contains the process ID of the script. The PID file is removed when the script exits. Before starting, the script checks if the PID file already exists. If it does not, then the script creates and writes its own PID to it. If it does, then the script checks the following: if the file contains a PID and a process is running with that PID, then the script dies; or, if there is no process running with that PID, then the script overwrites the file with its own PID and starts; else, if the file contains no PID, then the script dies.
283
+ attr_accessor :pid # (No value)
284
+
285
+ #
286
+ # short form: -P; type: int
287
+ # Port number to use for connection.
288
+ attr_accessor :port # (No value)
289
+
290
+ #
291
+ # Print queries that will resolve differences.
292
+ # If you don't trust mk-table-sync, or just want to see what it will do, this is a good way to be safe. These queries are valid SQL and you can run them yourself if you want to sync the tables manually.
293
+ attr_accessor :print # FALSE
294
+
295
+ #
296
+ # type: string
297
+ # Preferred recursion method used to find slaves.
298
+ # Possible methods are:
299
+ #METHOD # USES
300
+ #=========== ================
301
+ #processlist SHOW PROCESSLIST
302
+ #hosts # SHOW SLAVE HOSTS
303
+ # The processlist method is preferred because SHOW SLAVE HOSTS is not reliable. However, the hosts method is required if the server uses a non-standard port (not 3306). Usually mk-table-sync does the right thing and finds the slaves, but you may give a preferred method and it will be used first. If it doesn't find any slaves, the other methods will be tried.
304
+ attr_accessor :recursion_method # (No value)
305
+
306
+ #
307
+ # Write all INSERT and UPDATE statements as REPLACE.
308
+ # This is automatically switched on as needed when there are unique index violations.
309
+ attr_accessor :replace # FALSE
310
+
311
+ #
312
+ # type: string
313
+ # Sync tables listed as different in this table.
314
+ # Specifies that mk-table-sync should examine the specified table to find data that differs. The table is exactly the same as the argument of the same name to mk-table-checksum. That is, it contains records of which tables (and ranges of values) differ between the master and slave.
315
+ # For each table and range of values that shows differences between the master and slave, mk-table-checksum will sync that table, with the appropriate WHERE clause, to its master.
316
+ # This automatically sets --wait to 60 and causes changes to be made on the master instead of the slave.
317
+ # If --sync-to-master is specified, the tool will assume the server you specified is the slave, and connect to the master as usual to sync.
318
+ # Otherwise, it will try to use SHOW PROCESSLIST to find slaves of the server you specified. If it is unable to find any slaves via SHOW PROCESSLIST, it will inspect SHOW SLAVE HOSTS instead. You must configure each slave's report-host, report-port and other options for this to work right. After finding slaves, it will inspect the specified table on each slave to find data that needs to be synced, and sync it.
319
+ # The tool examines the master's copy of the table first, assuming that the master is potentially a slave as well. Any table that shows differences there will NOT be synced on the slave(s). For example, suppose your replication is set up as A->B, B->C, B->D. Suppose you use this argument and specify server B. The tool will examine server B's copy of the table. If it looks like server B's data in table test.tbl1 is different from server A's copy, the tool will not sync that table on servers C and D.
320
+ attr_accessor :replicate # (No value)
321
+
322
+ #
323
+ # type: string; default: wait_timeout=10000
324
+ # Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed.
325
+ attr_accessor :set_vars # wait_timeout=10000
326
+
327
+ #
328
+ # short form: -S; type: string
329
+ # Socket file to use for connection.
330
+ attr_accessor :socket # (No value)
331
+
332
+ #
333
+ # Treat the DSN as a slave and sync it to its master.
334
+ # Treat the server you specified as a slave. Inspect SHOW SLAVE STATUS, connect to the server's master, and treat the master as the source and the slave as the destination. Causes changes to be made on the master. Sets --wait to 60 by default, sets --lock to 1 by default, and disables --[no]transaction by default. See also --replicate, which changes this option's behavior.
335
+ attr_accessor :sync_to_master # FALSE
336
+
337
+ #
338
+ # short form: -t; type: hash
339
+ # Sync only this comma-separated list of tables.
340
+ # Table names may be qualified with the database name.
341
+ attr_accessor :tables # (No value)
342
+
343
+ #
344
+ # Keep going if --wait fails.
345
+ # If you specify --wait and the slave doesn't catch up to the master's position before the wait times out, the default behavior is to abort. This option makes the tool keep going anyway. Warning: if you are trying to get a consistent comparison between the two servers, you probably don't want to keep going after a timeout.
346
+ attr_accessor :timeout_ok # FALSE
347
+
348
+ #
349
+ # Use transactions instead of LOCK TABLES.
350
+ # The granularity of beginning and committing transactions is controlled by --lock. This is enabled by default, but since --lock is disabled by default, it has no effect.
351
+ # Most options that enable locking also disable transactions by default, so if you want to use transactional locking (via LOCK IN SHARE MODE and FOR UPDATE, you must specify --transaction explicitly.
352
+ # If you don't specify --transaction explicitly mk-table-sync will decide on a per-table basis whether to use transactions or table locks. It currently uses transactions on InnoDB tables, and table locks on all others.
353
+ # If --no-transaction is specified, then mk-table-sync will not use transactions at all (not even for InnoDB tables) and locking is controlled by --lock.
354
+ # When enabled, either explicitly or implicitly, the transaction isolation level is set REPEATABLE READ and transactions are started WITH CONSISTENT SNAPSHOT.
355
+ attr_accessor :transaction # FALSE
356
+
357
+ #
358
+ # TRIM() VARCHAR columns in BIT_XOR and ACCUM modes. Helps when comparing MySQL 4.1 to >= 5.0.
359
+ # This is useful when you don't care about the trailing space differences between MySQL versions which vary in their handling of trailing spaces. MySQL 5.0 and later all retain trailing spaces in VARCHAR, while previous versions would remove them.
360
+ attr_accessor :trim # FALSE
361
+
362
+ #
363
+ # default: yes
364
+ # Enable unique key checks (SET UNIQUE_CHECKS=1).
365
+ # Specifying --no-unique-checks will SET UNIQUE_CHECKS=0.
366
+ attr_accessor :unique_checks # TRUE
367
+
368
+ #
369
+ # short form: -u; type: string
370
+ # User for login if not current user.
371
+ attr_accessor :user # (No value)
372
+
373
+ #
374
+ # short form: -v; cumulative: yes
375
+ # Print results of sync operations.
376
+ # See OUTPUT for more details about the output.
377
+ attr_accessor :verbose # 0
378
+
379
+ #
380
+ # Show version and exit.
381
+ attr_accessor :version # FALSE
382
+
383
+ #
384
+ # short form: -w; type: time
385
+ # How long to wait for slaves to catch up to their master.
386
+ # Make the master wait for the slave to catch up in replication before comparing the tables. The value is the number of seconds to wait before timing out (see also --timeout-ok). Sets --lock to 1 and --[no]transaction to 0 by default. If you see an error such as the following,
387
+ #MASTER_POS_WAIT returned -1
388
+ # It means the timeout was exceeded and you need to increase it.
389
+ # The default value of this option is influenced by other options. To see what value is in effect, run with --help.
390
+ # To disable waiting entirely (except for locks), specify --wait 0. This helps when the slave is lagging on tables that are not being synced.
391
+ attr_accessor :wait # (No value)
392
+
393
+ #
394
+ # type: string
395
+ # WHERE clause to restrict syncing to part of the table.
396
+ attr_accessor :where # (No value)
397
+
398
+ #
399
+ # default: yes
400
+ # Add a chunk for rows with zero or zero-equivalent values. The only has an effect when --chunk-size is specified. The purpose of the zero chunk is to capture a potentially large number of zero values that would imbalance the size of the first chunk. For example, if a lot of negative numbers were inserted into an unsigned integer column causing them to be stored as zeros, then these zero values are captured by the zero chunk instead of the first chunk and all its non-zero values.
401
+ attr_accessor :zero_chunk # TRUE
402
+
403
+ #
404
+ # Sets the executable path, otherwise the environment path will be used.
405
+ #
406
+ attr_accessor :path_to_mk_table_sync
407
+
408
+ #
409
+ # Returns a new TableSync Object
410
+ #
411
+ def initialize()
412
+ end
413
+
414
+ #
415
+ # Execute the command
416
+ #
417
+ def start(options = nil)
418
+ tmp = Tempfile.new('tmp')
419
+ command = option_string() + options.to_s + " 2> " + tmp.path
420
+ success = system(command)
421
+ if success
422
+ begin
423
+ while (line = tmp.readline)
424
+ line.chomp
425
+ selected_string = line
426
+ end
427
+ rescue EOFError
428
+ tmp.close
429
+ end
430
+ return selected_string
431
+ else
432
+ tmp.close!
433
+ return success
434
+ end
435
+ end
436
+
437
+ def config
438
+ option_string()
439
+ end
440
+
441
+ private
442
+
443
+ def option_string()
444
+
445
+ unless @path_to_mk_table_sync
446
+ ostring = "mk-table-sync "
447
+ else
448
+ ostring = @path_to_mk_table_sync + " "
449
+ end
450
+
451
+ self.instance_variables.each do |i|
452
+ tmp_value = self.instance_variable_get "#{i}"
453
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
454
+ unless tmp_string == "--path-to-mk-table-sync"
455
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
456
+ ostring += "#{tmp_string} "
457
+ else
458
+ ostring += "#{tmp_string} #{tmp_value} "
459
+ end
460
+ end
461
+ end
462
+
463
+ return ostring
464
+
465
+ end
466
+
467
+ end
468
+