mogilefs-client 1.3.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/GNUmakefile +32 -0
- data/History.txt +23 -0
- data/LICENSE.txt +1 -0
- data/Manifest.txt +12 -1
- data/README.txt +22 -13
- data/bin/mog +37 -6
- data/lib/mogilefs.rb +19 -5
- data/lib/mogilefs/admin.rb +27 -34
- data/lib/mogilefs/backend.rb +106 -39
- data/lib/mogilefs/bigfile.rb +153 -0
- data/lib/mogilefs/client.rb +1 -5
- data/lib/mogilefs/httpfile.rb +65 -71
- data/lib/mogilefs/mogilefs.rb +102 -102
- data/lib/mogilefs/mysql.rb +166 -0
- data/lib/mogilefs/network.rb +64 -0
- data/lib/mogilefs/pool.rb +1 -1
- data/lib/mogilefs/util.rb +140 -9
- data/test/.gitignore +2 -0
- data/test/aggregate.rb +13 -0
- data/test/setup.rb +72 -91
- data/test/test_admin.rb +2 -2
- data/test/test_backend.rb +100 -38
- data/test/test_bigfile.rb +48 -0
- data/test/test_client.rb +7 -2
- data/test/test_db_backend.rb +73 -0
- data/test/test_mogilefs.rb +287 -107
- data/test/test_mysql.rb +94 -0
- data/test/test_network.rb +27 -0
- data/test/test_util.rb +59 -0
- metadata +22 -6
- data/lib/mogilefs/nfsfile.rb +0 -81
data/test/test_mysql.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'test/setup'
|
2
|
+
require 'mogilefs/mysql'
|
3
|
+
|
4
|
+
class MogileFS::Mysql
|
5
|
+
public :refresh_device
|
6
|
+
public :refresh_domain
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestMogileFS__Mysql < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@my = FakeMysql.new
|
13
|
+
@mg = MogileFS::Mysql.new(:mysql => @my)
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_refresh_device
|
18
|
+
expect = {
|
19
|
+
1=>
|
20
|
+
{:hostip=>"10.0.0.1",
|
21
|
+
:http_get_port=>7600,
|
22
|
+
:http_port=>7500,
|
23
|
+
:altip=>"192.168.0.1"},
|
24
|
+
2=>
|
25
|
+
{:hostip=>"10.0.0.2",
|
26
|
+
:http_get_port=>7600,
|
27
|
+
:http_port=>7500,
|
28
|
+
:altip=>"192.168.0.2"},
|
29
|
+
3=>
|
30
|
+
{:hostip=>"10.0.0.3",
|
31
|
+
:http_get_port=>7500,
|
32
|
+
:http_port=>7500,
|
33
|
+
:altip=>"10.0.0.3"},
|
34
|
+
4=>
|
35
|
+
{:hostip=>"10.0.0.4",
|
36
|
+
:http_get_port=>7500,
|
37
|
+
:http_port=>7500,
|
38
|
+
:altip=>"10.0.0.4"}
|
39
|
+
}
|
40
|
+
assert_equal expect, @mg.refresh_device
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_refresh_domain
|
44
|
+
expect = { 'test' => 1, 'foo' => 2 }
|
45
|
+
assert_equal expect, @mg.refresh_domain
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_get_paths
|
49
|
+
@my.expect << [ [ 12 ] ] # fid
|
50
|
+
@my.expect << [ [ 1 ], [ 3 ] ] # devids
|
51
|
+
expect = [ "http://10.0.0.1:7600/dev1/0/000/000/0000000012.fid",
|
52
|
+
"http://10.0.0.3:7500/dev3/0/000/000/0000000012.fid" ]
|
53
|
+
assert_equal expect, @mg._get_paths(:domain => 'test', :key => 'fookey')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_get_paths_alt
|
57
|
+
@my.expect << [ [ 12 ] ] # fid
|
58
|
+
@my.expect << [ [ 1 ], [ 3 ] ] # devids
|
59
|
+
expect = [ "http://192.168.0.1:7600/dev1/0/000/000/0000000012.fid",
|
60
|
+
"http://10.0.0.3:7500/dev3/0/000/000/0000000012.fid"]
|
61
|
+
params = { :domain => 'test', :key => 'fookey', :zone => 'alt' }
|
62
|
+
assert_equal expect, @mg._get_paths(params)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_list_keys
|
66
|
+
expect_full = [ [ 'foo', 123, 2 ], [ 'bar', 456, 1 ] ]
|
67
|
+
expect_keys = [ [ 'foo', 'bar' ], 'bar' ]
|
68
|
+
@my.expect << expect_full
|
69
|
+
full = []
|
70
|
+
keys = @mg._list_keys('test') do |dkey,length,devcount|
|
71
|
+
full << [ dkey, length, devcount ]
|
72
|
+
end
|
73
|
+
assert_equal expect_keys, keys
|
74
|
+
assert_equal expect_full, full
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_list_keys_empty
|
78
|
+
@my.expect << []
|
79
|
+
assert_nil @mg._list_keys('test')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_size
|
83
|
+
@my.expect << [ [ '123' ] ]
|
84
|
+
assert_equal 123, @mg._size('test', 'foo')
|
85
|
+
|
86
|
+
@my.expect << [ [ '456' ] ]
|
87
|
+
assert_equal 456, @mg._size('test', 'foo')
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_sleep
|
91
|
+
assert_nothing_raised { assert_equal({}, @mg.sleep(:duration => 1)) }
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test/setup'
|
2
|
+
require 'mogilefs'
|
3
|
+
require 'mogilefs/network'
|
4
|
+
|
5
|
+
class TestNetwork < Test::Unit::TestCase
|
6
|
+
include MogileFS::Network
|
7
|
+
|
8
|
+
def test_verify_uris
|
9
|
+
good = TempServer.new(Proc.new do |serv,port|
|
10
|
+
client,client_addr = serv.accept
|
11
|
+
client.readpartial(4096)
|
12
|
+
client.syswrite("HTTP/1.0 200 OK\r\nContent-Length: 0\r\n\r\n")
|
13
|
+
end)
|
14
|
+
bad = TempServer.new(Proc.new do |serv,port|
|
15
|
+
client, client_addr = serv.accept
|
16
|
+
client.close rescue nil
|
17
|
+
end)
|
18
|
+
|
19
|
+
good_uri = URI.parse("http://127.0.0.1:#{good.port}/")
|
20
|
+
bad_uri = URI.parse("http://127.0.0.1:#{bad.port}/")
|
21
|
+
ok = verify_uris([ good_uri, bad_uri ])
|
22
|
+
assert_equal [ good_uri ], ok
|
23
|
+
ensure
|
24
|
+
TempServer.destroy_all!
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/test/test_util.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test/setup'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
class TestMogileFS__Util < Test::Unit::TestCase
|
5
|
+
include MogileFS::Util
|
6
|
+
|
7
|
+
def test_mogilefs_write
|
8
|
+
done = Queue.new
|
9
|
+
|
10
|
+
svr = Proc.new do |serv, port|
|
11
|
+
client, client_addr = serv.accept
|
12
|
+
client.sync = true
|
13
|
+
readed = 0
|
14
|
+
loop do
|
15
|
+
begin
|
16
|
+
readed += client.readpartial(16384).length
|
17
|
+
rescue EOFError
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
done << readed
|
22
|
+
client.close rescue nil
|
23
|
+
end
|
24
|
+
t = TempServer.new(svr)
|
25
|
+
s = Socket.mogilefs_new('127.0.0.1', t.port)
|
26
|
+
tmp = s.getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF)
|
27
|
+
sndbuf_bytes = tmp.unpack('i')[0]
|
28
|
+
big_string = ' ' * (sndbuf_bytes * 10)
|
29
|
+
|
30
|
+
sent = s.send(big_string, 0)
|
31
|
+
assert(sent < big_string.length)
|
32
|
+
|
33
|
+
syswrite_full(s, big_string)
|
34
|
+
s.close rescue nil
|
35
|
+
readed = done.pop
|
36
|
+
|
37
|
+
assert_equal((sent + big_string.length), readed)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_write_timeout
|
41
|
+
done = Queue.new
|
42
|
+
|
43
|
+
svr = Proc.new do |serv, port|
|
44
|
+
client, client_addr = serv.accept
|
45
|
+
client.sync = true
|
46
|
+
readed = client.readpartial(16384)
|
47
|
+
sleep
|
48
|
+
end
|
49
|
+
t = TempServer.new(svr)
|
50
|
+
s = Socket.mogilefs_new('127.0.0.1', t.port)
|
51
|
+
tmp = s.getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF)
|
52
|
+
sndbuf_bytes = tmp.unpack('i')[0]
|
53
|
+
big_string = ' ' * (sndbuf_bytes * 10)
|
54
|
+
|
55
|
+
assert_raises(MogileFS::Timeout) { syswrite_full(s, big_string, 0.1) }
|
56
|
+
s.close rescue nil
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mogilefs-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Wong
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2009-02-02 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -31,9 +31,9 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.
|
34
|
+
version: 1.8.2
|
35
35
|
version:
|
36
|
-
description:
|
36
|
+
description: git://git.bogomips.org/mogilefs-client.git
|
37
37
|
email: normalperson@yhbt.net
|
38
38
|
executables:
|
39
39
|
- mog
|
@@ -45,6 +45,8 @@ extra_rdoc_files:
|
|
45
45
|
- Manifest.txt
|
46
46
|
- README.txt
|
47
47
|
files:
|
48
|
+
- .gitignore
|
49
|
+
- GNUmakefile
|
48
50
|
- History.txt
|
49
51
|
- LICENSE.txt
|
50
52
|
- Manifest.txt
|
@@ -54,18 +56,27 @@ files:
|
|
54
56
|
- lib/mogilefs.rb
|
55
57
|
- lib/mogilefs/admin.rb
|
56
58
|
- lib/mogilefs/backend.rb
|
59
|
+
- lib/mogilefs/bigfile.rb
|
57
60
|
- lib/mogilefs/client.rb
|
58
61
|
- lib/mogilefs/httpfile.rb
|
59
62
|
- lib/mogilefs/mogilefs.rb
|
60
|
-
- lib/mogilefs/
|
63
|
+
- lib/mogilefs/mysql.rb
|
64
|
+
- lib/mogilefs/network.rb
|
61
65
|
- lib/mogilefs/pool.rb
|
62
66
|
- lib/mogilefs/util.rb
|
67
|
+
- test/.gitignore
|
68
|
+
- test/aggregate.rb
|
63
69
|
- test/setup.rb
|
64
70
|
- test/test_admin.rb
|
65
71
|
- test/test_backend.rb
|
72
|
+
- test/test_bigfile.rb
|
66
73
|
- test/test_client.rb
|
74
|
+
- test/test_db_backend.rb
|
67
75
|
- test/test_mogilefs.rb
|
76
|
+
- test/test_mysql.rb
|
77
|
+
- test/test_network.rb
|
68
78
|
- test/test_pool.rb
|
79
|
+
- test/test_util.rb
|
69
80
|
has_rdoc: true
|
70
81
|
homepage: http://seattlerb.org/mogilefs-client
|
71
82
|
post_install_message:
|
@@ -89,13 +100,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
100
|
requirements: []
|
90
101
|
|
91
102
|
rubyforge_project: seattlerb
|
92
|
-
rubygems_version: 1.
|
103
|
+
rubygems_version: 1.3.1
|
93
104
|
signing_key:
|
94
105
|
specification_version: 2
|
95
106
|
summary: A Ruby MogileFS client
|
96
107
|
test_files:
|
108
|
+
- test/test_bigfile.rb
|
97
109
|
- test/test_pool.rb
|
110
|
+
- test/test_db_backend.rb
|
98
111
|
- test/test_mogilefs.rb
|
112
|
+
- test/test_network.rb
|
113
|
+
- test/test_mysql.rb
|
99
114
|
- test/test_client.rb
|
100
115
|
- test/test_admin.rb
|
116
|
+
- test/test_util.rb
|
101
117
|
- test/test_backend.rb
|
data/lib/mogilefs/nfsfile.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'mogilefs/backend'
|
2
|
-
|
3
|
-
##
|
4
|
-
# NFSFile wraps up the new file operations for storing files onto an NFS
|
5
|
-
# storage node.
|
6
|
-
#
|
7
|
-
# You really don't want to create an NFSFile by hand. Instead you want to
|
8
|
-
# create a new file using MogileFS::MogileFS.new_file.
|
9
|
-
|
10
|
-
class MogileFS::NFSFile < File
|
11
|
-
|
12
|
-
##
|
13
|
-
# The path of this file not including the local mount point.
|
14
|
-
|
15
|
-
attr_reader :path
|
16
|
-
|
17
|
-
##
|
18
|
-
# The key for this file. This key won't represent a real file until you've
|
19
|
-
# called #close.
|
20
|
-
|
21
|
-
attr_reader :key
|
22
|
-
|
23
|
-
##
|
24
|
-
# The class of this file.
|
25
|
-
|
26
|
-
attr_reader :class
|
27
|
-
|
28
|
-
class << self
|
29
|
-
|
30
|
-
##
|
31
|
-
# Wraps up File.new with MogileFS-specific data. Use
|
32
|
-
# MogileFS::MogileFS#new_file instead of this method.
|
33
|
-
|
34
|
-
def new(mg, fid, path, devid, klass, key)
|
35
|
-
fp = super join(mg.root, path), 'w+'
|
36
|
-
fp.send :setup, mg, fid, path, devid, klass, key
|
37
|
-
return fp
|
38
|
-
end
|
39
|
-
|
40
|
-
##
|
41
|
-
# Wraps up File.open with MogileFS-specific data. Use
|
42
|
-
# MogileFS::MogileFS#new_file instead of this method.
|
43
|
-
|
44
|
-
def open(mg, fid, path, devid, klass, key, &block)
|
45
|
-
fp = new mg, fid, path, devid, klass, key
|
46
|
-
|
47
|
-
return fp if block.nil?
|
48
|
-
|
49
|
-
begin
|
50
|
-
yield fp
|
51
|
-
ensure
|
52
|
-
fp.close
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
# Closes the file handle and marks it as closed in MogileFS.
|
60
|
-
|
61
|
-
def close
|
62
|
-
super
|
63
|
-
@mg.backend.create_close(:fid => @fid, :devid => @devid,
|
64
|
-
:domain => @mg.domain, :key => @key,
|
65
|
-
:path => @path)
|
66
|
-
return nil
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def setup(mg, fid, path, devid, klass, key)
|
72
|
-
@mg = mg
|
73
|
-
@fid = fid
|
74
|
-
@path = path
|
75
|
-
@devid = devid
|
76
|
-
@klass = klass
|
77
|
-
@key = key
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|