taps 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +0 -1
- data/VERSION.yml +1 -1
- data/lib/taps/cli.rb +5 -0
- data/lib/taps/client_session.rb +42 -18
- data/lib/taps/server.rb +2 -1
- data/lib/taps/utils.rb +19 -6
- data/spec/client_session_spec.rb +1 -1
- data/spec/utils_spec.rb +4 -0
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -27,7 +27,6 @@ or when you want to push a local database to a taps server
|
|
27
27
|
* Blob data may not transfer properly, I suspect that SQLite3 is modifying some native ruby objects.
|
28
28
|
* Foreign Keys get lost in the schema transfer
|
29
29
|
* Large tables (>1 million rows with a large number of columns) get slower as the offset gets larger. This is due to it being inefficient having large offset values in queries.
|
30
|
-
* Character encoding problems should be more transparent but they're not, it usually involves looking at the server log to see the error.
|
31
30
|
|
32
31
|
== Meta
|
33
32
|
|
data/VERSION.yml
CHANGED
data/lib/taps/cli.rb
CHANGED
@@ -36,6 +36,11 @@ class Cli < Thor
|
|
36
36
|
clientxfer(:cmd_send, database_url, remote_url)
|
37
37
|
end
|
38
38
|
|
39
|
+
desc "version", "Taps version"
|
40
|
+
def version
|
41
|
+
puts Taps.version
|
42
|
+
end
|
43
|
+
|
39
44
|
def clientxfer(method, database_url, remote_url)
|
40
45
|
if options[:chunksize]
|
41
46
|
Taps::Config.chunksize = options[:chunksize] < 100 ? 100 : options[:chunksize]
|
data/lib/taps/client_session.rb
CHANGED
@@ -70,11 +70,21 @@ class ClientSession
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def cmd_send
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
begin
|
74
|
+
verify_server
|
75
|
+
cmd_send_schema
|
76
|
+
cmd_send_data
|
77
|
+
cmd_send_indexes
|
78
|
+
cmd_send_reset_sequences
|
79
|
+
rescue RestClient::Exception => e
|
80
|
+
if e.respond_to?(:response)
|
81
|
+
puts "!!! Caught Server Exception"
|
82
|
+
puts "#{e.response.body}"
|
83
|
+
exit(1)
|
84
|
+
else
|
85
|
+
raise
|
86
|
+
end
|
87
|
+
end
|
78
88
|
end
|
79
89
|
|
80
90
|
def cmd_send_indexes
|
@@ -116,12 +126,14 @@ class ClientSession
|
|
116
126
|
|
117
127
|
offset = 0
|
118
128
|
loop do
|
119
|
-
|
120
|
-
|
129
|
+
row_size = 0
|
130
|
+
chunksize = Taps::Utils.calculate_chunksize(chunksize) do |c|
|
131
|
+
rows = Taps::Utils.format_data(table.order(order).limit(c, offset).all)
|
132
|
+
break if rows == { }
|
121
133
|
|
122
|
-
|
134
|
+
row_size = rows[:data].size
|
135
|
+
gzip_data = Taps::Utils.gzip(Marshal.dump(rows))
|
123
136
|
|
124
|
-
chunksize = Taps::Utils.calculate_chunksize(chunksize) do
|
125
137
|
begin
|
126
138
|
session_resource["tables/#{table_name}"].post(gzip_data, http_headers({
|
127
139
|
:content_type => 'application/octet-stream',
|
@@ -135,8 +147,10 @@ class ClientSession
|
|
135
147
|
end
|
136
148
|
end
|
137
149
|
|
138
|
-
progress.inc(
|
139
|
-
offset +=
|
150
|
+
progress.inc(row_size)
|
151
|
+
offset += row_size
|
152
|
+
|
153
|
+
break if row_size == 0
|
140
154
|
end
|
141
155
|
|
142
156
|
progress.finish
|
@@ -156,11 +170,21 @@ class ClientSession
|
|
156
170
|
end
|
157
171
|
|
158
172
|
def cmd_receive
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
173
|
+
begin
|
174
|
+
verify_server
|
175
|
+
cmd_receive_schema
|
176
|
+
cmd_receive_data
|
177
|
+
cmd_receive_indexes
|
178
|
+
cmd_reset_sequences
|
179
|
+
rescue RestClient::Exception => e
|
180
|
+
if e.respond_to?(:response)
|
181
|
+
puts "!!! Caught Server Exception"
|
182
|
+
puts "#{e.response.body}"
|
183
|
+
exit(1)
|
184
|
+
else
|
185
|
+
raise
|
186
|
+
end
|
187
|
+
end
|
164
188
|
end
|
165
189
|
|
166
190
|
def cmd_receive_data
|
@@ -199,8 +223,8 @@ class ClientSession
|
|
199
223
|
|
200
224
|
def fetch_table_rows(table_name, chunksize, offset)
|
201
225
|
response = nil
|
202
|
-
chunksize = Taps::Utils.calculate_chunksize(chunksize) do
|
203
|
-
response = session_resource["tables/#{table_name}/#{
|
226
|
+
chunksize = Taps::Utils.calculate_chunksize(chunksize) do |c|
|
227
|
+
response = session_resource["tables/#{table_name}/#{c}?offset=#{offset}"].get(http_headers)
|
204
228
|
end
|
205
229
|
raise CorruptedData unless Taps::Utils.valid_data?(response.to_s, response.headers[:taps_checksum])
|
206
230
|
|
data/lib/taps/server.rb
CHANGED
data/lib/taps/utils.rb
CHANGED
@@ -41,19 +41,32 @@ module Utils
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def calculate_chunksize(old_chunksize)
|
44
|
-
|
45
|
-
|
44
|
+
chunksize = old_chunksize
|
45
|
+
|
46
|
+
retries = 0
|
47
|
+
begin
|
48
|
+
t1 = Time.now
|
49
|
+
yield chunksize
|
50
|
+
rescue Errno::EPIPE
|
51
|
+
retries += 1
|
52
|
+
raise if retries > 1
|
53
|
+
# we got disconnected, the chunksize could be too large
|
54
|
+
# so we're resetting to a very small value
|
55
|
+
chunksize = 100
|
56
|
+
retry
|
57
|
+
end
|
58
|
+
|
46
59
|
t2 = Time.now
|
47
60
|
|
48
61
|
diff = t2 - t1
|
49
62
|
new_chunksize = if diff > 3.0
|
50
|
-
(
|
63
|
+
(chunksize / 3).ceil
|
51
64
|
elsif diff > 1.1
|
52
|
-
|
65
|
+
chunksize - 100
|
53
66
|
elsif diff < 0.8
|
54
|
-
|
67
|
+
chunksize * 2
|
55
68
|
else
|
56
|
-
|
69
|
+
chunksize + 100
|
57
70
|
end
|
58
71
|
new_chunksize = 100 if new_chunksize < 100
|
59
72
|
new_chunksize
|
data/spec/client_session_spec.rb
CHANGED
@@ -69,7 +69,7 @@ describe Taps::ClientSession do
|
|
69
69
|
it "fetches table rows given a chunksize and offset from taps server" do
|
70
70
|
@data = { :header => [ :x, :y ], :data => [ [1, 2], [3, 4] ] }
|
71
71
|
@gzip_data = Taps::Utils.gzip(Marshal.dump(@data))
|
72
|
-
Taps::Utils.stubs(:calculate_chunksize).with(1000).yields.returns(1000)
|
72
|
+
Taps::Utils.stubs(:calculate_chunksize).with(1000).yields(1000).returns(1000)
|
73
73
|
|
74
74
|
@response = mock('response')
|
75
75
|
@client.session_resource.stubs(:[]).with('tables/mytable/1000?offset=0').returns(mock('table resource'))
|
data/spec/utils_spec.rb
CHANGED
@@ -41,5 +41,9 @@ describe Taps::Utils do
|
|
41
41
|
Time.stubs(:now).returns(10.0).returns(11.1)
|
42
42
|
Taps::Utils.calculate_chunksize(1000) { }.should == 1100
|
43
43
|
end
|
44
|
+
|
45
|
+
it "will reset the chunksize to a small value if we got a broken pipe exception" do
|
46
|
+
Taps::Utils.calculate_chunksize(1000) { |c| raise Errno::EPIPE if c == 1000; c.should == 100 }.should == 200
|
47
|
+
end
|
44
48
|
end
|
45
49
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Chimal, Jr.
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-03-
|
13
|
+
date: 2009-03-23 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -85,18 +85,18 @@ extra_rdoc_files: []
|
|
85
85
|
files:
|
86
86
|
- spec/base.rb
|
87
87
|
- spec/schema_spec.rb
|
88
|
-
- spec/utils_spec.rb
|
89
|
-
- spec/client_session_spec.rb
|
90
88
|
- spec/server_spec.rb
|
89
|
+
- spec/client_session_spec.rb
|
90
|
+
- spec/utils_spec.rb
|
91
91
|
- lib/taps/db_session.rb
|
92
92
|
- lib/taps/progress_bar.rb
|
93
|
-
- lib/taps/
|
93
|
+
- lib/taps/client_session.rb
|
94
94
|
- lib/taps/adapter_hacks.rb
|
95
95
|
- lib/taps/adapter_hacks/invalid_text_limit.rb
|
96
96
|
- lib/taps/adapter_hacks/non_rails_schema_dump.rb
|
97
97
|
- lib/taps/schema.rb
|
98
98
|
- lib/taps/config.rb
|
99
|
-
- lib/taps/
|
99
|
+
- lib/taps/cli.rb
|
100
100
|
- lib/taps/server.rb
|
101
101
|
- lib/taps/utils.rb
|
102
102
|
- README.rdoc
|