roma-storage 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+
2
+ module Roma
3
+ module Storage
4
+
5
+ class DummyStorage
6
+
7
+ def initialize; end
8
+ def init(*args); end
9
+ def opendb(fname,divnum); end
10
+ def closedb; end
11
+ def get_context(vn, k, d) nil; end
12
+ def rset(vn, k, d, lclock, exptime, v); end
13
+ def set(vn, k, d, exptime, v); end
14
+ def add(vn, k, d, exptime, v); end
15
+ def replace(vn, k, d, exptime, v); end
16
+ def append(vn, k, d, exptime, v); end
17
+ def prepend(vn, k, d, exptime, v); end
18
+ def get(vn,k,d); 'dummy'; end
19
+ def rdelete(vn,k,d,lclock); end
20
+ def delete(vn,k,d); end
21
+ def incr(vn, k, d, v); end
22
+ def decr(vn, k, d, v); end
23
+ def true_length; 100; end
24
+ def clean_up(t); end
25
+
26
+ def load(dmp); 10 end
27
+
28
+ # Returns the vnode dump.
29
+ def dump(vn)
30
+ Marshal.dump(get_vnode_hash(vn))
31
+ end
32
+
33
+ private
34
+
35
+ # Create vnode dump.
36
+ def get_vnode_hash(vn)
37
+ {'dummy'=>'dummy'}
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,114 @@
1
+ require 'roma/storage/basic_storage'
2
+
3
+ module Roma
4
+ module Storage
5
+
6
+ module RH_Ext
7
+ def put(k,v); self[k] = v; end
8
+ def get(k); self[k]; end
9
+ def out(k); delete(k); end
10
+ def rnum; length; end
11
+ def sync; true; end
12
+ end
13
+
14
+ class RubyHashStorage < BasicStorage
15
+
16
+ def opendb
17
+ create_div_hash
18
+ @divnum.times do |i|
19
+ @hdb[i] = open_db(nil)
20
+ @hdbc[i] = nil
21
+ @dbs[i] = :normal
22
+ end
23
+ end
24
+
25
+ if RUBY_VERSION >= '1.9.2'
26
+ def each_clean_up(t, vnhash)
27
+ @do_clean_up = true
28
+ nt = Time.now.to_i
29
+ @hdb.each{ |hdb|
30
+ keys = hdb.keys
31
+ keys.each{ |k|
32
+ v = hdb[k]
33
+ return unless @do_clean_up
34
+ vn, last, clk, expt = unpack_header(v)
35
+ vn_stat = vnhash[vn]
36
+ if vn_stat == :primary && ( (expt != 0 && nt > expt) || (expt == 0 && t > last) )
37
+ yield k, vn
38
+ hdb.out(k) if hdb.get(k) == v
39
+ elsif vn_stat == nil && t > last
40
+ yield k, vn
41
+ hdb.out(k) if hdb.get(k) == v
42
+ end
43
+ sleep @each_clean_up_sleep
44
+ }
45
+ }
46
+ end
47
+
48
+ def each_unpacked_db(target_vn, db)
49
+ count = 0
50
+ tn = Time.now.to_i
51
+ keys = db[@hdiv[target_vn]].keys
52
+ keys.each do |k|
53
+ v = db[@hdiv[target_vn]][k]
54
+ vn, last, clk, expt, val = unpack_data(v)
55
+ if vn != target_vn || (expt != 0 && tn > expt)
56
+ count += 1
57
+ sleep @each_vn_dump_sleep if count % @each_vn_dump_sleep_count == 0
58
+ next
59
+ end
60
+ yield vn, last, clk, expt, k, val
61
+ end
62
+ end
63
+ private :each_unpacked_db
64
+
65
+
66
+ def each_hdb_dump(i,except_vnh = nil)
67
+ count = 0
68
+ keys = @hdb[i].keys
69
+ keys.each{|k|
70
+ v = @hdb[i][k]
71
+ vn, last, clk, expt, val = unpack_data(v)
72
+ if except_vnh && except_vnh.key?(vn) || Time.now.to_i > expt
73
+ count += 1
74
+ sleep @each_vn_dump_sleep if count % @each_vn_dump_sleep_count == 0
75
+ else
76
+ yield [vn, last, clk, expt, k.length, k, val.length, val].pack("NNNNNa#{k.length}Na#{val.length}")
77
+ sleep @each_vn_dump_sleep
78
+ end
79
+ }
80
+ end
81
+
82
+ # Create vnode dump.
83
+ def get_vnode_hash(vn)
84
+ buf = {}
85
+ count = 0
86
+ hdb = @hdb[@hdiv[vn]]
87
+ keys = hdb.keys
88
+ keys.each{ |k|
89
+ v = hdb[k]
90
+ count += 1
91
+ sleep @each_vn_dump_sleep if count % @each_vn_dump_sleep_count == 0
92
+ dat = unpack_data(v) #v.unpack('NNNN')
93
+ buf[k] = v if dat[0] == vn
94
+ }
95
+ return buf
96
+ end
97
+ private :get_vnode_hash
98
+
99
+ end
100
+
101
+ private
102
+
103
+ def open_db(fname)
104
+ hdb = {}
105
+ hdb.extend(Roma::Storage::RH_Ext)
106
+ return hdb
107
+ end
108
+
109
+ def close_db(hdb); end
110
+
111
+ end # class RubyHashStorage
112
+
113
+ end # module Storage
114
+ end # module Roma
@@ -0,0 +1,5 @@
1
+ module Roma
2
+ module Storage
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "roma/storage/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "roma-storage"
8
+ spec.version = Roma::Storage::VERSION
9
+ spec.authors = ["Tatsuya Sato"]
10
+ spec.email = ["tatsuya.b.sato@rakuten.com"]
11
+
12
+ spec.summary = %q{Storages available for Roma server.}
13
+ spec.description = %q{This gem provides storage classes available for Roma server.}
14
+ spec.homepage = "https://roma-kvs.org/"
15
+ spec.license = "GPL-3.0"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roma-storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tatsuya Sato
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This gem provides storage classes available for Roma server.
56
+ email:
57
+ - tatsuya.b.sato@rakuten.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/roma/storage.rb
73
+ - lib/roma/storage/basic_storage.rb
74
+ - lib/roma/storage/dummy_storage.rb
75
+ - lib/roma/storage/ruby_hash_storage.rb
76
+ - lib/roma/storage/version.rb
77
+ - roma-storage.gemspec
78
+ homepage: https://roma-kvs.org/
79
+ licenses:
80
+ - GPL-3.0
81
+ metadata:
82
+ allowed_push_host: https://rubygems.org
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.7.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Storages available for Roma server.
103
+ test_files: []