higgs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/ChangeLog +208 -0
  2. data/LICENSE +26 -0
  3. data/README +2 -0
  4. data/Rakefile +75 -0
  5. data/bin/higgs_backup +67 -0
  6. data/bin/higgs_dump_index +43 -0
  7. data/bin/higgs_dump_jlog +42 -0
  8. data/bin/higgs_verify +37 -0
  9. data/lib/cgi/session/higgs.rb +72 -0
  10. data/lib/higgs/block.rb +192 -0
  11. data/lib/higgs/cache.rb +117 -0
  12. data/lib/higgs/dbm.rb +55 -0
  13. data/lib/higgs/exceptions.rb +31 -0
  14. data/lib/higgs/flock.rb +77 -0
  15. data/lib/higgs/index.rb +164 -0
  16. data/lib/higgs/jlog.rb +159 -0
  17. data/lib/higgs/lock.rb +189 -0
  18. data/lib/higgs/storage.rb +1086 -0
  19. data/lib/higgs/store.rb +228 -0
  20. data/lib/higgs/tar.rb +390 -0
  21. data/lib/higgs/thread.rb +370 -0
  22. data/lib/higgs/tman.rb +513 -0
  23. data/lib/higgs/utils/bman.rb +285 -0
  24. data/lib/higgs/utils.rb +22 -0
  25. data/lib/higgs/version.rb +21 -0
  26. data/lib/higgs.rb +59 -0
  27. data/misc/cache_bench/cache_bench.rb +43 -0
  28. data/misc/dbm_bench/.strc +8 -0
  29. data/misc/dbm_bench/Rakefile +78 -0
  30. data/misc/dbm_bench/dbm_multi_thread.rb +199 -0
  31. data/misc/dbm_bench/dbm_rnd_delete.rb +43 -0
  32. data/misc/dbm_bench/dbm_rnd_read.rb +44 -0
  33. data/misc/dbm_bench/dbm_rnd_update.rb +44 -0
  34. data/misc/dbm_bench/dbm_seq_read.rb +45 -0
  35. data/misc/dbm_bench/dbm_seq_write.rb +44 -0
  36. data/misc/dbm_bench/st_verify.rb +28 -0
  37. data/misc/io_bench/cksum_bench.rb +48 -0
  38. data/misc/io_bench/jlog_bench.rb +71 -0
  39. data/misc/io_bench/write_bench.rb +128 -0
  40. data/misc/thread_bench/lock_bench.rb +132 -0
  41. data/mkrdoc.rb +8 -0
  42. data/rdoc.yml +13 -0
  43. data/sample/count.rb +60 -0
  44. data/sample/dbmtest.rb +38 -0
  45. data/test/Rakefile +45 -0
  46. data/test/run.rb +32 -0
  47. data/test/test_block.rb +163 -0
  48. data/test/test_cache.rb +214 -0
  49. data/test/test_cgi_session.rb +142 -0
  50. data/test/test_flock.rb +162 -0
  51. data/test/test_index.rb +258 -0
  52. data/test/test_jlog.rb +180 -0
  53. data/test/test_lock.rb +320 -0
  54. data/test/test_online_backup.rb +169 -0
  55. data/test/test_storage.rb +439 -0
  56. data/test/test_storage_conf.rb +202 -0
  57. data/test/test_storage_init_opts.rb +89 -0
  58. data/test/test_store.rb +211 -0
  59. data/test/test_tar.rb +432 -0
  60. data/test/test_thread.rb +541 -0
  61. data/test/test_tman.rb +875 -0
  62. data/test/test_tman_init_opts.rb +56 -0
  63. data/test/test_utils_bman.rb +234 -0
  64. metadata +115 -0
@@ -0,0 +1,56 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'higgs/tman'
4
+ require 'test/unit'
5
+ require 'yaml'
6
+
7
+ module Higgs::Test
8
+ class TransactionManagerInitOptionsTest < Test::Unit::TestCase
9
+ # for ident(1)
10
+ CVS_ID = '$Id: test_tman_init_opts.rb 559 2007-09-25 15:20:20Z toki $'
11
+
12
+ include Higgs::TransactionManager::InitOptions
13
+
14
+ def test_default
15
+ init_options({})
16
+ assert_equal(false, @read_only)
17
+ assert_equal(false, self.read_only)
18
+ assert_equal(:foo, @decode.call(:foo))
19
+ assert_equal(:bar, @encode.call(:bar))
20
+ assert_instance_of(Higgs::GiantLockManager, @lock_manager) # auto: require 'higgs/lock'
21
+ assert_instance_of(Higgs::LRUCache, @master_cache) # auto: require 'higgs/cache'
22
+ end
23
+
24
+ def test_read_only_true
25
+ init_options(:read_only => true)
26
+ assert_equal(true, @read_only)
27
+ assert_equal(true, self.read_only)
28
+ end
29
+
30
+ def test_read_only_false
31
+ init_options(:read_only => false)
32
+ assert_equal(false, @read_only)
33
+ assert_equal(false, self.read_only)
34
+ end
35
+
36
+ def test_decode
37
+ init_options(:decode => proc{|r| YAML.load(r) })
38
+ assert_equal([ 1, 2, 3], @decode.call([ 1, 2, 3 ].to_yaml))
39
+ end
40
+
41
+ def test_encode
42
+ init_options(:encode => proc{|w| w.to_yaml })
43
+ assert_equal([ 1, 2, 3 ].to_yaml, @encode.call([ 1, 2, 3 ]))
44
+ end
45
+
46
+ def test_lock_manager
47
+ init_options(:lock_manager => :dummy_lock_manager)
48
+ assert_equal(:dummy_lock_manager, @lock_manager)
49
+ end
50
+
51
+ def test_master_cache
52
+ init_options(:master_cache => :dummy_master_cache)
53
+ assert_equal(:dummy_master_cache, @master_cache)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,234 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'fileutils'
4
+ require 'higgs/thread'
5
+ require 'higgs/utils/bman'
6
+ require 'logger'
7
+ require 'test/unit'
8
+
9
+ module Higgs::Test
10
+ class UtilsBackupManagerTest < Test::Unit::TestCase
11
+ include Higgs
12
+
13
+ # for ident(1)
14
+ CVS_ID = '$Id: test_utils_bman.rb 567 2007-09-29 06:44:00Z toki $'
15
+
16
+ STORAGE_ITEMS = (ENV['STORAGE_ITEMS'] || '100').to_i
17
+ WARM_START_ITEMS = (ENV['WARM_START_ITEMS'] || '1000').to_i
18
+ MAX_ITEM_BYTES = (ENV['MAX_ITEM_BYTES'] || '16384').to_i
19
+ ITEM_CHARS = ('A'..'Z').to_a + ('a'..'z').to_a
20
+
21
+ def setup
22
+ srand(0)
23
+ @from_dir = 'bman_from'
24
+ @from_name = 'foo'
25
+ @from = File.join(@from_dir, @from_name)
26
+ @to_dir = 'bman_to'
27
+ @to_name = 'bar'
28
+ FileUtils.rm_rf(@from_dir) # for debug
29
+ FileUtils.mkdir_p(@from_dir)
30
+ FileUtils.rm_rf(@to_dir) # for debug
31
+ FileUtils.mkdir_p(@to_dir)
32
+ @jlog_rotate_service_uri = 'druby://localhost:17320'
33
+ @from_st = Storage.new(@from,
34
+ :jlog_rotate_max => 0,
35
+ :jlog_rotate_service_uri => @jlog_rotate_service_uri,
36
+ :logger => proc{|path|
37
+ logger = Logger.new(path, 1)
38
+ logger.level = Logger::DEBUG
39
+ logger
40
+ })
41
+ @bman = Utils::BackupManager.new(:from => @from,
42
+ :to_dir => @to_dir,
43
+ :to_name => @to_name,
44
+ :jlog_rotate_service_uri => @jlog_rotate_service_uri,
45
+ :verbose => $DEBUG ? 2 : 0)
46
+ end
47
+
48
+ def teardown
49
+ @from_st.shutdown
50
+ DRb.stop_service # Why cannot each service be stopped?
51
+ FileUtils.rm_rf(@from_dir) unless $DEBUG
52
+ FileUtils.rm_rf(@to_dir) unless $DEBUG
53
+ end
54
+
55
+ def test_backup_index
56
+ @bman.backup_index
57
+ assert((File.exist? File.join(@to_dir, @to_name + '.idx')))
58
+ end
59
+
60
+ def test_backup_data
61
+ @bman.backup_data
62
+ assert(FileUtils.cmp(@from + '.tar', File.join(@to_dir, @to_name + '.tar')))
63
+ end
64
+
65
+ def test_rotate_jlog_0
66
+ assert_equal(0, Storage.rotate_entries(@from + '.jlog').length)
67
+ end
68
+
69
+ def test_rotate_jlog_1
70
+ @bman.rotate_jlog
71
+ assert_equal(1, Storage.rotate_entries(@from + '.jlog').length)
72
+ end
73
+
74
+ def test_rotate_jlog_2
75
+ @bman.rotate_jlog
76
+ @bman.rotate_jlog
77
+ assert_equal(2, Storage.rotate_entries(@from + '.jlog').length)
78
+ end
79
+
80
+ def test_rotate_jlog_10
81
+ 10.times do
82
+ @bman.rotate_jlog
83
+ end
84
+ assert_equal(10, Storage.rotate_entries(@from + '.jlog').length)
85
+ end
86
+
87
+ def test_backup_jlog_0
88
+ @bman.backup_jlog
89
+ assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
90
+ end
91
+
92
+ def test_backup_jlog_1
93
+ @bman.rotate_jlog
94
+ @bman.backup_jlog
95
+ assert_equal(1, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
96
+ end
97
+
98
+ def test_backup_jlog_2
99
+ @bman.rotate_jlog
100
+ @bman.rotate_jlog
101
+ @bman.backup_jlog
102
+ assert_equal(2, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
103
+ end
104
+
105
+ def test_backup_jlog_10
106
+ 10.times do
107
+ @bman.rotate_jlog
108
+ end
109
+ @bman.backup_jlog
110
+ assert_equal(10, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
111
+ end
112
+
113
+ def test_clean_jlog
114
+ @bman.rotate_jlog
115
+ @bman.rotate_jlog
116
+ @bman.rotate_jlog
117
+ @bman.backup_jlog
118
+
119
+ assert_equal(3, Storage.rotate_entries(@from + '.jlog').length)
120
+ assert_equal(3, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
121
+
122
+ @bman.clean_jlog
123
+ assert_equal(0, Storage.rotate_entries(@from + '.jlog').length)
124
+ assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
125
+ end
126
+
127
+ def test_clean_jlog_delete_backup
128
+ @bman.rotate_jlog
129
+ @bman.rotate_jlog
130
+ @bman.rotate_jlog
131
+ @bman.backup_jlog
132
+ @bman.rotate_jlog
133
+
134
+ assert_equal(4, Storage.rotate_entries(@from + '.jlog').length)
135
+ assert_equal(3, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
136
+
137
+ @bman.clean_jlog
138
+ assert_equal(1, Storage.rotate_entries(@from + '.jlog').length)
139
+ assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
140
+ end
141
+
142
+ def test_clean_jlog_no_backup_no_delete
143
+ @bman.rotate_jlog
144
+ @bman.rotate_jlog
145
+ @bman.rotate_jlog
146
+
147
+ assert_equal(3, Storage.rotate_entries(@from + '.jlog').length)
148
+ assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
149
+
150
+ @bman.clean_jlog
151
+ assert_equal(3, Storage.rotate_entries(@from + '.jlog').length)
152
+ assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
153
+ end
154
+
155
+ def update_storage(options)
156
+ count = 0
157
+ while (options[:spin_lock])
158
+ count += 1
159
+ options[:end_of_warm_up].start if (count == WARM_START_ITEMS)
160
+
161
+ write_list = []
162
+ ope = [ :write, :system_properties, :custom_properties, :delete ][rand(3)]
163
+ key = rand(STORAGE_ITEMS)
164
+ case (ope)
165
+ when :write
166
+ value = rand(256).chr * rand(MAX_ITEM_BYTES)
167
+ write_list << [ ope, key, value ]
168
+ when :system_properties
169
+ next unless (@from_st.key? key)
170
+ write_list << [ ope, key, { 'string_only' => [ true, false ][rand(2)] } ]
171
+ when :custom_properties
172
+ next unless (@from_st.key? key)
173
+ value = ITEM_CHARS[rand(ITEM_CHARS.size)] * rand(MAX_ITEM_BYTES)
174
+ write_list << [ ope, key, { 'foo' => value } ]
175
+ when :delete
176
+ next unless (@from_st.key? key)
177
+ write_list << [ ope, key ]
178
+ else
179
+ raise "unknown operation: #{ope}"
180
+ end
181
+ @from_st.write_and_commit(write_list)
182
+ end
183
+ end
184
+ private :update_storage
185
+
186
+ def test_recover_and_verify_and_clean_jlog
187
+ options = {
188
+ :end_of_warm_up => Latch.new,
189
+ :spin_lock => true
190
+ }
191
+ t = Thread.new{ update_storage(options) }
192
+
193
+ options[:end_of_warm_up].wait
194
+ @bman.backup_index
195
+ @bman.backup_data
196
+ options[:spin_lock] = false
197
+ t.join
198
+
199
+ @bman.rotate_jlog
200
+ @bman.backup_jlog
201
+ @bman.recover
202
+ @bman.verify
203
+ @bman.clean_jlog
204
+
205
+ assert(FileUtils.cmp(@from + '.tar', File.join(@to_dir, @to_name + '.tar')))
206
+ assert_equal(Index.new.load(@from + '.idx').to_h,
207
+ Index.new.load(File.join(@to_dir, @to_name + '.idx')).to_h)
208
+ assert_equal(0, Storage.rotate_entries(@from + '.jlog').length)
209
+ assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
210
+ end
211
+
212
+ def test_online_backup
213
+ options = {
214
+ :end_of_warm_up => Latch.new,
215
+ :spin_lock => true
216
+ }
217
+ t = Thread.new{ update_storage(options) }
218
+
219
+ options[:end_of_warm_up].wait
220
+ @bman.online_backup
221
+ options[:spin_lock] = false
222
+ t.join
223
+
224
+ assert((File.file? File.join(@to_dir, @to_name + '.tar')))
225
+ assert((File.file? File.join(@to_dir, @to_name + '.idx')))
226
+ assert_equal(0, Storage.rotate_entries(File.join(@to_dir, @to_name + '.jlog')).length)
227
+ end
228
+ end
229
+ end
230
+
231
+ # Local Variables:
232
+ # mode: Ruby
233
+ # indent-tabs-mode: nil
234
+ # End:
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: higgs
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-09-29 00:00:00 +09:00
8
+ summary: pure ruby transactional storage compatible with unix TAR format
9
+ require_paths:
10
+ - lib
11
+ email: toki@freedom.ne.jp
12
+ homepage:
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - TOKI Yoshinori
31
+ files:
32
+ - misc/dbm_bench/Rakefile
33
+ - test/Rakefile
34
+ - Rakefile
35
+ - misc/dbm_bench/.strc
36
+ - lib/cgi/session/higgs.rb
37
+ - lib/higgs/jlog.rb
38
+ - lib/higgs/utils/bman.rb
39
+ - lib/higgs/exceptions.rb
40
+ - lib/higgs/cache.rb
41
+ - lib/higgs/lock.rb
42
+ - lib/higgs/thread.rb
43
+ - lib/higgs/block.rb
44
+ - lib/higgs/dbm.rb
45
+ - lib/higgs/tman.rb
46
+ - lib/higgs/storage.rb
47
+ - lib/higgs/tar.rb
48
+ - lib/higgs/index.rb
49
+ - lib/higgs/flock.rb
50
+ - lib/higgs/store.rb
51
+ - lib/higgs/version.rb
52
+ - lib/higgs/utils.rb
53
+ - lib/higgs.rb
54
+ - misc/cache_bench/cache_bench.rb
55
+ - misc/thread_bench/lock_bench.rb
56
+ - misc/dbm_bench/dbm_seq_read.rb
57
+ - misc/dbm_bench/dbm_rnd_read.rb
58
+ - misc/dbm_bench/dbm_multi_thread.rb
59
+ - misc/dbm_bench/dbm_seq_write.rb
60
+ - misc/dbm_bench/st_verify.rb
61
+ - misc/dbm_bench/dbm_rnd_delete.rb
62
+ - misc/dbm_bench/dbm_rnd_update.rb
63
+ - misc/io_bench/write_bench.rb
64
+ - misc/io_bench/cksum_bench.rb
65
+ - misc/io_bench/jlog_bench.rb
66
+ - test/test_cgi_session.rb
67
+ - test/test_utils_bman.rb
68
+ - test/test_lock.rb
69
+ - test/test_thread.rb
70
+ - test/test_cache.rb
71
+ - test/test_storage_init_opts.rb
72
+ - test/test_tman.rb
73
+ - test/test_block.rb
74
+ - test/test_storage_conf.rb
75
+ - test/test_tar.rb
76
+ - test/run.rb
77
+ - test/test_storage.rb
78
+ - test/test_index.rb
79
+ - test/test_tman_init_opts.rb
80
+ - test/test_flock.rb
81
+ - test/test_store.rb
82
+ - test/test_jlog.rb
83
+ - test/test_online_backup.rb
84
+ - mkrdoc.rb
85
+ - sample/count.rb
86
+ - sample/dbmtest.rb
87
+ - rdoc.yml
88
+ - bin/higgs_backup
89
+ - bin/higgs_dump_index
90
+ - bin/higgs_dump_jlog
91
+ - bin/higgs_verify
92
+ - ChangeLog
93
+ - LICENSE
94
+ - README
95
+ test_files:
96
+ - test/run.rb
97
+ rdoc_options:
98
+ - -SNa
99
+ - -i
100
+ - .
101
+ - -m
102
+ - Higgs
103
+ extra_rdoc_files: []
104
+
105
+ executables:
106
+ - higgs_backup
107
+ - higgs_dump_index
108
+ - higgs_dump_jlog
109
+ - higgs_verify
110
+ extensions: []
111
+
112
+ requirements: []
113
+
114
+ dependencies: []
115
+