higgs 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,8 +1,22 @@
1
+ 2007-10-12 TOKI Yoshinori <toki@freedom.ne.jp>
2
+
3
+ * lib/higgs/version.rb: version 0.1.2.
4
+
5
+ 2007-10-10 TOKI Yoshinori <toki@freedom.ne.jp>
6
+
7
+ * lib/higgs/storage.rb (Higgs::Storage class),
8
+ lib/higgs/utils/bman.rb (Higgs::Utils::BackupManager class): fixed
9
+ some close leakage bugs of file lock in the error case of
10
+ recovery.
11
+
12
+ * lib/higgs/flock.rb (Higgs::FileLock class): open with block.
13
+
1
14
  2007-10-08 TOKI Yoshinori <toki@freedom.ne.jp>
2
15
 
3
16
  * lib/higgs/version.rb: version 0.1.1.
4
17
 
5
- * lib/higgs/utils/bman.rb: added variation of incremental backup.
18
+ * lib/higgs/utils/bman.rb (Higgs::Utils::BackupManager class):
19
+ added variation of incremental backup.
6
20
 
7
21
  * bin/higgs_backup: changed command line syntax. added restore
8
22
  commands.
data/lib/higgs/flock.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # = file lock
2
2
  #
3
3
  # Author:: $Author: toki $
4
- # Date:: $Date: 2007-09-26 00:20:20 +0900 (Wed, 26 Sep 2007) $
5
- # Revision:: $Revision: 559 $
4
+ # Date:: $Date: 2007-10-10 00:49:33 +0900 (Wed, 10 Oct 2007) $
5
+ # Revision:: $Revision: 626 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
@@ -11,7 +11,7 @@
11
11
  module Higgs
12
12
  class FileLock
13
13
  # for ident(1)
14
- CVS_ID = '$Id: flock.rb 559 2007-09-25 15:20:20Z toki $'
14
+ CVS_ID = '$Id: flock.rb 626 2007-10-09 15:49:33Z toki $'
15
15
 
16
16
  def initialize(path, read_only=false)
17
17
  @path = path
@@ -68,6 +68,16 @@ module Higgs
68
68
 
69
69
  r
70
70
  end
71
+
72
+ def self.open(*args)
73
+ flock = new(*args)
74
+ begin
75
+ r = yield(flock)
76
+ ensure
77
+ flock.close
78
+ end
79
+ r
80
+ end
71
81
  end
72
82
  end
73
83
 
data/lib/higgs/storage.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # = transactional storage core
2
2
  #
3
3
  # Author:: $Author: toki $
4
- # Date:: $Date: 2007-10-05 02:35:02 +0900 (Fri, 05 Oct 2007) $
5
- # Revision:: $Revision: 614 $
4
+ # Date:: $Date: 2007-10-10 00:49:33 +0900 (Wed, 10 Oct 2007) $
5
+ # Revision:: $Revision: 626 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
@@ -23,7 +23,7 @@ module Higgs
23
23
  # = transactional storage core
24
24
  class Storage
25
25
  # for ident(1)
26
- CVS_ID = '$Id: storage.rb 614 2007-10-04 17:35:02Z toki $'
26
+ CVS_ID = '$Id: storage.rb 626 2007-10-09 15:49:33Z toki $'
27
27
 
28
28
  extend Forwardable
29
29
  include Exceptions
@@ -837,41 +837,41 @@ module Higgs
837
837
  jlog_name = "#{name}.jlog"
838
838
  lock_name = "#{name}.lock"
839
839
 
840
- flock = FileLock.new(lock_name)
841
- flock.synchronize{
842
- begin
843
- w_io = File.open(tar_name, File::WRONLY | File::CREAT | File::EXCL, 0660)
844
- rescue Errno::EEXIST
845
- w_io = File.open(tar_name, File::WRONLY, 0660)
846
- end
847
- w_io.binmode
848
- w_tar = Tar::ArchiveWriter.new(w_io)
840
+ FileLock.open(lock_name) {|flock|
841
+ flock.synchronize{
842
+ begin
843
+ w_io = File.open(tar_name, File::WRONLY | File::CREAT | File::EXCL, 0660)
844
+ rescue Errno::EEXIST
845
+ w_io = File.open(tar_name, File::WRONLY, 0660)
846
+ end
847
+ w_io.binmode
848
+ w_tar = Tar::ArchiveWriter.new(w_io)
849
849
 
850
- index = Index.new
851
- index.load(idx_name) if (File.exist? idx_name)
850
+ index = Index.new
851
+ index.load(idx_name) if (File.exist? idx_name)
852
852
 
853
- out << "recovery target: #{name}\n" if (out && verbose_level >= 1)
854
- jlog_list = rotate_entries(jlog_name)
855
- jlog_list << jlog_name if (File.exist? jlog_name)
856
- for curr_name in jlog_list
857
- begin
858
- JournalLogger.each_log(curr_name) do |log|
859
- change_number = log[0]
860
- out << "apply journal log: #{change_number}\n" if (out && verbose_level >= 1)
861
- apply_journal(w_tar, index, log)
853
+ out << "recovery target: #{name}\n" if (out && verbose_level >= 1)
854
+ jlog_list = rotate_entries(jlog_name)
855
+ jlog_list << jlog_name if (File.exist? jlog_name)
856
+ for curr_name in jlog_list
857
+ begin
858
+ JournalLogger.each_log(curr_name) do |log|
859
+ change_number = log[0]
860
+ out << "apply journal log: #{change_number}\n" if (out && verbose_level >= 1)
861
+ apply_journal(w_tar, index, log)
862
+ end
863
+ rescue Block::BrokenError
864
+ out << "warning: incompleted journal log and stopped at #{curr_name}\n" if out
862
865
  end
863
- rescue Block::BrokenError
864
- out << "warning: incompleted journal log and stopped at #{curr_name}\n" if out
865
866
  end
866
- end
867
- w_tar.seek(index.eoa)
868
- w_tar.write_EOA
867
+ w_tar.seek(index.eoa)
868
+ w_tar.write_EOA
869
869
 
870
- index.save(idx_name)
871
- w_tar.fsync
872
- w_tar.close(false)
870
+ index.save(idx_name)
871
+ w_tar.fsync
872
+ w_tar.close(false)
873
+ }
873
874
  }
874
- flock.close
875
875
 
876
876
  nil
877
877
  end
@@ -1,8 +1,8 @@
1
1
  # = backup manager
2
2
  #
3
3
  # Author:: $Author: toki $
4
- # Date:: $Date: 2007-10-08 22:10:08 +0900 (Mon, 08 Oct 2007) $
5
- # Revision:: $Revision: 621 $
4
+ # Date:: $Date: 2007-10-10 00:49:33 +0900 (Wed, 10 Oct 2007) $
5
+ # Revision:: $Revision: 626 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
@@ -146,7 +146,7 @@ module Higgs
146
146
  # as <tt>BACKUP_TARGET_STORAGE</tt>.
147
147
  #
148
148
  # === OPTION: <tt>--jlog-rotate-service-uri=URI</tt>
149
- # access point journal log rotation remote service.
149
+ # access point for journal log rotation remote service.
150
150
  # <tt>URI</tt> is the same as <tt>:jlog_rotate_service_uri</tt>
151
151
  # when Higgs::Storage is opened.
152
152
  #
@@ -158,7 +158,7 @@ module Higgs
158
158
  #
159
159
  class BackupManager
160
160
  # for ident(1)
161
- CVS_ID = '$Id: bman.rb 621 2007-10-08 13:10:08Z toki $'
161
+ CVS_ID = '$Id: bman.rb 626 2007-10-09 15:49:33Z toki $'
162
162
 
163
163
  def initialize(options={})
164
164
  @from = options[:from]
@@ -326,14 +326,16 @@ module Higgs
326
326
  unless (@to) then
327
327
  raise 'required to_storage'
328
328
  end
329
- FileLock.new("#{@from}.lock").synchronize{
330
- FileUtils.cp("#{@to}.idx", "#{@from}.idx", :preserve => true, :verbose => @verbose >= 2)
331
- FileUtils.cp("#{@to}.tar", "#{@from}.tar", :preserve => true, :verbose => @verbose >= 2)
332
- for path in Storage.rotate_entries("#{@to}.jlog")
333
- path =~ /\.jlog\.\d+$/ or raise "mismatch jlog name: #{path}"
334
- ext = $&
335
- FileUtils.cp(path, "#{@from}#{ext}", :preserve => true, :verbose => @verbose >= 2)
336
- end
329
+ FileLock.open("#{@from}.lock") {|flock|
330
+ flock.synchronize{
331
+ FileUtils.cp("#{@to}.idx", "#{@from}.idx", :preserve => true, :verbose => @verbose >= 2)
332
+ FileUtils.cp("#{@to}.tar", "#{@from}.tar", :preserve => true, :verbose => @verbose >= 2)
333
+ for path in Storage.rotate_entries("#{@to}.jlog")
334
+ path =~ /\.jlog\.\d+$/ or raise "mismatch jlog name: #{path}"
335
+ ext = $&
336
+ FileUtils.cp(path, "#{@from}#{ext}", :preserve => true, :verbose => @verbose >= 2)
337
+ end
338
+ }
337
339
  }
338
340
  @out << log('completed storage files restore.') if (@verbose >= 1)
339
341
  nil
data/lib/higgs/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # = version
2
2
  #
3
3
  # Author:: $Author: toki $
4
- # Date:: $Date: 2007-10-08 22:16:13 +0900 (Mon, 08 Oct 2007) $
5
- # Revision:: $Revision: 622 $
4
+ # Date:: $Date: 2007-10-12 16:19:52 +0900 (Fri, 12 Oct 2007) $
5
+ # Revision:: $Revision: 628 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
@@ -10,9 +10,9 @@
10
10
 
11
11
  module Higgs
12
12
  # for ident(1)
13
- CVS_ID = '$Id: version.rb 622 2007-10-08 13:16:13Z toki $'
13
+ CVS_ID = '$Id: version.rb 628 2007-10-12 07:19:52Z toki $'
14
14
 
15
- VERSION = '0.1.1'
15
+ VERSION = '0.1.2'
16
16
  end
17
17
 
18
18
  # Local Variables:
@@ -30,7 +30,7 @@ module Higgs::Test
30
30
  include OnlineBackupParams
31
31
 
32
32
  # for ident(1)
33
- CVS_ID = '$Id: test_online_backup.rb 584 2007-09-29 15:05:15Z toki $'
33
+ CVS_ID = '$Id: test_online_backup.rb 627 2007-10-12 07:10:13Z toki $'
34
34
 
35
35
  def setup
36
36
  srand(0)
@@ -143,9 +143,9 @@ module Higgs::Test
143
143
  Storage.recover(@restore_name)
144
144
 
145
145
  # recovered files are same as original files.
146
- assert(FileUtils.cmp("#{@backup_name}.tar", "#{@restore_name}.tar"), 'tar')
146
+ assert(FileUtils.cmp("#{@backup_name}.tar", "#{@restore_name}.tar"), 'data')
147
147
  assert_equal(Index.new.load("#{@backup_name}.idx").to_h,
148
- Index.new.load("#{@restore_name}.idx").to_h, 'idx')
148
+ Index.new.load("#{@restore_name}.idx").to_h, 'index')
149
149
  ensure
150
150
  FileUtils.touch(@stop_latch)
151
151
  FileUtils.touch(@end_latch)
data/test/test_storage.rb CHANGED
@@ -10,7 +10,7 @@ module Higgs::Test
10
10
  include Higgs
11
11
 
12
12
  # for ident(1)
13
- CVS_ID = '$Id: test_storage.rb 609 2007-10-04 16:27:39Z toki $'
13
+ CVS_ID = '$Id: test_storage.rb 627 2007-10-12 07:10:13Z toki $'
14
14
 
15
15
  def setup
16
16
  srand(0) # preset for rand
@@ -36,7 +36,7 @@ module Higgs::Test
36
36
  include StorageTestCase
37
37
 
38
38
  # for ident(1)
39
- CVS_ID = '$Id: test_storage.rb 609 2007-10-04 16:27:39Z toki $'
39
+ CVS_ID = '$Id: test_storage.rb 627 2007-10-12 07:10:13Z toki $'
40
40
 
41
41
  def new_storage
42
42
  Storage.new(@name, :logger => @logger)
@@ -372,7 +372,7 @@ module Higgs::Test
372
372
  include StorageTestCase
373
373
 
374
374
  # for ident(1)
375
- CVS_ID = '$Id: test_storage.rb 609 2007-10-04 16:27:39Z toki $'
375
+ CVS_ID = '$Id: test_storage.rb 627 2007-10-12 07:10:13Z toki $'
376
376
 
377
377
  def new_storage
378
378
  Storage.new(@name,
@@ -421,8 +421,9 @@ module Higgs::Test
421
421
  end
422
422
  Storage.recover(other_name)
423
423
 
424
- assert(FileUtils.cmp("#{@name}.tar", "#{other_name}.tar"), 'tar')
425
- assert(FileUtils.cmp("#{@name}.idx", "#{other_name}.idx"), 'idx')
424
+ assert(FileUtils.cmp("#{@name}.tar", "#{other_name}.tar"), 'data')
425
+ assert(Index.new.load("#{@name}.idx").to_h ==
426
+ Index.new.load("#{other_name}.idx").to_h, 'index')
426
427
  end
427
428
 
428
429
  def test_auto_recovery
@@ -445,9 +446,10 @@ module Higgs::Test
445
446
  st2 = Storage.new(other_name, :logger => @logger)
446
447
  st2.shutdown
447
448
 
448
- assert(FileUtils.cmp("#{@name}.tar", "#{other_name}.tar"), 'tar')
449
- assert(FileUtils.cmp("#{@name}.idx", "#{other_name}.idx"), 'idx')
450
- assert(FileUtils.cmp("#{@name}.jlog", "#{other_name}.jlog"), 'jlog')
449
+ assert(FileUtils.cmp("#{@name}.tar", "#{other_name}.tar"), 'data')
450
+ assert(Index.new.load("#{@name}.idx").to_h ==
451
+ Index.new.load("#{other_name}.idx").to_h)
452
+ assert(FileUtils.cmp("#{@name}.jlog", "#{other_name}.jlog"), 'index')
451
453
  end
452
454
 
453
455
  def test_lost_journal_log_error
@@ -474,7 +476,7 @@ module Higgs::Test
474
476
  include Higgs
475
477
 
476
478
  # for ident(1)
477
- CVS_ID = '$Id: test_storage.rb 609 2007-10-04 16:27:39Z toki $'
479
+ CVS_ID = '$Id: test_storage.rb 627 2007-10-12 07:10:13Z toki $'
478
480
 
479
481
  def setup
480
482
  @test_dir = 'st_test'
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: higgs
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2007-10-08 00:00:00 +09:00
6
+ version: 0.1.2
7
+ date: 2007-10-12 00:00:00 +09:00
8
8
  summary: pure ruby transactional storage compatible with unix TAR format
9
9
  require_paths:
10
10
  - lib