Class: DumpCleaner::Cleaners::MysqlShellTableCleaner

Inherits:
BaseCleaner
  • Object
show all
Includes:
MysqlShellDumpHelpers
Defined in:
lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb

Defined Under Namespace

Classes: DumpTableInfo

Instance Attribute Summary collapse

Attributes inherited from BaseCleaner

#config, #options

Instance Method Summary collapse

Methods included from MysqlShellDumpHelpers

#destination_file_for

Methods inherited from BaseCleaner

#keep_same_record?, #post_cleanup

Constructor Details

#initialize(db:, table:, config:, options:) ⇒ MysqlShellTableCleaner

Returns a new instance of MysqlShellTableCleaner.



12
13
14
15
16
17
18
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 12

def initialize(db:, table:, config:, options:)
  super(config:, options:)
  @db = db
  @table = table
  @cleanup_data = Cleanup::DataSource.new(config:)
  @cleaning = Cleanup::Cleaning.new(config:)
end

Instance Attribute Details

#cleaningObject (readonly)

Returns the value of attribute cleaning.



10
11
12
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 10

def cleaning
  @cleaning
end

#cleanup_dataObject (readonly)

Returns the value of attribute cleanup_data.



10
11
12
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 10

def cleanup_data
  @cleanup_data
end

#table_infoObject (readonly)

Returns the value of attribute table_info.



10
11
12
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 10

def table_info
  @table_info
end

Instance Method Details

#cleanObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 25

def clean
  table_config = config.cleanup_table_config(db: @db, table: @table)
  Log.info { "Cleaning table #{table_info.db_dot_table}" }

  DumpCleaner::Cleanup::Uniqueness::CaseInsensitiveCache.instance.clear

  Dir.glob("#{options.source_dump_path}/#{table_info.db_at_table}@@*.#{table_info.extension}").each do |file|
    # Open3.pipeline_r(pipe_source_args(file), ["head", "-n", "1000"]) do |tsv_data, _wait_thread|
    Open3.pipeline_r(pipe_source_args(file)) do |tsv_data, _wait_thread|
      Open3.pipeline_w(pipe_sink_args(destination_file_for(file))) do |zstd_out, _wait_thread|
        tsv_data.each_line do |line|
          line = line.chomp(table_info.dialect.lines_terminated_by)
          zstd_out.print "#{clean_line(line, table_config:)}#{table_info.dialect.lines_terminated_by}"
        end
      end
    end
  end
end

#pre_cleanupObject



20
21
22
23
# File 'lib/dump_cleaner/cleaners/mysql_shell_table_cleaner.rb', line 20

def pre_cleanup
  @table_info = DumpTableInfo.load(db: @db, table: @table, source_dump_path: options.source_dump_path)
  validate_table_info
end