Class: Flydata::Command::Sync
- Includes:
- Helpers
- Defined in:
- lib/flydata/command/sync.rb
Direct Known Subclasses
Defined Under Namespace
Classes: SyncDataEntryError
Constant Summary collapse
- INSERT_PROGRESS_INTERVAL =
1000
- SERVER_DATA_PROCESSING_TIMEOUT =
seconds
3600
- STATUS_PARSING =
for dump.pos file
'PARSING'
- STATUS_WAITING =
'WAITING'
- STATUS_COMPLETE =
'COMPLETE'
Constants included from Helpers
Instance Attribute Summary collapse
-
#ddl_tables ⇒ Object
readonly
true if full initial sync.
-
#full_initial_sync ⇒ Object
readonly
true if full initial sync.
-
#full_tables ⇒ Object
readonly
true if full initial sync.
-
#input_tables ⇒ Object
readonly
true if full initial sync.
-
#new_tables ⇒ Object
readonly
true if full initial sync.
Attributes inherited from Base
Class Method Summary collapse
-
.slop ⇒ Object
Command: flydata sync - Arguments.
-
.slop_fix_binlogpos ⇒ Object
Command: flydata sync:fix_binlogpos - Arguments.
-
.slop_flush ⇒ Object
Command: flydata sync:flush - Arguments.
-
.slop_generate_table_ddl ⇒ Object
Command: flydata sync:generate_table_ddl - Arguments.
-
.slop_reset ⇒ Object
Command: flydata sync:reset - Arguments.
Instance Method Summary collapse
-
#fix_binlogpos ⇒ Object
Command: flydata sync:fix_binlogpos Set binlog path - Entry method.
-
#flush(*tables) ⇒ Object
Command: flydata sync:flush - Entry method.
-
#generate_table_ddl(*tables) ⇒ Object
Command: flydata sync:generate_table_ddl - Entry method.
-
#reset(*tables) ⇒ Object
Command: flydata sync:reset - Entry method.
-
#run(*tables) ⇒ Object
Command: flydata sync - Entry method.
-
#skip ⇒ Object
Depricated Command: flydata sync:skip skip initial sync.
-
#try_mysql_sync ⇒ Object
Public method - Called from Sender#start/restart.
Methods included from Helpers
as_size, development?, env_mode, env_suffix, flydata_api_host_file, flydata_conf_file, flydata_version, format_menu_list, retry_on, to_command_class, usage_text
Methods inherited from Base
#ask_input_table_name, #ask_yes_no, #choose_one, #flydata, #initialize, #newline, #register_crontab, #retrieve_data_entries, #separator, #show_purpose_name
Methods included from Flydata::CommandLoggable
#before_logging, #log_error_stderr, #log_info_stdout, #log_warn_stderr
Constructor Details
This class inherits a constructor from Flydata::Command::Base
Instance Attribute Details
#ddl_tables ⇒ Object (readonly)
true if full initial sync
34 35 36 |
# File 'lib/flydata/command/sync.rb', line 34 def ddl_tables @ddl_tables end |
#full_initial_sync ⇒ Object (readonly)
true if full initial sync
34 35 36 |
# File 'lib/flydata/command/sync.rb', line 34 def full_initial_sync @full_initial_sync end |
#full_tables ⇒ Object (readonly)
true if full initial sync
34 35 36 |
# File 'lib/flydata/command/sync.rb', line 34 def full_tables @full_tables end |
#input_tables ⇒ Object (readonly)
true if full initial sync
34 35 36 |
# File 'lib/flydata/command/sync.rb', line 34 def input_tables @input_tables end |
#new_tables ⇒ Object (readonly)
true if full initial sync
34 35 36 |
# File 'lib/flydata/command/sync.rb', line 34 def new_tables @new_tables end |
Class Method Details
.slop ⇒ Object
Command: flydata sync
- Arguments
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/flydata/command/sync.rb', line 48 def self.slop Slop.new do on 'c', 'skip-cleanup', 'Skip server cleanup' on 'f', 'skip-flush', 'Skip server flush' on 'y', 'yes', 'Skip command prompt assuming yes to all questions. Use this for batch operation.' on 'd', 'dump-file', 'Dump mysqldump into a file. Use this for debugging after making sure the free space.' # dummy for compatibility on 's', 'dump-stream', 'Dump mysqldump stream instead of saving dump file. It might cause timeout error if db size is larger than 10GB.' on 'n', 'no-flydata-start', 'Don\'t start the flydata agent after initial sync.' #TODO : This option is temp! Should remove soon. on 'ff', 'Skip checking query queue and flush' end end |
.slop_fix_binlogpos ⇒ Object
Command: flydata sync:fix_binlogpos
- Arguments
237 238 239 240 241 |
# File 'lib/flydata/command/sync.rb', line 237 def self.slop_fix_binlogpos Slop.new do on 'f', 'force', 'update sent binlog position file forcibly' end end |
.slop_flush ⇒ Object
Command: flydata sync:flush
- Arguments
105 106 107 108 109 110 |
# File 'lib/flydata/command/sync.rb', line 105 def self.slop_flush Slop.new do on 'f', 'skip-flush', 'Skip server flush' on 'y', 'yes', 'Skip command prompt assuming yes to all questions. Use this for batch operation.' end end |
.slop_generate_table_ddl ⇒ Object
Command: flydata sync:generate_table_ddl
- Arguments
212 213 214 215 216 217 218 219 |
# File 'lib/flydata/command/sync.rb', line 212 def self.slop_generate_table_ddl Slop.new do on 'c', 'ctl-only', 'Only generate FlyData Control definitions' on 'y', 'yes', 'Skip command prompt assuming yes to all questions. Use this for batch operation.' on 's', 'skip-primary-key-check', 'Skip primary key check when generating DDL' on 'all-tables', 'Generate all table schema' end end |
.slop_reset ⇒ Object
Command: flydata sync:reset
- Arguments
131 132 133 134 135 136 |
# File 'lib/flydata/command/sync.rb', line 131 def self.slop_reset Slop.new do on 'c', 'client', 'Resets client only.' on 'y', 'yes', 'Skip command prompt assuming yes to all questions. Use this for batch operation.' end end |
Instance Method Details
#fix_binlogpos ⇒ Object
Command: flydata sync:fix_binlogpos Set binlog path
- Entry method
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/flydata/command/sync.rb', line 246 def fix_binlogpos de = data_entry sync_fm = create_sync_file_manager(de) if File.exists?(sync_fm.sent_binlog_path) && !opts.force? log_info_stdout("Skip creating sent binlogpos because sent position file is exist already. (#{sync_fm.sent_binlog_path})") return end if Flydata::Command::Sender.new.process_exist? log_warn_stderr("flydata is running. flydata process needs to be stopped with 'flydata stop'.") return end binlog_info = sync_fm.load_binlog if binlog_info.nil? log_info_stdout("Skip creating sent binlogpos because binlog position file is empty or invalid. (#{sync_fm.sent_binlog_path})") return end say("Updating binlog position files...") log_info("Updating binlog position files... Original binlog_info:#{binlog_info}") # Update binlog.sent.pos file # -1 is because the position in binlog.pos is the next event's position. # on the other hand the position in sent position indicates already processed. binlog_info[:pos] -= 1 log_info("Updating sent position file. #{binlog_info} -> #{sync_fm.sent_binlog_path}") sync_fm.save_sent_binlog(binlog_info) # Update binlog.pos file to start from head of the current binlog file new_binlog_info = binlog_info.dup.tap{|h| h[:pos] = 4} # 4 is the first position of binlog file. log_info("Updating original position file. #{new_binlog_info} -> #{sync_fm.binlog_path}") sync_fm.save_binlog(new_binlog_info) log_info_stdout("Done!") end |
#flush(*tables) ⇒ Object
Command: flydata sync:flush
- Entry method
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/flydata/command/sync.rb', line 114 def flush(*tables) begin flush_buffer_and_stop(tables) rescue ServerDataProcessingTimeout => e ee = ServerDataProcessingTimeout.new("Delayed Data Processing") ee.description = <<EOS Data processing is taking more than expected. Please contact [email protected] to check the system status. EOS ee.set_backtrace e.backtrace raise ee end log_info_stdout("Buffers have been flushed and the sender process has been stopped.") end |
#generate_table_ddl(*tables) ⇒ Object
Command: flydata sync:generate_table_ddl
- Entry method
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/flydata/command/sync.rb', line 223 def generate_table_ddl(*tables) # Compatibility check de = data_entry dp = flydata.data_port.get Flydata::MysqlCompatibilityCheck.new(dp, de['mysql_data_entry_preference']).check # Set instance variables set_current_tables(tables, include_invalid_tables: true) do_generate_table_ddl(de) end |
#reset(*tables) ⇒ Object
Command: flydata sync:reset
- Entry method
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/flydata/command/sync.rb', line 140 def reset(*tables) show_purpose_name # Flush client buffer msg = tables.empty? ? '' : " for these tables : #{tables.join(" ")}" return unless ask_yes_no("This resets the current sync#{msg}. Are you sure?") sender = Flydata::Command::Sender.new sender.flush_client_buffer # TODO We should rather delete buffer files sender.stop # Set instance variables de = data_entry set_current_tables(tables) begin wait_for_server_buffer(timeout: SERVER_DATA_PROCESSING_TIMEOUT, tables: target_tables_for_api) rescue ServerDataProcessingTimeout => e ee = ServerDataProcessingTimeout.new("Delayed Data Processing") ee.description = <<EOS Data processing is taking more than expected. Please contact [email protected] to check the system status. Once checked, you can continue sync reset with the following command flydata sync:reset #{tables.empty? ? '' : tables.join(" ")} EOS ee.set_backtrace e.backtrace raise ee end # Cleanup tables on server cleanup_sync_server(de, @input_tables) unless opts.client? # Delete local files sync_fm = create_sync_file_manager(de) delete_files = [ sync_fm.dump_file_path, sync_fm.dump_pos_path, sync_fm.mysql_table_marshal_dump_path, sync_fm.sync_info_file, sync_fm.stats_path, sync_fm.table_position_file_paths(*@input_tables), sync_fm.table_binlog_pos_paths(*@input_tables), sync_fm.table_binlog_pos_init_paths(*@input_tables), sync_fm.table_rev_file_paths(*@input_tables), sync_fm.table_ddl_file_paths(*@input_tables) ] new_tables_after_reset = @new_tables + @input_tables if @input_tables.empty? or @full_tables.empty? or @full_tables.all?{|ft| new_tables_after_reset.include?(ft)} delete_files << sync_fm.binlog_path delete_files << sync_fm.sent_binlog_path end delete_files.flatten.each do |path| FileUtils.rm(path) if File.exists?(path) end sync_fm.close log_info_stdout("Reset completed successfully.") end |
#run(*tables) ⇒ Object
Command: flydata sync
- Entry method
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/flydata/command/sync.rb', line 63 def run(*tables) # Process check sender = Flydata::Command::Sender.new if (sender.process_exist?) if tables.empty? # full sync log_warn_stderr("FlyData Agent is already running. If you'd like to restart FlyData Sync from scratch, run 'flydata sync:reset' first.") else # per-table sync log_warn_stderr("Flydata Agent is already running. If you'd like to Sync the table(s), run 'flydata sync:flush' first.") end exit 1 end # Start initial sync with check handle_mysql_sync(tables) # Start continuous sync by starting fluentd process unless opts.no_flydata_start? log_info_stdout("Starting FlyData Agent...") Flydata::Command::Sender.new.start(quiet: true) log_info_stdout(" -> Done") end # Show message dashboard_url = "#{flydata.flydata_api_host}/dashboard" redshift_console_url = "#{flydata.flydata_api_host}/redshift_clusters/query/new" = ALL_DONE_MESSAGE_TEMPLATE % [redshift_console_url, dashboard_url] log_info_stdout() end |
#skip ⇒ Object
Depricated Command: flydata sync:skip skip initial sync
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/flydata/command/sync.rb', line 199 def skip de = data_entry sync_fm = create_sync_file_manager(de) binlog_path = sync_fm.binlog_path sync_fm.close `touch #{binlog_path}` log_info_stdout("Created an empty binlog position file.") log_info_stdout("-> #{binlog_path}") log_info_stdout("Run 'flydata start' to start continuous sync.") end |
#try_mysql_sync ⇒ Object
Public method
- Called from Sender#start/restart
96 97 98 99 100 101 |
# File 'lib/flydata/command/sync.rb', line 96 def try_mysql_sync # Start initial sync handle_mysql_sync rescue SyncDataEntryError return end |