regurgitator 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/GIT-VERSION-GEN +1 -1
- data/lib/regurgitator/device.rb +8 -10
- data/lib/regurgitator/domain.rb +3 -3
- data/lib/regurgitator/endpoint.rb +1 -0
- data/lib/regurgitator/file_info.rb +7 -5
- data/lib/regurgitator/file_request.rb +2 -2
- data/lib/regurgitator/list_keys.rb +2 -1
- data/lib/regurgitator/local_file.rb +4 -3
- data/lib/regurgitator/server_settings.rb +4 -4
- data/regurgitator.gemspec +11 -16
- data/t/t0002-domain_host.sh +5 -2
- metadata +6 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2d383effa64f09d324b76580dd3f4c2750759b6
|
4
|
+
data.tar.gz: ff6b44450160b68be22d4b86304e5589f77ffa3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1a18579be3d5a719e6fb212c1d246fcdf0c693a7e8a85df87fd8763b550e58f92454accd35bb6d261adcacf3bcee7a44a66ad0b879161edb147df84ea6d1fb2
|
7
|
+
data.tar.gz: cd56b2b2b5ec792d89763fceb8b0e6eac7550431053e740cbe193687be3a6bde57c84ada185a46d37a8cc826bee0db6df839ece9da521a4c0fe65de81b25ceb1
|
data/GIT-VERSION-GEN
CHANGED
data/lib/regurgitator/device.rb
CHANGED
@@ -6,15 +6,6 @@ require_relative 'server_settings'
|
|
6
6
|
module Regurgitator::Device # :nodoc:
|
7
7
|
include Regurgitator::ServerSettings
|
8
8
|
|
9
|
-
REFRESH_DEVICE = <<-EOS
|
10
|
-
SELECT d.devid, h.hostip, h.http_port, h.http_get_port
|
11
|
-
FROM device d
|
12
|
-
LEFT JOIN host h ON d.hostid = h.hostid
|
13
|
-
WHERE d.status IN ('readonly','alive','drain') AND h.status = 'alive'
|
14
|
-
EOS
|
15
|
-
|
16
|
-
DEVICES_ON = 'SELECT devid FROM file_on WHERE fid = ?'
|
17
|
-
|
18
9
|
def device_init
|
19
10
|
server_settings_init
|
20
11
|
@dev_cache_mtime = 0
|
@@ -41,7 +32,14 @@ module Regurgitator::Device # :nodoc:
|
|
41
32
|
return @dev_cache if !force && ((Regurgitator.now - @dev_cache_mtime) < 60)
|
42
33
|
tmp = {}.compare_by_identity
|
43
34
|
refresh_zone(force)
|
44
|
-
|
35
|
+
|
36
|
+
sql = <<-EOS.freeze
|
37
|
+
SELECT d.devid, h.hostip, h.http_port, h.http_get_port
|
38
|
+
FROM device d
|
39
|
+
LEFT JOIN host h ON d.hostid = h.hostid
|
40
|
+
WHERE d.status IN ('readonly','alive','drain') AND h.status = 'alive'
|
41
|
+
EOS
|
42
|
+
@db[sql].each do |x|
|
45
43
|
# devices in "drain" status may hit raciness try those as a last resort
|
46
44
|
x[:preferred] = !!(x[:d_status] =~ %r{\A(?:readonly|alive)\z})
|
47
45
|
hostip = x[:hostip]
|
data/lib/regurgitator/domain.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
# helpers for domain lookups
|
3
3
|
module Regurgitator::Domain # :nodoc:
|
4
4
|
|
5
|
-
REFRESH_DOMAIN = 'SELECT dmid,namespace FROM domain' # :nodoc:
|
6
|
-
|
7
5
|
def domain_init
|
8
6
|
@domain_lock = Mutex.new
|
9
7
|
@domain_cache_mtime = 0
|
@@ -26,7 +24,9 @@ module Regurgitator::Domain # :nodoc:
|
|
26
24
|
def refresh_domain_unlocked # :nodoc:
|
27
25
|
return @domain_cache if ((Regurgitator.now - @domain_cache_mtime) < 15)
|
28
26
|
tmp = {}
|
29
|
-
@db[
|
27
|
+
@db['SELECT dmid,namespace FROM domain'.freeze].each do |x|
|
28
|
+
tmp[x[:namespace].freeze] = x[:dmid]
|
29
|
+
end
|
30
30
|
@domain_cache_mtime = Regurgitator.now
|
31
31
|
@domain_cache = tmp
|
32
32
|
end
|
@@ -71,6 +71,7 @@ module Regurgitator::Endpoint # :nodoc:
|
|
71
71
|
status, headers, body = r = Regurgitator::FileRequest.run(env, uris)
|
72
72
|
filename!(env, headers, dkey)
|
73
73
|
headers['ETag'] = %("#{info[:fid]}")
|
74
|
+
headers.delete('Connection'.freeze)
|
74
75
|
|
75
76
|
case env["REQUEST_METHOD"]
|
76
77
|
when "GET"
|
@@ -7,8 +7,6 @@ module Regurgitator::FileInfo # :nodoc:
|
|
7
7
|
include Regurgitator::Domain
|
8
8
|
include Regurgitator::Device
|
9
9
|
|
10
|
-
FILE_INFO = 'SELECT fid,length FROM file WHERE dmid = ? AND dkey = ? LIMIT 1'
|
11
|
-
|
12
10
|
def file_info_init
|
13
11
|
domain_init
|
14
12
|
device_init
|
@@ -27,7 +25,11 @@ module Regurgitator::FileInfo # :nodoc:
|
|
27
25
|
def file_info(env, domain, dkey, update = false)
|
28
26
|
dmid = get_dmid(domain) or return
|
29
27
|
devices = refresh_device(update)
|
30
|
-
|
28
|
+
|
29
|
+
info = @db[
|
30
|
+
'SELECT fid,length FROM file WHERE dmid = ? AND dkey = ? LIMIT 1'.freeze,
|
31
|
+
dmid, dkey
|
32
|
+
].first or return
|
31
33
|
0 == info[:length] and return info
|
32
34
|
fid = info[:fid]
|
33
35
|
read_uris = Hash.new { |h,k| h[k] = [] }
|
@@ -35,12 +37,12 @@ module Regurgitator::FileInfo # :nodoc:
|
|
35
37
|
|
36
38
|
zone = env['regurgitator.zone']
|
37
39
|
|
38
|
-
@db[
|
40
|
+
@db['SELECT devid FROM file_on WHERE fid = ?'.freeze, fid].each do |x|
|
39
41
|
devinfo = devices[x[:devid]] or next
|
40
42
|
fid >= 10_000_000_000 and next # TODO: support larger FIDs
|
41
43
|
|
42
44
|
uris = devinfo[:uris][:pri]
|
43
|
-
nfid = sprintf('%010u', fid)
|
45
|
+
nfid = sprintf('%010u'.freeze, fid)
|
44
46
|
/\A(\d)(\d{3})(\d{3})(?:\d{3})\z/ =~ nfid
|
45
47
|
fid_path = "/#$1/#$2/#$3/#{nfid}.fid"
|
46
48
|
uris = uris.map do |u|
|
@@ -38,9 +38,9 @@ class Regurgitator::FileRequest < HTTP_Spew::Request # :nodoc:
|
|
38
38
|
}
|
39
39
|
PASS_HEADERS.each { |k| pass = env[k] and req[k] = pass }
|
40
40
|
tmp = HTTP_Spew.wait(1, uri_group.map { |uris| new(req, uris) }, timeout)
|
41
|
-
tmp.delete_if
|
41
|
+
tmp.delete_if(&:error)
|
42
42
|
ready = tmp.shift or raise Regurgitator::NoDevices, "no readable devices"
|
43
|
-
tmp.each
|
43
|
+
tmp.each(&:close)
|
44
44
|
ready.response
|
45
45
|
end
|
46
46
|
end
|
@@ -19,7 +19,8 @@ module Regurgitator::ListKeys # :nodoc:
|
|
19
19
|
limit = LIST_KEYS_MAX if limit > LIST_KEYS_MAX
|
20
20
|
sql = "SELECT fid,dkey,length,devcount,classid " \
|
21
21
|
"FROM file WHERE dmid = #{dmid}"
|
22
|
-
|
22
|
+
prefix and
|
23
|
+
sql << " AND dkey LIKE /*! BINARY */ #{@db.literal(prefix+'%'.freeze)}"
|
23
24
|
sql << " AND dkey > #{@db.literal(after)}" if after
|
24
25
|
sql << " ORDER BY dkey LIMIT #{limit}"
|
25
26
|
|
@@ -21,10 +21,10 @@ class Regurgitator::LocalFile # :nodoc:
|
|
21
21
|
size = stat.size
|
22
22
|
|
23
23
|
headers = {
|
24
|
-
"Content-Type" => "application/octet-stream", # always ".fid"
|
24
|
+
"Content-Type" => "application/octet-stream".freeze, # always ".fid"
|
25
25
|
"Content-Length" => size.to_s,
|
26
26
|
"Last-Modified" => stat.mtime.httpdate,
|
27
|
-
"Accept-Ranges" => "bytes",
|
27
|
+
"Accept-Ranges" => "bytes".freeze,
|
28
28
|
}
|
29
29
|
@response = [ 200, headers ]
|
30
30
|
|
@@ -38,7 +38,7 @@ class Regurgitator::LocalFile # :nodoc:
|
|
38
38
|
else
|
39
39
|
@response[0] = 416
|
40
40
|
headers["Content-Range"] = "bytes */#{size}"
|
41
|
-
headers["Content-Length"] = '0'
|
41
|
+
headers["Content-Length"] = '0'.freeze
|
42
42
|
@response << []
|
43
43
|
return
|
44
44
|
end
|
@@ -72,6 +72,7 @@ class Regurgitator::LocalFile # :nodoc:
|
|
72
72
|
yield buf
|
73
73
|
end
|
74
74
|
end
|
75
|
+
buf.clear
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
@@ -4,8 +4,6 @@
|
|
4
4
|
require_relative 'local'
|
5
5
|
module Regurgitator::ServerSettings # :nodoc:
|
6
6
|
|
7
|
-
SETTINGS_LOOKUP = 'SELECT value FROM server_settings WHERE field = ? LIMIT 1'
|
8
|
-
|
9
7
|
def server_settings_init
|
10
8
|
@zone_cache_mtime = 0
|
11
9
|
@zone_cache = nil
|
@@ -23,10 +21,12 @@ module Regurgitator::ServerSettings # :nodoc:
|
|
23
21
|
def refresh_zone_unlocked(force)
|
24
22
|
return @zone_cache if !force && ((Regurgitator.now-@zone_cache_mtime) < 60)
|
25
23
|
tmp = Patricia.new
|
24
|
+
sql = 'SELECT value FROM server_settings WHERE field = ? LIMIT 1'.freeze
|
25
|
+
|
26
26
|
begin
|
27
|
-
row = @db[
|
27
|
+
row = @db[sql, 'network_zones'.freeze].first or return tmp
|
28
28
|
row[:value].split(/\s*,\s*/).each do |zone|
|
29
|
-
row = @db[
|
29
|
+
row = @db[sql, "zone_#{zone}"].first or next
|
30
30
|
begin
|
31
31
|
tmp.add(row[:value], zone)
|
32
32
|
rescue ArgumentError
|
data/regurgitator.gemspec
CHANGED
@@ -1,29 +1,24 @@
|
|
1
1
|
# -*- encoding: binary -*-
|
2
|
-
|
3
|
-
|
4
|
-
require 'olddoc'
|
5
|
-
extend Olddoc::Gemspec
|
6
|
-
name, summary, title = readme_metadata
|
2
|
+
manifest = File.exist?('.manifest') ?
|
3
|
+
IO.readlines('.manifest').map!(&:chomp!) : `git ls-files`.split("\n")
|
7
4
|
|
8
5
|
Gem::Specification.new do |s|
|
9
6
|
s.name = %q{regurgitator}
|
10
|
-
s.version = ENV[
|
11
|
-
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
|
7
|
+
s.version = (ENV['VERSION'].dup || '0.9.0')
|
8
|
+
s.authors = ['regurgitator hackers']
|
9
|
+
s.description = File.read('README').split("\n\n")[1]
|
10
|
+
s.email = %q{regurgitator-public@bogomips.org}
|
11
|
+
s.extra_rdoc_files = IO.readlines('.document').map!(&:chomp!).keep_if do |f|
|
12
|
+
File.exist?(f)
|
13
|
+
end
|
16
14
|
s.files = manifest
|
17
|
-
s.homepage =
|
18
|
-
s.summary =
|
15
|
+
s.homepage = 'https://bogomips.org/regurgitator/'
|
16
|
+
s.summary = 'regurgitator - read-only Rack endpoints for MogileFS'
|
19
17
|
s.test_files = Dir["test/test_*.rb"]
|
20
|
-
|
21
18
|
s.add_dependency("rack", ['~> 2.0'])
|
22
19
|
s.add_dependency("sequel", ["~> 4.0"])
|
23
20
|
s.add_dependency("http_spew", ['~> 0.5'])
|
24
21
|
s.add_dependency("rpatricia", ["~> 1.0"])
|
25
|
-
s.add_development_dependency('olddoc', "~> 1.0")
|
26
|
-
|
27
22
|
s.required_ruby_version = '>= 2.1'
|
28
23
|
s.licenses = %w(GPL-2.0+)
|
29
24
|
end
|
data/t/t0002-domain_host.sh
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/bin/sh
|
2
2
|
. ./test-lib.sh
|
3
|
-
t_plan
|
3
|
+
t_plan 8 "DomainHost tests"
|
4
4
|
|
5
5
|
t_begin "setup" && {
|
6
6
|
setup domain_host.ru
|
@@ -50,11 +50,14 @@ t_begin "reproxy existing file" && {
|
|
50
50
|
grep '^< Etag: "1"' $curl_err
|
51
51
|
}
|
52
52
|
|
53
|
-
t_begin "
|
53
|
+
t_begin "update host name and sleep 16s for cache refresh" && {
|
54
54
|
sqlite3 $db <<EOF
|
55
55
|
UPDATE domain SET namespace = 'i-have-a-cname.example.org'
|
56
56
|
WHERE namespace = 'd';
|
57
57
|
EOF
|
58
|
+
}
|
59
|
+
|
60
|
+
t_begin 'retry using CNAME host name' && {
|
58
61
|
sleep 16
|
59
62
|
cksum="$(curl -sSvf 2> $curl_err \
|
60
63
|
-H Host:i-have-a-cname.example.org \
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regurgitator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- regurgitator hackers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -66,41 +66,14 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: olddoc
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.0'
|
83
69
|
description: |-
|
84
70
|
regurgitator is a GPL-licensed library and Rack middleware for
|
85
71
|
serving files stored in MogileFS. It can be embedded inside
|
86
72
|
any existing Rack application or be used as a standalone Rack app.
|
87
|
-
email:
|
73
|
+
email: regurgitator-public@bogomips.org
|
88
74
|
executables: []
|
89
75
|
extensions: []
|
90
76
|
extra_rdoc_files:
|
91
|
-
- lib/regurgitator.rb
|
92
|
-
- lib/regurgitator/device.rb
|
93
|
-
- lib/regurgitator/domain.rb
|
94
|
-
- lib/regurgitator/domain_host.rb
|
95
|
-
- lib/regurgitator/domain_path.rb
|
96
|
-
- lib/regurgitator/endpoint.rb
|
97
|
-
- lib/regurgitator/file_info.rb
|
98
|
-
- lib/regurgitator/file_request.rb
|
99
|
-
- lib/regurgitator/list_keys.rb
|
100
|
-
- lib/regurgitator/local.rb
|
101
|
-
- lib/regurgitator/local_file.rb
|
102
|
-
- lib/regurgitator/one_domain.rb
|
103
|
-
- lib/regurgitator/server_settings.rb
|
104
77
|
- NEWS
|
105
78
|
- README
|
106
79
|
- LICENSE
|
@@ -172,10 +145,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
145
|
version: '0'
|
173
146
|
requirements: []
|
174
147
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.6.
|
148
|
+
rubygems_version: 2.6.12
|
176
149
|
signing_key:
|
177
150
|
specification_version: 4
|
178
|
-
summary: read-only Rack endpoints for MogileFS
|
151
|
+
summary: regurgitator - read-only Rack endpoints for MogileFS
|
179
152
|
test_files:
|
180
153
|
- test/test_local.rb
|
181
154
|
- test/test_server_settings.rb
|