higgs 0.1.2 → 0.1.3

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,3 +1,106 @@
1
+ 2007-11-11 TOKI Yoshinori <toki@freedom.ne.jp>
2
+
3
+ * lib/higgs/version.rb: version 0.1.3.
4
+
5
+ 2007-11-10 TOKI Yoshinori <toki@freedom.ne.jp>
6
+
7
+ * bin/higgs_apply_jlog, bin/higgs_ping: some utilities.
8
+
9
+ 2007-11-09 TOKI Yoshinori <toki@freedom.ne.jp>
10
+
11
+ * lib/higgs/storage.rb (Higgs::Storage class): probe for alived
12
+ storage.
13
+
14
+ 2007-11-04 TOKI Yoshinori <toki@freedom.ne.jp>
15
+
16
+ * lib/higgs/storage.rb (Higgs::Storage class): standby mode check.
17
+
18
+ * lib/higgs/tman.rb (Higgs::TransactionManager class),
19
+ lib/higgs/services.rb (Higgs::RemoteServices class),
20
+ lib/higgs/sman.rb (Higgs::StorageManager class):
21
+ some methods for replication.
22
+
23
+ 2007-10-31 TOKI Yoshinori <toki@freedom.ne.jp>
24
+
25
+ * lib/higgs/thread.rb (Higgs::SharedWork class),
26
+ lib/higgs/cache.rb (Higgs::SharedWorkCache class): ArgumentError
27
+ for no block argument.
28
+
29
+ 2007-10-28 TOKI Yoshinori <toki@freedom.ne.jp>
30
+
31
+ * lib/higgs/utils/bman.rb (Higgs::Utils::BackupManager class):
32
+ checked eof-mark of journal log to backup.
33
+
34
+ 2007-10-25 TOKI Yoshinori <toki@freedom.ne.jp>
35
+
36
+ * lib/higgs/storage.rb (Higgs::Storage class): fixed a bug, buffer
37
+ flush of write I/O handle is not done.
38
+
39
+ 2007-10-24 TOKI Yoshinori <toki@freedom.ne.jp>
40
+
41
+ * lib/higgs/storage.rb (Higgs::Storage class): renamed from
42
+ `rotate_entries' to `rotated_entries'.
43
+
44
+ 2007-10-23 TOKI Yoshinori <toki@freedom.ne.jp>
45
+
46
+ * lib/higgs/lock.rb: exclusive block of lock manager.
47
+
48
+ 2007-10-21 TOKI Yoshinori <toki@freedom.ne.jp>
49
+
50
+ * lib/higgs/storage.rb (Higgs::Storage class): storage id
51
+ consistency check on applying journal log.
52
+
53
+ * lib/higgs/index.rb (Higgs::Index class),
54
+ lib/higgs/storage.rb (Higgs::Storage class): storage id.
55
+
56
+ 2007-10-16 TOKI Yoshinori <toki@freedom.ne.jp>
57
+
58
+ * lib/higgs/utils/bman.rb (Higgs::Utils::BackupManager class):
59
+ localhost check for runtime.
60
+
61
+ * lib/higgs/storage.rb (Higgs::Storage class),
62
+ lib/higgs/services.rb (Higgs::RemoteServices class): provided
63
+ localhost check service.
64
+
65
+ 2007-10-14 TOKI Yoshinori <toki@freedom.ne.jp>
66
+
67
+ * lib/higgs/storage.rb, lib/higgs/tman.rb: obsolete
68
+ Higgs::Storage::Export module, obsolete
69
+ Higgs::TransactionManager::Export module.
70
+
71
+ * lib/higgs/sman.rb (Higgs::StorageManager class): base class of
72
+ Higgs::Store and Higgs::DBM. this class integrates Higgs::Storage,
73
+ Higgs::TransactionManager, and Higgs::RemoteServices and is those
74
+ front end.
75
+
76
+ * bin/higgs_backup: obsolete `--jlog-rotate-service-uri=URI'
77
+ option, new `--remote-services-uri=URI' option.
78
+
79
+ * lib/higgs/utils/bman.rb: obsolete `:jlog_rotate_service_uri'
80
+ option, new `:remote_services_uri' option.
81
+
82
+ * lib/higgs/storage.rb (Higgs::Storage class): obsolete
83
+ `:jlog_rotate_service_uri' option. this remote service is
84
+ integrated to Higgs::RemoteServices.
85
+
86
+ * lib/higgs/services.rb (Higgs::RemoteServices class): class to
87
+ integrate remote services.
88
+
89
+ * lib/higgs/storage.rb (Higgs::Storage class): enabled to apply
90
+ journal log to online storage.
91
+
92
+ 2007-10-13 TOKI Yoshinori <toki@freedom.ne.jp>
93
+
94
+ * lib/higgs/storage.rb (Higgs::Storage class): write EOA to
95
+ storage at each applying journal log.
96
+
97
+ * lib/higgs/storage.rb (Higgs::Storage class), lib/higgs/tman.rb
98
+ (Higgs::TransactionManager class, Higgs::TransactionContext
99
+ class): unique data id for secondary cache. index structure
100
+ changed a little.
101
+
102
+ * lib/higgs/tman.rb: fixed a bug of wrong key of secondary cache.
103
+
1
104
  2007-10-12 TOKI Yoshinori <toki@freedom.ne.jp>
2
105
 
3
106
  * lib/higgs/version.rb: version 0.1.2.
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  # for ident(1)
2
- CVS_ID = '$Id: Rakefile 586 2007-09-30 03:03:12Z toki $'
2
+ CVS_ID = '$Id: Rakefile 678 2007-11-09 16:08:34Z toki $'
3
3
 
4
4
  require 'lib/higgs/version'
5
5
  require 'rake/gempackagetask'
@@ -46,7 +46,14 @@ spec = Gem::Specification.new{|s|
46
46
  s.summary = 'pure ruby transactional storage compatible with unix TAR format'
47
47
  s.author = 'TOKI Yoshinori'
48
48
  s.email = 'toki@freedom.ne.jp'
49
- s.executables = %w[ higgs_backup higgs_dump_index higgs_dump_jlog higgs_verify ]
49
+ s.executables = %w[
50
+ higgs_apply_jlog
51
+ higgs_backup
52
+ higgs_dump_index
53
+ higgs_dump_jlog
54
+ higgs_ping
55
+ higgs_verify
56
+ ]
50
57
  s.files = Dir['**/{Rakefile,.strc,*.{rb,yml}}']
51
58
  s.files += %w[ ChangeLog LICENSE README ]
52
59
  s.test_files = %w[ test/run.rb ]
@@ -0,0 +1,35 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'drb'
4
+ require 'optparse'
5
+
6
+ # for ident(1)
7
+ CVS_ID = '$Id: higgs_apply_jlog 680 2007-11-11 02:04:47Z toki $'
8
+
9
+ opt_not_delete = false
10
+ opt_switch_to_write = false
11
+
12
+ opts = OptionParser.new
13
+ opts.banner = "Usage: #{opts.program_name} [OPTIONs] URI_FOR_REMOTE_SERVICES\n"
14
+ opts.banner << "OPTIONs:\n"
15
+ opts.on('-n', '--not-delete') {|value|
16
+ opt_not_delete = value ? true : false
17
+ }
18
+ opts.on('--switch-to-write') {|value|
19
+ opt_switch_to_write = true
20
+ }
21
+ opts.parse!
22
+
23
+ if (ARGV.empty?) then
24
+ puts opts
25
+ exit 1
26
+ end
27
+
28
+ uri = ARGV.shift
29
+ services = DRbObject.new_with_uri(uri)
30
+ jlog_apply_service = services[:jlog_apply_service_v1] or raise 'not provided remote service: jlog_apply_service_v1'
31
+ jlog_apply_service.call(opt_not_delete)
32
+ if (opt_switch_to_write) then
33
+ switch_to_write_service = services[:switch_to_write_service_v1] or raise 'not provided remote service: switch_to_write_service_v1'
34
+ switch_to_write_service.call
35
+ end
data/bin/higgs_backup CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/local/bin/ruby
2
2
 
3
+ require 'drb'
3
4
  require 'higgs/utils/bman'
4
5
  require 'optparse'
5
6
 
6
7
  # for ident(1)
7
- CVS_ID = '$Id: higgs_backup 619 2007-10-08 12:42:36Z toki $'
8
+ CVS_ID = '$Id: higgs_backup 641 2007-10-18 16:04:02Z toki $'
8
9
 
9
10
  STDOUT.sync = true
10
11
 
@@ -42,8 +43,8 @@ opts.on('-t', '--to-dir=DIR_TO_BACKUP', String) {|value|
42
43
  opts.on('-n', '--to-name=NAME_TO_BACKUP', String) {|value|
43
44
  options[:to_name] = value
44
45
  }
45
- opts.on('-u', '--jlog-rotate-service-uri=URI', String) {|value|
46
- options[:jlog_rotate_service_uri] = value
46
+ opts.on('-U', '--remote-services-uri=URI', String) {|value|
47
+ options[:remote_services_uri] = value
47
48
  }
48
49
  opts.on('-v', '--verbose', '--[no-]verbose') {|value|
49
50
  if (value) then
@@ -71,6 +72,7 @@ unless (ARGV.empty?) then
71
72
  commands = ARGV
72
73
  end
73
74
 
75
+ DRb.start_service
74
76
  bman = Higgs::Utils::BackupManager.new(options)
75
77
  for cmd in commands
76
78
  unless (bman.public_methods(false).include? cmd) then
data/bin/higgs_dump_jlog CHANGED
@@ -6,7 +6,7 @@ require 'pp'
6
6
  require 'yaml'
7
7
 
8
8
  # for ident(1)
9
- CVS_ID = '$Id: higgs_dump_jlog 462 2007-07-15 09:25:07Z toki $'
9
+ CVS_ID = '$Id: higgs_dump_jlog 677 2007-11-08 16:22:02Z toki $'
10
10
 
11
11
  opts = OptionParser.new
12
12
  opts.banner = "Usage: #{opts.program_name} [options] [JOURNAL_LOG_PATHs]"
@@ -25,16 +25,32 @@ opts.on_tail('-h', '--help') {
25
25
  }
26
26
  opts.parse!
27
27
 
28
- Higgs::JournalLogger.scan_log(ARGF) {|log|
29
- case (output_format)
30
- when :pretty
31
- pp log
32
- when :yaml
33
- puts log.to_yaml
28
+ def scan_args
29
+ if (ARGV.empty?) then
30
+ yield(STDIN)
34
31
  else
35
- raise "unknown output format: #{output_format}"
32
+ for filename in ARGV
33
+ File.open(filename, 'r') {|r|
34
+ r.binmode
35
+ yield(r)
36
+ }
37
+ end
36
38
  end
37
- }
39
+ nil
40
+ end
41
+
42
+ scan_args do |r|
43
+ Higgs::JournalLogger.scan_log(r) do |log|
44
+ case (output_format)
45
+ when :pretty
46
+ pp log
47
+ when :yaml
48
+ puts log.to_yaml
49
+ else
50
+ raise "unknown output format: #{output_format}"
51
+ end
52
+ end
53
+ end
38
54
 
39
55
  # Local Variables:
40
56
  # mode: Ruby
data/bin/higgs_ping ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'drb'
4
+ require 'optparse'
5
+
6
+ # for ident(1)
7
+ CVS_ID = '$Id: higgs_ping 679 2007-11-11 01:41:18Z toki $'
8
+
9
+ opt_verbose = 0
10
+
11
+ opts = OptionParser.new
12
+ opts.banner = "Usage: #{opts.program_name} [OPTIONs] URI_FOR_REMOTE_SERVICES\n"
13
+ opts.banner << "OPTIONs:\n"
14
+ opts.on('-v', '--[no-]verbose') {|value|
15
+ if (value) then
16
+ opt_verbose += 1
17
+ else
18
+ opt_verbose -= 1
19
+ end
20
+ }
21
+ opts.on('--verbose-level=LEVEL', Integer) {|value|
22
+ opt_verbose = value
23
+ }
24
+ opts.parse!
25
+
26
+ if (ARGV.empty?) then
27
+ puts opts
28
+ exit 1
29
+ end
30
+
31
+ uri = ARGV.shift
32
+ begin
33
+ puts "connect to #{uri}" if (opt_verbose >= 2)
34
+ services = DRbObject.new_with_uri(uri)
35
+ alive_service = services[:alive_service_v1] or raise 'not provided remote service: alive_service_v1'
36
+ if (alive_service.call) then
37
+ puts "alive" if (opt_verbose >= 1)
38
+ exit 0
39
+ end
40
+ rescue DRb::DRbError
41
+ # fall through
42
+ puts "error: #{$!}" if (opt_verbose >= 2)
43
+ end
44
+
45
+ puts "dead" if (opt_verbose >= 1)
46
+ exit 255
data/lib/higgs/block.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  # = block read/write
2
2
  #
3
3
  # Author:: $Author: toki $
4
- # Date:: $Date: 2007-09-30 15:20:15 +0900 (Sun, 30 Sep 2007) $
5
- # Revision:: $Revision: 591 $
4
+ # Date:: $Date: 2007-10-24 01:04:47 +0900 (Wed, 24 Oct 2007) $
5
+ # Revision:: $Revision: 654 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
9
9
  #
10
10
 
11
+ require 'digest'
11
12
  require 'higgs/exceptions'
12
13
 
13
14
  module Higgs
@@ -27,7 +28,7 @@ module Higgs
27
28
  #
28
29
  module Block
29
30
  # for ident(1)
30
- CVS_ID = '$Id: block.rb 591 2007-09-30 06:20:15Z toki $'
31
+ CVS_ID = '$Id: block.rb 654 2007-10-23 16:04:47Z toki $'
31
32
 
32
33
  include Exceptions
33
34
 
@@ -42,26 +43,17 @@ module Higgs
42
43
  HEAD_CKSUM_FMT = 'v'
43
44
 
44
45
  BODY_HASH = {}
45
- [ [ :SUM16, proc{|s| s.sum(16).to_s }, nil ],
46
- [ :MD5, proc{|s| Digest::MD5.digest(s) }, 'digest/md5' ],
47
- [ :RMD160, proc{|s| Digest::RMD160.digest(s) }, 'digest/rmd160' ],
48
- [ :SHA1, proc{|s| Digest::SHA1.digest(s) }, 'digest/sha1' ],
49
- [ :SHA256, proc{|s| Digest::SHA256.digest(s) }, 'digest/sha2' ],
50
- [ :SHA384, proc{|s| Digest::SHA384.digest(s) }, 'digest/sha2' ],
51
- [ :SHA512, proc{|s| Digest::SHA512.digest(s) }, 'digest/sha2' ]
52
- ].each do |hash_symbol, hash_proc, hash_lib|
53
- if (hash_lib) then
54
- begin
55
- require(hash_lib)
56
- rescue LoadError
57
- next
58
- end
59
- end
60
- BODY_HASH[hash_symbol] = hash_proc
61
- end
62
-
63
46
  BODY_HASH_BIN = {}
64
- BODY_HASH.each do |hash_symbol, hash_proc|
47
+
48
+ [ [ :SUM16, proc{|s| s.sum(16).to_s } ],
49
+ [ :MD5, proc{|s| Digest::MD5.digest(s) } ],
50
+ [ :RMD160, proc{|s| Digest::RMD160.digest(s) } ],
51
+ [ :SHA1, proc{|s| Digest::SHA1.digest(s) } ],
52
+ [ :SHA256, proc{|s| Digest::SHA256.digest(s) } ],
53
+ [ :SHA384, proc{|s| Digest::SHA384.digest(s) } ],
54
+ [ :SHA512, proc{|s| Digest::SHA512.digest(s) } ]
55
+ ].each do |hash_symbol, hash_proc|
56
+ BODY_HASH[hash_symbol] = hash_proc
65
57
  BODY_HASH_BIN[hash_symbol.to_s] = hash_proc
66
58
  end
67
59
 
data/lib/higgs/cache.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # = cache utilities
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-31 00:36:09 +0900 (Wed, 31 Oct 2007) $
5
+ # Revision:: $Revision: 659 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
@@ -16,7 +16,7 @@ module Higgs
16
16
  # = cache by Least Recently Used strategy
17
17
  class LRUCache
18
18
  # for ident(1)
19
- CVS_ID = '$Id: cache.rb 559 2007-09-25 15:20:20Z toki $'
19
+ CVS_ID = '$Id: cache.rb 659 2007-10-30 15:36:09Z toki $'
20
20
 
21
21
  extend Forwardable
22
22
 
@@ -73,11 +73,11 @@ module Higgs
73
73
  # = multi-thread safe cache
74
74
  class SharedWorkCache
75
75
  # for ident(1)
76
- CVS_ID = '$Id: cache.rb 559 2007-09-25 15:20:20Z toki $'
76
+ CVS_ID = '$Id: cache.rb 659 2007-10-30 15:36:09Z toki $'
77
77
 
78
78
  def initialize(cache={}, &work)
79
79
  unless (work) then
80
- raise 'required work block'
80
+ raise ArgumentError, 'required work block'
81
81
  end
82
82
  @work = work
83
83
  @lock = Mutex.new
data/lib/higgs/dbm.rb CHANGED
@@ -1,15 +1,14 @@
1
1
  # = storage like dbm
2
2
  #
3
3
  # Author:: $Author: toki $
4
- # Date:: $Date: 2007-10-02 01:05:07 +0900 (Tue, 02 Oct 2007) $
5
- # Revision:: $Revision: 600 $
4
+ # Date:: $Date: 2007-10-24 00:46:00 +0900 (Wed, 24 Oct 2007) $
5
+ # Revision:: $Revision: 653 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
9
9
  #
10
10
 
11
- require 'higgs/storage'
12
- require 'higgs/tman'
11
+ require 'higgs/sman'
13
12
 
14
13
  module Higgs
15
14
  # = storage like dbm
@@ -53,34 +52,19 @@ module Higgs
53
52
  # custom_property[number]: 0
54
53
  # %
55
54
  #
56
- class DBM
55
+ class DBM < StorageManager
57
56
  # for ident(1)
58
- CVS_ID = '$Id: dbm.rb 600 2007-10-01 16:05:07Z toki $'
59
-
60
- include Storage::Export
61
- include TransactionManager::Export
57
+ CVS_ID = '$Id: dbm.rb 653 2007-10-23 15:46:00Z toki $'
62
58
 
63
59
  DECODE = proc{|r| r }
64
60
  ENCODE = proc{|w| w }
65
61
 
66
- # <tt>name</tt> is a storage name and see Higgs::Storage.new for
67
- # detail. see Higgs::Storage::InitOptions and
68
- # Higgs::TransactionManager::InitOptions for <tt>options</tt>.
62
+ # see Higgs::StorageManager.new for <tt>name</tt> and <tt>options</tt>.
69
63
  def initialize(name, options={})
70
- @storage = Storage.new(name, options)
64
+ options = options.dup
71
65
  options[:decode] = DECODE
72
66
  options[:encode] = ENCODE
73
- @tman = TransactionManager.new(@storage, options)
74
- end
75
-
76
- def self.open(*args)
77
- dbm = new(*args)
78
- begin
79
- r = yield(dbm)
80
- ensure
81
- dbm.shutdown
82
- end
83
- r
67
+ super(name, options)
84
68
  end
85
69
  end
86
70
  end
data/lib/higgs/index.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # = storage index
2
2
  #
3
3
  # Author:: $Author: toki $
4
- # Date:: $Date: 2007-09-30 14:54:30 +0900 (Sun, 30 Sep 2007) $
5
- # Revision:: $Revision: 589 $
4
+ # Date:: $Date: 2007-10-21 22:40:57 +0900 (Sun, 21 Oct 2007) $
5
+ # Revision:: $Revision: 649 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
@@ -15,14 +15,14 @@ module Higgs
15
15
  # = storage index
16
16
  class Index
17
17
  # for ident(1)
18
- CVS_ID = '$Id: index.rb 589 2007-09-30 05:54:30Z toki $'
18
+ CVS_ID = '$Id: index.rb 649 2007-10-21 13:40:57Z toki $'
19
19
 
20
20
  extend Forwardable
21
21
  include Block
22
22
 
23
23
  MAGIC_SYMBOL = 'HIGGS_INDEX'
24
24
  MAJOR_VERSION = 0
25
- MINOR_VERSION = 1
25
+ MINOR_VERSION = 2
26
26
 
27
27
  def initialize
28
28
  @change_number = 0
@@ -30,10 +30,12 @@ module Higgs
30
30
  @free_lists = {}
31
31
  @index = {}
32
32
  @identities = {}
33
+ @storage_id = nil
33
34
  end
34
35
 
35
36
  attr_reader :change_number
36
37
  attr_accessor :eoa
38
+ attr_accessor :storage_id
37
39
 
38
40
  def succ!
39
41
  @change_number = @change_number.succ
@@ -104,7 +106,8 @@ module Higgs
104
106
  :eoa => @eoa,
105
107
  :free_lists => @free_lists,
106
108
  :index => @index,
107
- :identities => @identities
109
+ :identities => @identities,
110
+ :storage_id => @storage_id
108
111
  }
109
112
  end
110
113
 
@@ -130,6 +133,21 @@ module Higgs
130
133
  end
131
134
  private :migration_0_0_to_0_1
132
135
 
136
+ def migration_0_1_to_0_2(index_data)
137
+ if ((index_data[:version] <=> [ 0, 1 ]) > 0) then
138
+ return
139
+ end
140
+ if ((index_data[:version] <=> [ 0, 1 ]) < 0) then
141
+ raise "unexpected index format version: #{index_data[:version].join('.')}"
142
+ end
143
+
144
+ index_data[:storage_id] = @storage_id
145
+ index_data[:version] = [ 0, 2 ]
146
+
147
+ index_data
148
+ end
149
+ private :migration_0_1_to_0_2
150
+
133
151
  def save(path)
134
152
  tmp_path = "#{path}.tmp.#{$$}"
135
153
  File.open(tmp_path, File::WRONLY | File::CREAT | File::TRUNC, 0660) {|f|
@@ -147,6 +165,7 @@ module Higgs
147
165
  f.binmode
148
166
  index_data = Marshal.load(block_read(f, MAGIC_SYMBOL))
149
167
  migration_0_0_to_0_1(index_data)
168
+ migration_0_1_to_0_2(index_data)
150
169
  if (index_data[:version] != [ MAJOR_VERSION, MINOR_VERSION ]) then
151
170
  raise "unsupported version: #{index_data[:version].join('.')}"
152
171
  end
@@ -155,6 +174,7 @@ module Higgs
155
174
  @free_lists = index_data[:free_lists]
156
175
  @index = index_data[:index]
157
176
  @identities = index_data[:identities]
177
+ @storage_id = index_data[:storage_id]
158
178
  }
159
179
  self
160
180
  end
data/lib/higgs/jlog.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # = journal log writer
2
2
  #
3
3
  # Author:: $Author: toki $
4
- # Date:: $Date: 2007-10-03 00:02:48 +0900 (Wed, 03 Oct 2007) $
5
- # Revision:: $Revision: 603 $
4
+ # Date:: $Date: 2007-10-28 23:35:37 +0900 (Sun, 28 Oct 2007) $
5
+ # Revision:: $Revision: 657 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
@@ -14,7 +14,7 @@ module Higgs
14
14
  # = journal log writer
15
15
  class JournalLogger
16
16
  # for ident(1)
17
- CVS_ID = '$Id: jlog.rb 603 2007-10-02 15:02:48Z toki $'
17
+ CVS_ID = '$Id: jlog.rb 657 2007-10-28 14:35:37Z toki $'
18
18
 
19
19
  include Block
20
20
 
@@ -71,10 +71,6 @@ module Higgs
71
71
 
72
72
  class << self
73
73
  def has_eof_mark?(path)
74
- unless (File.exist? path) then
75
- return true
76
- end
77
-
78
74
  File.open(path, 'r') {|f|
79
75
  f.binmode
80
76
  fsiz = f.stat.size
@@ -98,7 +94,7 @@ module Higgs
98
94
  end
99
95
 
100
96
  def need_for_recovery?(path)
101
- ! (has_eof_mark? path)
97
+ (File.exist? path) && ! (has_eof_mark? path)
102
98
  end
103
99
 
104
100
  def open(path, *args)
data/lib/higgs/lock.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # = multi-thread lock manager
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-23 00:23:50 +0900 (Tue, 23 Oct 2007) $
5
+ # Revision:: $Revision: 652 $
6
6
  #
7
7
  # == license
8
8
  # :include:LICENSE
@@ -18,7 +18,7 @@ module Higgs
18
18
  # = multi-thread lock manager
19
19
  class LockManager
20
20
  # for ident(1)
21
- CVS_ID = '$Id: lock.rb 559 2007-09-25 15:20:20Z toki $'
21
+ CVS_ID = '$Id: lock.rb 652 2007-10-22 15:23:50Z toki $'
22
22
 
23
23
  include Exceptions
24
24
 
@@ -84,7 +84,7 @@ module Higgs
84
84
 
85
85
  class GiantLockManager < LockManager
86
86
  # for ident(1)
87
- CVS_ID = '$Id: lock.rb 559 2007-09-25 15:20:20Z toki $'
87
+ CVS_ID = '$Id: lock.rb 652 2007-10-22 15:23:50Z toki $'
88
88
 
89
89
  def initialize(*args)
90
90
  super
@@ -115,14 +115,23 @@ module Higgs
115
115
  }
116
116
  r
117
117
  end
118
+
119
+ def exclusive
120
+ r = nil
121
+ @rw_lock.write_lock.synchronize{
122
+ r = yield
123
+ }
124
+ r
125
+ end
118
126
  end
119
127
 
120
128
  class FineGrainLockManager < LockManager
121
129
  # for ident(1)
122
- CVS_ID = '$Id: lock.rb 559 2007-09-25 15:20:20Z toki $'
130
+ CVS_ID = '$Id: lock.rb 652 2007-10-22 15:23:50Z toki $'
123
131
 
124
132
  def initialize(*args)
125
133
  super
134
+ @tx_lock = ReadWriteLock.new
126
135
  @cache = SharedWorkCache.new{|key| ReadWriteLock.new }
127
136
  end
128
137
 
@@ -171,13 +180,26 @@ module Higgs
171
180
  else
172
181
  lock_handler = ReadWriteLockHandler.new(self, @cache)
173
182
  end
174
- begin
175
- r = yield(lock_handler)
176
- ensure
177
- for lock in lock_handler.lock_list
178
- lock.unlock
183
+
184
+ r = nil
185
+ @tx_lock.read_lock.synchronize{
186
+ begin
187
+ r = yield(lock_handler)
188
+ ensure
189
+ for lock in lock_handler.lock_list
190
+ lock.unlock
191
+ end
179
192
  end
180
- end
193
+ }
194
+
195
+ r
196
+ end
197
+
198
+ def exclusive
199
+ r = nil
200
+ @tx_lock.write_lock.synchronize{
201
+ r = yield
202
+ }
181
203
  r
182
204
  end
183
205
  end