mogilefs-client 2.2.0 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +11 -0
- data/.gemtest +0 -0
- data/.gitignore +4 -0
- data/.wrongdoc.yml +5 -0
- data/GIT-VERSION-GEN +28 -0
- data/GNUmakefile +44 -0
- data/HACKING +33 -0
- data/{History.txt → History} +0 -1
- data/{LICENSE.txt → LICENSE} +0 -1
- data/Manifest.txt +34 -7
- data/README +51 -0
- data/Rakefile +11 -11
- data/TODO +10 -0
- data/bin/mog +109 -68
- data/examples/mogstored_rack.rb +189 -0
- data/lib/mogilefs.rb +56 -17
- data/lib/mogilefs/admin.rb +128 -62
- data/lib/mogilefs/backend.rb +205 -95
- data/lib/mogilefs/bigfile.rb +54 -70
- data/lib/mogilefs/bigfile/filter.rb +58 -0
- data/lib/mogilefs/chunker.rb +30 -0
- data/lib/mogilefs/client.rb +0 -2
- data/lib/mogilefs/copy_stream.rb +30 -0
- data/lib/mogilefs/http_file.rb +175 -0
- data/lib/mogilefs/http_reader.rb +79 -0
- data/lib/mogilefs/mogilefs.rb +242 -148
- data/lib/mogilefs/mysql.rb +3 -4
- data/lib/mogilefs/paths_size.rb +24 -0
- data/lib/mogilefs/pool.rb +0 -1
- data/lib/mogilefs/socket.rb +9 -0
- data/lib/mogilefs/socket/kgio.rb +55 -0
- data/lib/mogilefs/socket/pure_ruby.rb +70 -0
- data/lib/mogilefs/socket_common.rb +58 -0
- data/lib/mogilefs/util.rb +6 -169
- data/test/aggregate.rb +11 -11
- data/test/exec.rb +72 -0
- data/test/fresh.rb +222 -0
- data/test/integration.rb +43 -0
- data/test/setup.rb +1 -0
- data/test/socket_test.rb +98 -0
- data/test/test_admin.rb +14 -37
- data/test/test_backend.rb +50 -107
- data/test/test_bigfile.rb +2 -2
- data/test/test_db_backend.rb +1 -2
- data/test/test_fresh.rb +8 -0
- data/test/test_http_reader.rb +34 -0
- data/test/test_mogilefs.rb +278 -98
- data/test/test_mogilefs_integration.rb +174 -0
- data/test/test_mogilefs_integration_large_pipe.rb +62 -0
- data/test/test_mogilefs_integration_list_keys.rb +40 -0
- data/test/test_mogilefs_socket_kgio.rb +11 -0
- data/test/test_mogilefs_socket_pure.rb +7 -0
- data/test/test_mogstored_rack.rb +89 -0
- data/test/test_mogtool_bigfile.rb +116 -0
- data/test/test_mysql.rb +1 -2
- data/test/test_pool.rb +1 -1
- data/test/test_unit_mogstored_rack.rb +72 -0
- metadata +76 -54
- data/README.txt +0 -80
- data/lib/mogilefs/httpfile.rb +0 -157
- data/lib/mogilefs/network.rb +0 -107
- data/test/test_network.rb +0 -56
- data/test/test_util.rb +0 -121
data/test/test_mysql.rb
CHANGED
data/test/test_pool.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
require "test/unit"
|
3
|
+
require "tmpdir"
|
4
|
+
require "fileutils"
|
5
|
+
begin
|
6
|
+
require "./examples/mogstored_rack"
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestUnitMogstoredRack < Test::Unit::TestCase
|
11
|
+
attr_reader :req
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@docroot = Dir.mktmpdir(["mogstored_rack", ".docroot"])
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_defaults
|
18
|
+
req = Rack::MockRequest.new(MogstoredRack.new(@docroot))
|
19
|
+
all_methods(req)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_fsync_true
|
23
|
+
req = Rack::MockRequest.new(MogstoredRack.new(@docroot, :fsync=>true))
|
24
|
+
all_methods(req)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_reread_verify
|
28
|
+
app = MogstoredRack.new(@docroot, :reread_verify=>true)
|
29
|
+
req = Rack::MockRequest.new(app)
|
30
|
+
all_methods(req)
|
31
|
+
end
|
32
|
+
|
33
|
+
def all_methods(req)
|
34
|
+
assert_equal 200, req.get("/").status
|
35
|
+
assert ! File.directory?("#@docroot/dev666")
|
36
|
+
assert_equal 204, req.request("MKCOL", "/dev666").status
|
37
|
+
assert File.directory?("#@docroot/dev666")
|
38
|
+
|
39
|
+
io = StringIO.new("HELLO")
|
40
|
+
r = req.request("PUT", "/dev666/666.fid", :input => io)
|
41
|
+
assert_equal 201, r.status
|
42
|
+
assert_equal "HELLO", IO.read("#@docroot/dev666/666.fid")
|
43
|
+
|
44
|
+
# invalid MD5
|
45
|
+
io = StringIO.new("WORLD")
|
46
|
+
md5 = [ Digest::MD5.new.digest ].pack("m").strip!
|
47
|
+
opts = { :input => io, "HTTP_CONTENT_MD5" => md5 }
|
48
|
+
r = req.request("PUT", "/dev666/666.fid", opts)
|
49
|
+
assert_equal 400, r.status
|
50
|
+
assert_equal "HELLO", IO.read("#@docroot/dev666/666.fid")
|
51
|
+
|
52
|
+
# valid MD5
|
53
|
+
io = StringIO.new("VALID")
|
54
|
+
md5 = [ Digest::MD5.digest("VALID") ].pack("m").strip!
|
55
|
+
opts = { :input => io, "HTTP_CONTENT_MD5" => md5 }
|
56
|
+
r = req.request("PUT", "/dev666/666.fid", opts)
|
57
|
+
assert_equal 201, r.status
|
58
|
+
assert_equal "VALID", IO.read("#@docroot/dev666/666.fid")
|
59
|
+
|
60
|
+
r = req.request("GET", "/dev666/666.fid")
|
61
|
+
assert_equal 200, r.status
|
62
|
+
assert_equal "VALID", r.body
|
63
|
+
|
64
|
+
r = req.request("DELETE", "/dev666/666.fid")
|
65
|
+
assert_equal 204, r.status
|
66
|
+
assert ! File.exist?("#@docroot/dev666/666.fid")
|
67
|
+
end
|
68
|
+
|
69
|
+
def teardown
|
70
|
+
FileUtils.rmtree(@docroot)
|
71
|
+
end
|
72
|
+
end if defined?(Rack)
|
metadata
CHANGED
@@ -1,109 +1,121 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mogilefs-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15424119
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
|
-
-
|
8
|
-
-
|
7
|
+
- 3
|
8
|
+
- 0
|
9
9
|
- 0
|
10
|
-
|
10
|
+
- rc
|
11
|
+
- 1
|
12
|
+
version: 3.0.0.rc1
|
11
13
|
platform: ruby
|
12
14
|
authors:
|
13
15
|
- Eric Wong
|
14
|
-
- Eric Hodel
|
15
16
|
autorequire:
|
16
17
|
bindir: bin
|
17
18
|
cert_chain: []
|
18
19
|
|
19
|
-
date: 2011-
|
20
|
-
default_executable:
|
20
|
+
date: 2011-11-21 00:00:00 Z
|
21
21
|
dependencies:
|
22
|
-
- !ruby/object:Gem::Dependency
|
23
|
-
name: ZenTest
|
24
|
-
prerelease: false
|
25
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
|
-
requirements:
|
28
|
-
- - ">="
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 29
|
31
|
-
segments:
|
32
|
-
- 3
|
33
|
-
- 6
|
34
|
-
- 1
|
35
|
-
version: 3.6.1
|
36
|
-
type: :development
|
37
|
-
version_requirements: *id001
|
38
22
|
- !ruby/object:Gem::Dependency
|
39
23
|
name: hoe
|
40
24
|
prerelease: false
|
41
|
-
requirement: &
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
42
26
|
none: false
|
43
27
|
requirements:
|
44
|
-
- -
|
28
|
+
- - ~>
|
45
29
|
- !ruby/object:Gem::Version
|
46
|
-
hash:
|
30
|
+
hash: 27
|
47
31
|
segments:
|
48
32
|
- 2
|
49
|
-
-
|
50
|
-
|
51
|
-
version: 2.8.0
|
33
|
+
- 12
|
34
|
+
version: "2.12"
|
52
35
|
type: :development
|
53
|
-
version_requirements: *
|
54
|
-
description:
|
55
|
-
|
36
|
+
version_requirements: *id001
|
37
|
+
description: |-
|
38
|
+
A MogileFS client library for Ruby. MogileFS is an open source
|
39
|
+
distributed filesystem, see: http://mogilefs.org for more details. This
|
40
|
+
library allows any Ruby application to read, write and delete files in a
|
41
|
+
MogileFS instance.
|
42
|
+
email:
|
43
|
+
- normalperson@yhbt.net
|
56
44
|
executables:
|
57
45
|
- mog
|
58
46
|
extensions: []
|
59
47
|
|
60
48
|
extra_rdoc_files:
|
61
|
-
- History.txt
|
62
|
-
- LICENSE.txt
|
63
49
|
- Manifest.txt
|
64
|
-
- README.txt
|
65
50
|
files:
|
51
|
+
- .document
|
66
52
|
- .gitignore
|
53
|
+
- .wrongdoc.yml
|
54
|
+
- GIT-VERSION-GEN
|
67
55
|
- GNUmakefile
|
68
|
-
-
|
69
|
-
-
|
56
|
+
- HACKING
|
57
|
+
- History
|
58
|
+
- LICENSE
|
70
59
|
- Manifest.txt
|
71
|
-
- README
|
60
|
+
- README
|
72
61
|
- Rakefile
|
62
|
+
- TODO
|
73
63
|
- bin/mog
|
64
|
+
- examples/mogstored_rack.rb
|
74
65
|
- lib/mogilefs.rb
|
75
66
|
- lib/mogilefs/admin.rb
|
76
67
|
- lib/mogilefs/backend.rb
|
77
68
|
- lib/mogilefs/bigfile.rb
|
69
|
+
- lib/mogilefs/bigfile/filter.rb
|
70
|
+
- lib/mogilefs/chunker.rb
|
78
71
|
- lib/mogilefs/client.rb
|
79
|
-
- lib/mogilefs/
|
72
|
+
- lib/mogilefs/copy_stream.rb
|
73
|
+
- lib/mogilefs/http_file.rb
|
74
|
+
- lib/mogilefs/http_reader.rb
|
80
75
|
- lib/mogilefs/mogilefs.rb
|
81
76
|
- lib/mogilefs/mysql.rb
|
82
|
-
- lib/mogilefs/
|
77
|
+
- lib/mogilefs/paths_size.rb
|
83
78
|
- lib/mogilefs/pool.rb
|
79
|
+
- lib/mogilefs/socket.rb
|
80
|
+
- lib/mogilefs/socket/kgio.rb
|
81
|
+
- lib/mogilefs/socket/pure_ruby.rb
|
82
|
+
- lib/mogilefs/socket_common.rb
|
84
83
|
- lib/mogilefs/util.rb
|
85
84
|
- setup.rb
|
86
85
|
- test/.gitignore
|
87
86
|
- test/aggregate.rb
|
87
|
+
- test/exec.rb
|
88
|
+
- test/fresh.rb
|
89
|
+
- test/integration.rb
|
88
90
|
- test/setup.rb
|
91
|
+
- test/socket_test.rb
|
89
92
|
- test/test_admin.rb
|
90
93
|
- test/test_backend.rb
|
91
94
|
- test/test_bigfile.rb
|
92
95
|
- test/test_client.rb
|
93
96
|
- test/test_db_backend.rb
|
97
|
+
- test/test_fresh.rb
|
98
|
+
- test/test_http_reader.rb
|
94
99
|
- test/test_mogilefs.rb
|
100
|
+
- test/test_mogilefs_integration.rb
|
101
|
+
- test/test_mogilefs_integration_large_pipe.rb
|
102
|
+
- test/test_mogilefs_integration_list_keys.rb
|
103
|
+
- test/test_mogilefs_socket_kgio.rb
|
104
|
+
- test/test_mogilefs_socket_pure.rb
|
105
|
+
- test/test_mogstored_rack.rb
|
106
|
+
- test/test_mogtool_bigfile.rb
|
95
107
|
- test/test_mysql.rb
|
96
|
-
- test/test_network.rb
|
97
108
|
- test/test_pool.rb
|
98
|
-
- test/
|
99
|
-
|
100
|
-
|
109
|
+
- test/test_unit_mogstored_rack.rb
|
110
|
+
- lib/mogilefs/version.rb
|
111
|
+
- .gemtest
|
112
|
+
homepage: http://bogomips.org/mogilefs-client
|
101
113
|
licenses: []
|
102
114
|
|
103
115
|
post_install_message:
|
104
116
|
rdoc_options:
|
105
117
|
- --main
|
106
|
-
- README
|
118
|
+
- README
|
107
119
|
require_paths:
|
108
120
|
- lib
|
109
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -118,27 +130,37 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
131
|
none: false
|
120
132
|
requirements:
|
121
|
-
- - "
|
133
|
+
- - ">"
|
122
134
|
- !ruby/object:Gem::Version
|
123
|
-
hash:
|
135
|
+
hash: 25
|
124
136
|
segments:
|
125
|
-
-
|
126
|
-
|
137
|
+
- 1
|
138
|
+
- 3
|
139
|
+
- 1
|
140
|
+
version: 1.3.1
|
127
141
|
requirements: []
|
128
142
|
|
129
143
|
rubyforge_project: seattlerb
|
130
|
-
rubygems_version: 1.
|
144
|
+
rubygems_version: 1.8.11
|
131
145
|
signing_key:
|
132
146
|
specification_version: 3
|
133
|
-
summary:
|
147
|
+
summary: MogileFS client library for Ruby
|
134
148
|
test_files:
|
149
|
+
- test/test_http_reader.rb
|
150
|
+
- test/test_unit_mogstored_rack.rb
|
151
|
+
- test/test_mogilefs_integration_list_keys.rb
|
135
152
|
- test/test_db_backend.rb
|
136
|
-
- test/
|
153
|
+
- test/test_mogilefs_socket_pure.rb
|
137
154
|
- test/test_mysql.rb
|
138
|
-
- test/test_util.rb
|
139
155
|
- test/test_backend.rb
|
140
156
|
- test/test_mogilefs.rb
|
157
|
+
- test/test_mogtool_bigfile.rb
|
141
158
|
- test/test_client.rb
|
142
159
|
- test/test_admin.rb
|
160
|
+
- test/test_mogilefs_socket_kgio.rb
|
161
|
+
- test/test_mogilefs_integration.rb
|
162
|
+
- test/test_fresh.rb
|
143
163
|
- test/test_pool.rb
|
144
164
|
- test/test_bigfile.rb
|
165
|
+
- test/test_mogilefs_integration_large_pipe.rb
|
166
|
+
- test/test_mogstored_rack.rb
|
data/README.txt
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
= mogilefs-client
|
2
|
-
|
3
|
-
A Ruby MogileFS client
|
4
|
-
|
5
|
-
Rubyforge Project:
|
6
|
-
|
7
|
-
http://rubyforge.org/projects/seattlerb/
|
8
|
-
|
9
|
-
Documentation:
|
10
|
-
|
11
|
-
http://seattlerb.rubyforge.org/mogilefs-client
|
12
|
-
|
13
|
-
File bugs:
|
14
|
-
|
15
|
-
http://rubyforge.org/tracker/?func=add&group_id=1513&atid=5921
|
16
|
-
|
17
|
-
Please email Eric Wong at normalperson@yhbt.net as well since
|
18
|
-
he finds web interfaces difficult to use.
|
19
|
-
|
20
|
-
Source repository (git):
|
21
|
-
|
22
|
-
git://git.bogomips.org/mogilefs-client.git
|
23
|
-
http://git.bogomips.org/mogilefs-client.git
|
24
|
-
git://repo.or.cz/ruby-mogilefs-client.git (mirror)
|
25
|
-
http://repo.or.cz/r/ruby-mogilefs-client.git (mirror)
|
26
|
-
|
27
|
-
Repository browsers:
|
28
|
-
|
29
|
-
* http://git.bogomips.org/cgit/mogilefs-client.git (cgit)
|
30
|
-
* http://repo.or.cz/w/ruby-mogilefs-client.git (gitweb mirror)
|
31
|
-
|
32
|
-
== About
|
33
|
-
|
34
|
-
A Ruby MogileFS client. MogileFS is a distributed filesystem written
|
35
|
-
by Danga Interactive. This client only supports HTTP.
|
36
|
-
|
37
|
-
For information on MogileFS see:
|
38
|
-
|
39
|
-
http://danga.com/mogilefs/
|
40
|
-
|
41
|
-
== Installing mogilefs-client
|
42
|
-
|
43
|
-
First you need a MogileFS setup. You can find information on how to do
|
44
|
-
that at the above URL.
|
45
|
-
|
46
|
-
Then install the gem:
|
47
|
-
|
48
|
-
$ sudo gem install mogilefs-client
|
49
|
-
|
50
|
-
== Using mogilefs-client
|
51
|
-
|
52
|
-
# Create a new instance that will communicate with these trackers:
|
53
|
-
hosts = %w[192.168.1.69:6001 192.168.1.70:6001]
|
54
|
-
mg = MogileFS::MogileFS.new(:domain => 'test', :hosts => hosts)
|
55
|
-
|
56
|
-
# Stores "A bunch of text to store" into 'some_key' with a class of 'text'.
|
57
|
-
mg.store_content 'some_key', 'text', "A bunch of text to store"
|
58
|
-
|
59
|
-
# Retrieve data from 'some_key'
|
60
|
-
data = mg.get_file_data 'some_key'
|
61
|
-
|
62
|
-
# Store the contents of 'image.jpeg' into the key 'my_image' with a class of
|
63
|
-
# 'image'.
|
64
|
-
mg.store_file 'my_image', 'image', 'image.jpeg'
|
65
|
-
|
66
|
-
# Store the contents of 'image.jpeg' into the key 'my_image' with a class of
|
67
|
-
# 'image' using an open IO.
|
68
|
-
File.open 'image.jpeg', 'rb' do |fp|
|
69
|
-
mg.store_file 'my_image', 'image', fp
|
70
|
-
end
|
71
|
-
|
72
|
-
# Remove the key 'my_image' and 'some_key'.
|
73
|
-
mg.delete 'my_image'
|
74
|
-
mg.delete 'some_key'
|
75
|
-
|
76
|
-
== WARNING!
|
77
|
-
|
78
|
-
This client is only supported in HTTP mode. NFS mode was previously
|
79
|
-
supported in 1.3.x, but since MogileFS 2.x has dropped support for
|
80
|
-
NFS, this client has removed support for it.
|
data/lib/mogilefs/httpfile.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
# -*- encoding: binary -*-
|
2
|
-
require 'stringio'
|
3
|
-
require 'uri'
|
4
|
-
require 'mogilefs/backend'
|
5
|
-
require 'mogilefs/util'
|
6
|
-
|
7
|
-
##
|
8
|
-
# HTTPFile wraps up the new file operations for storing files onto an HTTP
|
9
|
-
# storage node.
|
10
|
-
#
|
11
|
-
# You really don't want to create an HTTPFile by hand. Instead you want to
|
12
|
-
# create a new file using MogileFS::MogileFS.new_file.
|
13
|
-
#
|
14
|
-
#--
|
15
|
-
# TODO dup'd content in MogileFS::NFSFile
|
16
|
-
|
17
|
-
class MogileFS::HTTPFile < StringIO
|
18
|
-
include MogileFS::Util
|
19
|
-
|
20
|
-
class EmptyResponseError < MogileFS::Error; end
|
21
|
-
class BadResponseError < MogileFS::Error; end
|
22
|
-
class UnparseableResponseError < MogileFS::Error; end
|
23
|
-
class NoStorageNodesError < MogileFS::Error
|
24
|
-
def message; 'Unable to open socket to storage node'; end
|
25
|
-
end
|
26
|
-
|
27
|
-
##
|
28
|
-
# The URI this file will be stored to.
|
29
|
-
|
30
|
-
attr_reader :uri
|
31
|
-
|
32
|
-
##
|
33
|
-
# The key for this file. This key won't represent a real file until you've
|
34
|
-
# called #close.
|
35
|
-
|
36
|
-
attr_reader :key
|
37
|
-
|
38
|
-
##
|
39
|
-
# The class of this file.
|
40
|
-
|
41
|
-
attr_reader :class
|
42
|
-
|
43
|
-
##
|
44
|
-
# The big_io name in case we have file > 256M
|
45
|
-
|
46
|
-
attr_accessor :big_io
|
47
|
-
|
48
|
-
attr_accessor :streaming_io
|
49
|
-
|
50
|
-
##
|
51
|
-
# Works like File.open. Use MogileFS::MogileFS#new_file instead of this
|
52
|
-
# method.
|
53
|
-
|
54
|
-
def self.open(*args)
|
55
|
-
fp = new(*args)
|
56
|
-
fp.set_encoding(Encoding::BINARY) if fp.respond_to?(:set_encoding)
|
57
|
-
|
58
|
-
return fp unless block_given?
|
59
|
-
|
60
|
-
begin
|
61
|
-
yield fp
|
62
|
-
ensure
|
63
|
-
fp.close
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
##
|
68
|
-
# Creates a new HTTPFile with MogileFS-specific data. Use
|
69
|
-
# MogileFS::MogileFS#new_file instead of this method.
|
70
|
-
|
71
|
-
def initialize(mg, fid, klass, key, dests, content_length)
|
72
|
-
super ''
|
73
|
-
@mg = mg
|
74
|
-
@fid = fid
|
75
|
-
@uri = @devid = nil
|
76
|
-
@klass = klass
|
77
|
-
@key = key
|
78
|
-
@big_io = nil
|
79
|
-
@streaming_io = nil
|
80
|
-
|
81
|
-
@dests = dests
|
82
|
-
@tried = {}
|
83
|
-
|
84
|
-
@socket = nil
|
85
|
-
end
|
86
|
-
|
87
|
-
##
|
88
|
-
# Writes an HTTP PUT request to +sock+ to upload the file and
|
89
|
-
# returns file size if the socket finished writing
|
90
|
-
def upload(devid, uri)
|
91
|
-
file_size = length
|
92
|
-
sock = Socket.mogilefs_new(uri.host, uri.port)
|
93
|
-
|
94
|
-
if @streaming_io
|
95
|
-
file_size = @streaming_io.length
|
96
|
-
syswrite_full(sock, "PUT #{uri.request_uri} HTTP/1.0\r\n" \
|
97
|
-
"Content-Length: #{file_size}\r\n\r\n")
|
98
|
-
@streaming_io.call(Proc.new do |data_to_write|
|
99
|
-
syswrite_full(sock, data_to_write)
|
100
|
-
end)
|
101
|
-
elsif @big_io
|
102
|
-
# Don't try to run out of memory
|
103
|
-
File.open(@big_io, "rb") do |fp|
|
104
|
-
file_size = fp.stat.size
|
105
|
-
syswrite_full(sock, "PUT #{uri.request_uri} HTTP/1.0\r\n" \
|
106
|
-
"Content-Length: #{file_size}\r\n\r\n")
|
107
|
-
sysrwloop(fp, sock)
|
108
|
-
end
|
109
|
-
else
|
110
|
-
syswrite_full(sock, "PUT #{uri.request_uri} HTTP/1.0\r\n" \
|
111
|
-
"Content-Length: #{length}\r\n\r\n#{string}")
|
112
|
-
end
|
113
|
-
|
114
|
-
line = sock.gets or
|
115
|
-
raise EmptyResponseError, 'Unable to read response line from server'
|
116
|
-
|
117
|
-
if line =~ %r%^HTTP/\d+\.\d+\s+(\d+)% then
|
118
|
-
case $1.to_i
|
119
|
-
when 200..299 then # success!
|
120
|
-
else
|
121
|
-
raise BadResponseError, "HTTP response status from upload: #{$1}"
|
122
|
-
end
|
123
|
-
else
|
124
|
-
raise UnparseableResponseError, "Response line not understood: #{line}"
|
125
|
-
end
|
126
|
-
|
127
|
-
@mg.backend.create_close(:fid => @fid, :devid => devid,
|
128
|
-
:domain => @mg.domain, :key => @key,
|
129
|
-
:path => uri.to_s, :size => file_size)
|
130
|
-
file_size
|
131
|
-
end # def upload
|
132
|
-
|
133
|
-
def close
|
134
|
-
try_dests = @dests.dup
|
135
|
-
last_err = nil
|
136
|
-
|
137
|
-
loop do
|
138
|
-
devid, url = try_dests.shift
|
139
|
-
devid && url or break
|
140
|
-
|
141
|
-
uri = URI.parse(url)
|
142
|
-
begin
|
143
|
-
bytes = upload(devid, uri)
|
144
|
-
@devid, @uri = devid, uri
|
145
|
-
return bytes
|
146
|
-
rescue SystemCallError, Errno::ECONNREFUSED, MogileFS::Timeout,
|
147
|
-
EmptyResponseError, BadResponseError,
|
148
|
-
UnparseableResponseError => err
|
149
|
-
last_err = @tried[url] = err
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
raise last_err ? last_err : NoStorageNodesError
|
154
|
-
end
|
155
|
-
|
156
|
-
end
|
157
|
-
|