-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathre_wald.rb
executable file
·35 lines (25 loc) · 1.01 KB
/
re_wald.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby
require 'pathname'
input = ARGV
raise "provide an output directory and number of files to combine as arguments" unless ARGV.length == 2
OUTPUT_DIR = Pathname.new(input[0])
MAX_FILES_TO_COMBINE = input[1].to_i
puts "Writing new .wal files to #{OUTPUT_DIR} with a batch size of #{MAX_FILES_TO_COMBINE}"
wal_file_number = 1
file_name_buffer = []
Dir.glob('*.wal').sort.each do |file|
puts "buf += #{file}"
file_name_buffer << file
next if file_name_buffer.length < MAX_FILES_TO_COMBINE
files_to_join = file_name_buffer.join(' ')
target_file = OUTPUT_DIR.join("#{sprintf("%016X", wal_file_number)}.wal")
puts "merge: #{files_to_join} target: #{target_file}"
`cat #{files_to_join} > #{target_file}`
file_name_buffer = []
wal_file_number += 1
end
exit(0) if file_name_buffer.length == 0
files_to_join = file_name_buffer.join(' ')
target_file = OUTPUT_DIR.join("#{sprintf("%016X", wal_file_number)}.wal")
puts "merge: #{files_to_join} target: #{target_file}"
`cat #{files_to_join} > #{target_file}`