Class: Sq::Dbsync::BatchLoadAction
Overview
Load action to reload an entire table in full. The table will be loaded in parallel to the existing one, then atomically swapped in on completion.
Constant Summary
collapse
- MAX_LAG =
60 * 5
Constants inherited
from LoadAction
LoadAction::EPOCH
Instance Method Summary
collapse
Methods inherited from LoadAction
#call, #do_prepare, #initialize, stages, #tag
Instance Method Details
22
23
24
25
26
|
# File 'lib/sq/dbsync/batch_load_action.rb', line 22
def
@start_time = now.call
@file, @last_row_at = measure(:extract) { (nil) }
self
end
|
#load_data ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/sq/dbsync/batch_load_action.rb', line 28
def load_data
measure(:load) do
TempfileFactory.split(@file, 1_000_000, logger) do |path|
db.load_from_file(
plan.prefixed_table_name,
plan.columns,
path
)
end
@file.close!
end
self
end
|
#operation ⇒ Object
9
|
# File 'lib/sq/dbsync/batch_load_action.rb', line 9
def operation; 'batch'; end
|
#post_load ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/sq/dbsync/batch_load_action.rb', line 42
def post_load
while @start_time <= now.call - MAX_LAG
@start_time = now.call
catchup
end
switch_tables
self
end
|
#prepare ⇒ Object
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/sq/dbsync/batch_load_action.rb', line 11
def prepare
return false if plan.batch_load == false
if super
if target.table_exists?(plan.prefixed_table_name)
target.drop_table(plan.prefixed_table_name)
end
true
end
end
|