hutch-xamplr 1.0.5 → 1.1.0
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/Rakefile +1 -0
- data/VERSION.yml +2 -2
- data/examples/random-people-shared-addresses/Makefile +2 -2
- data/examples/random-people-shared-addresses/batch-load-users.rb +2 -5
- data/examples/random-people-shared-addresses/find-mentions.rb +1 -4
- data/examples/random-people-shared-addresses/find-people-by-address.rb +1 -4
- data/examples/random-people-shared-addresses/optimise.rb +1 -4
- data/examples/random-people-shared-addresses/people.rb +0 -15
- data/examples/random-people-shared-addresses/query.rb +1 -4
- data/examples/random-people-shared-addresses/query2.rb +1 -4
- data/examples/random-people-shared-addresses/results.write.BASELINE +298 -0
- data/examples/random-people-shared-addresses/results.write.NEW_ATTR_ENCODING +294 -0
- data/examples/random-people-shared-addresses/settings.rb +3 -0
- data/examples/random-people/batch-load-users.rb +1 -4
- data/examples/random-people/optimise.rb +1 -4
- data/examples/random-people/people.rb +0 -3
- data/examples/random-people/query.rb +1 -5
- data/examples/random-people/query2.rb +1 -4
- data/examples/random-people/settings.rb +3 -0
- data/examples/random-people/what-to-query-on.rb +1 -3
- data/examples/read-testing/Makefile +10 -0
- data/examples/read-testing/load.rb +65 -0
- data/examples/read-testing/read.rb +51 -0
- data/examples/read-testing/results.read.BASELINE +6 -0
- data/examples/read-testing/results.read.FAST +5 -0
- data/examples/read-testing/rrr.rb +87 -0
- data/examples/read-testing/settings.rb +2 -0
- data/examples/read-testing/xampl-gen.rb +36 -0
- data/examples/read-testing/xml/text.xml +8 -0
- data/lib/xamplr.rb +10 -1
- data/lib/xamplr/exceptions.rb +97 -0
- data/lib/xamplr/from-xml-orig.rb +350 -0
- data/lib/xamplr/from-xml.rb +272 -183
- data/lib/xamplr/handwritten/example.rb +0 -58
- data/lib/xamplr/handwritten/hand-example.rb +0 -27
- data/lib/xamplr/handwritten/test-handwritten.rb +0 -37
- data/lib/xamplr/mixins.rb +10 -48
- data/lib/xamplr/persist-to-xml.rb +249 -0
- data/lib/xamplr/persistence.rb +44 -412
- data/lib/xamplr/persistence.rb.more_thread_safe +0 -13
- data/lib/xamplr/persistence.rb.partially_thread_safe +0 -13
- data/lib/xamplr/persister.rb +298 -0
- data/lib/xamplr/{persister → persisters}/caches.rb +0 -0
- data/lib/xamplr/{persister → persisters}/caching.rb +1 -1
- data/lib/xamplr/{persister → persisters}/filesystem.rb +4 -5
- data/lib/xamplr/{persister → persisters}/in-memory.rb +1 -1
- data/lib/xamplr/{persister → persisters}/simple.rb +0 -0
- data/lib/xamplr/{persister → persisters}/tokyo-cabinet.rb +53 -15
- data/lib/xamplr/simpleTemplate/{input-c.r4 → obsolete/input-c.r4} +0 -0
- data/lib/xamplr/simpleTemplate/{play.r6.txt → obsolete/play.r6.txt} +0 -0
- data/lib/xamplr/simpleTemplate/{play_more.r6.txt → obsolete/play_more.r6.txt} +0 -0
- data/lib/xamplr/simpleTemplate/{test001.r5 → obsolete/test001.r5} +0 -0
- data/lib/xamplr/simpleTemplate/{test002.r5 → obsolete/test002.r5} +0 -0
- data/lib/xamplr/simpleTemplate/{test003.r5 → obsolete/test003.r5} +0 -0
- data/lib/xamplr/templates/child_indexed.template +1 -1
- data/lib/xamplr/templates/element_classes.template +1 -1
- data/lib/xamplr/templates/element_data.template +0 -39
- data/lib/xamplr/templates/element_empty.template +0 -40
- data/lib/xamplr/templates/element_mixed.template +0 -41
- data/lib/xamplr/templates/element_simple.template +0 -40
- data/lib/xamplr/test-support/bench.rb +6 -26
- data/lib/xamplr/test-support/test.rb +1 -89
- data/lib/xamplr/visitor.rb +0 -778
- data/lib/xamplr/visitors.rb +573 -0
- data/lib/xamplr/xampl-generator.rb +1 -1
- data/lib/xamplr/xampl-hand-generated.rb +0 -85
- data/lib/xamplr/xampl-module.rb +36 -0
- data/lib/xamplr/xampl-object-internals.rb +6 -0
- data/lib/xamplr/xampl-object.rb +10 -341
- data/lib/xamplr/xampl-persisted-object.rb +122 -0
- data/lib/xamplr/xml-text.rb +117 -0
- metadata +53 -18
- data/lib/xamplr/persister/subversion.rb +0 -61
- data/lib/xamplr/rac.sh +0 -6
- data/lib/xamplr/rac_gen.sh +0 -1
- data/lib/xamplr/templates/child_indexed.template.000 +0 -87
@@ -569,8 +569,6 @@ module Xampl
|
|
569
569
|
return xampl.persist
|
570
570
|
when :ruby_format then
|
571
571
|
return xampl.to_ruby
|
572
|
-
when :yaml_format then
|
573
|
-
return xampl.as_yaml
|
574
572
|
end
|
575
573
|
end
|
576
574
|
|
@@ -580,20 +578,9 @@ module Xampl
|
|
580
578
|
|
581
579
|
if representation =~ /^</ then
|
582
580
|
return XamplObject.realise_from_xml_string(representation, target)
|
583
|
-
elsif representation =~ /^-/ then
|
584
|
-
return XamplObject.from_yaml(representation, target)
|
585
581
|
else
|
586
582
|
XamplObject.from_ruby(representation, target)
|
587
583
|
end
|
588
|
-
|
589
|
-
# case @format
|
590
|
-
# when nil, :xml_format then
|
591
|
-
# return XamplObject.realise_from_xml_string(representation, target)
|
592
|
-
# when :ruby_format then
|
593
|
-
# XamplObject.from_ruby(representation, target)
|
594
|
-
# when :yaml_format then
|
595
|
-
# return XamplObject.from_yaml(representation, target)
|
596
|
-
# end
|
597
584
|
end
|
598
585
|
|
599
586
|
def write(xampl)
|
@@ -561,8 +561,6 @@ module Xampl
|
|
561
561
|
return xampl.persist
|
562
562
|
when :ruby_format then
|
563
563
|
return xampl.to_ruby
|
564
|
-
when :yaml_format then
|
565
|
-
return xampl.as_yaml
|
566
564
|
end
|
567
565
|
end
|
568
566
|
|
@@ -572,20 +570,9 @@ module Xampl
|
|
572
570
|
|
573
571
|
if representation =~ /^</ then
|
574
572
|
return XamplObject.realise_from_xml_string(representation, target)
|
575
|
-
elsif representation =~ /^-/ then
|
576
|
-
return XamplObject.from_yaml(representation, target)
|
577
573
|
else
|
578
574
|
XamplObject.from_ruby(representation, target)
|
579
575
|
end
|
580
|
-
|
581
|
-
# case @format
|
582
|
-
# when nil, :xml_format then
|
583
|
-
# return XamplObject.realise_from_xml_string(representation, target)
|
584
|
-
# when :ruby_format then
|
585
|
-
# XamplObject.from_ruby(representation, target)
|
586
|
-
# when :yaml_format then
|
587
|
-
# return XamplObject.from_yaml(representation, target)
|
588
|
-
# end
|
589
576
|
end
|
590
577
|
|
591
578
|
def write(xampl)
|
@@ -0,0 +1,298 @@
|
|
1
|
+
|
2
|
+
require "xamplr/persistence"
|
3
|
+
|
4
|
+
module Xampl
|
5
|
+
class Persister
|
6
|
+
attr_accessor :name,
|
7
|
+
:automatic,
|
8
|
+
:block_changes,
|
9
|
+
:read_count, :total_read_count,
|
10
|
+
:write_count, :total_write_count,
|
11
|
+
:total_sync_count, :total_rollback_count,
|
12
|
+
:cache_hits, :total_cache_hits,
|
13
|
+
:last_write_count,
|
14
|
+
:rolled_back
|
15
|
+
attr_reader :syncing, :format
|
16
|
+
|
17
|
+
def initialize(name=nil, format=nil)
|
18
|
+
@name = name
|
19
|
+
@format = format
|
20
|
+
@automatic = false
|
21
|
+
@changed = {}
|
22
|
+
@cache_hits = 0
|
23
|
+
@total_cache_hits = 0
|
24
|
+
@read_count = 0
|
25
|
+
@total_read_count = 0
|
26
|
+
@write_count = 0
|
27
|
+
@total_write_count = 0
|
28
|
+
@last_write_count = 0
|
29
|
+
@total_sync_count = 0
|
30
|
+
@total_rollback_count = 0
|
31
|
+
@rolled_back = false
|
32
|
+
@syncing = false
|
33
|
+
|
34
|
+
@busy_count = 0
|
35
|
+
end
|
36
|
+
|
37
|
+
def optimise(opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
def close
|
41
|
+
self.sync
|
42
|
+
end
|
43
|
+
|
44
|
+
def busy(yes)
|
45
|
+
if yes then
|
46
|
+
@busy_count += 1
|
47
|
+
elsif 0 < @busy_count then
|
48
|
+
@busy_count -= 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def is_busy
|
53
|
+
return 0 < @busy_count
|
54
|
+
end
|
55
|
+
|
56
|
+
def introduce(xampl)
|
57
|
+
if xampl.introduce_persister(self) then
|
58
|
+
cache(xampl)
|
59
|
+
end
|
60
|
+
has_changed(xampl) if xampl.is_changed
|
61
|
+
end
|
62
|
+
|
63
|
+
def has_changed(xampl)
|
64
|
+
#raise XamplException.new(:live_across_rollback) if @rolled_back
|
65
|
+
# puts "!!!! has_changed #{xampl} #{xampl.get_the_index} -- persist required: #{xampl.persist_required}"
|
66
|
+
if xampl.persist_required && xampl.is_changed then
|
67
|
+
unless self == xampl.persister
|
68
|
+
raise MixedPersisters.new(xampl.persister, self)
|
69
|
+
end
|
70
|
+
@changed[xampl] = xampl
|
71
|
+
# puts "!!!! change recorded ==> #{@changed.size}/#{count_changed} #{@changed.object_id} !!!!"
|
72
|
+
# @changed.each{ | thing, ignore |
|
73
|
+
# puts " changed: #{thing}, index: #{thing.get_the_index}, changed: #{thing.is_changed}"
|
74
|
+
# }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def has_not_changed(xampl)
|
79
|
+
# puts "!!!! has_not_changed #{xampl} #{xampl.get_the_index} -- in @changed: #{nil != @changed[xampl]}"
|
80
|
+
@changed.delete(xampl) if xampl
|
81
|
+
end
|
82
|
+
|
83
|
+
def count_changed
|
84
|
+
# @changed.each{ | thing, ignore |
|
85
|
+
# puts "changed: #{thing}, index: #{thing.get_the_index}"
|
86
|
+
# }
|
87
|
+
return @changed.size
|
88
|
+
end
|
89
|
+
|
90
|
+
def cache(xampl)
|
91
|
+
raise XamplException.new(:unimplemented)
|
92
|
+
end
|
93
|
+
|
94
|
+
def uncache(xampl)
|
95
|
+
raise XamplException.new(:unimplemented)
|
96
|
+
end
|
97
|
+
|
98
|
+
def clear_cache
|
99
|
+
raise XamplException.new(:unimplemented)
|
100
|
+
end
|
101
|
+
|
102
|
+
def Persister.replace(old_xampl, new_xampl)
|
103
|
+
pid = old_xampl.get_the_index
|
104
|
+
if old_xampl.persister != @@persister then
|
105
|
+
raise MixedPersisters.new(@@persister, old_xampl.persister)
|
106
|
+
end
|
107
|
+
if new_xampl.persister != @@persister then
|
108
|
+
raise MixedPersisters.new(@@persister, new_xampl.persister)
|
109
|
+
end
|
110
|
+
|
111
|
+
new_xampl.note_replacing(old_xampl)
|
112
|
+
|
113
|
+
unless old_xampl.load_needed then
|
114
|
+
Xampl.log.warn("Replacing live xampl: #{old_xampl} pid: #{pid}")
|
115
|
+
@@persister.uncache(old_xampl)
|
116
|
+
old_xampl.invalidate
|
117
|
+
end
|
118
|
+
new_xampl.pid = nil
|
119
|
+
new_xampl.pid = pid
|
120
|
+
@@persister.introduce(new_xampl)
|
121
|
+
end
|
122
|
+
|
123
|
+
def represent(xampl, mentions=[])
|
124
|
+
#puts "REPRESENT #{xampl} load needed: #{xampl.load_needed}"
|
125
|
+
# return nil if xampl.load_needed
|
126
|
+
case xampl.default_persister_format || @format
|
127
|
+
when nil, :xml_format then
|
128
|
+
return xampl.persist("", mentions)
|
129
|
+
when :ruby_format then
|
130
|
+
return xampl.to_ruby(mentions)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def realise(representation, target=nil)
|
135
|
+
# Normally we'd expect to see the representation in the @format format, but
|
136
|
+
# that isn't necessarily the case. Try to work out what the format might be...
|
137
|
+
|
138
|
+
if representation =~ /^</ then
|
139
|
+
return XamplObject.realise_from_xml_string(representation, target)
|
140
|
+
else
|
141
|
+
XamplObject.from_ruby(representation, target)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def version(stream)
|
146
|
+
raise XamplException.new(:unimplemented)
|
147
|
+
# catch(:refuse_to_version) do
|
148
|
+
# end
|
149
|
+
end
|
150
|
+
|
151
|
+
def write(xampl)
|
152
|
+
raise XamplException.new(:unimplemented)
|
153
|
+
end
|
154
|
+
|
155
|
+
def read(klass, pid, target=nil)
|
156
|
+
raise XamplException.new(:unimplemented)
|
157
|
+
end
|
158
|
+
|
159
|
+
def lookup(klass, pid)
|
160
|
+
#raise XamplException.new(:live_across_rollback) if @rolled_back
|
161
|
+
#puts "#{File.basename(__FILE__)} #{__LINE__} LOOKUP:: klass: #{klass} pid: #{pid}"
|
162
|
+
|
163
|
+
begin
|
164
|
+
busy(true)
|
165
|
+
xampl = read(klass, pid)
|
166
|
+
ensure
|
167
|
+
busy(false)
|
168
|
+
end
|
169
|
+
|
170
|
+
#puts "#{File.basename(__FILE__)} #{__LINE__} ---> #{ xampl }"
|
171
|
+
|
172
|
+
return xampl
|
173
|
+
end
|
174
|
+
|
175
|
+
def find_known(klass, pid)
|
176
|
+
#raise XamplException.new(:live_across_rollback) if @rolled_back
|
177
|
+
|
178
|
+
xampl = read_from_cache(klass, pid, nil)
|
179
|
+
|
180
|
+
return xampl
|
181
|
+
end
|
182
|
+
|
183
|
+
def lazy_load(target, klass, pid)
|
184
|
+
# puts "#{File.basename(__FILE__)} #{__LINE__} LAZY_LOAD:: klass: #{klass} pid: #{pid} target: #{target}"
|
185
|
+
|
186
|
+
xampl = read(klass, pid, target)
|
187
|
+
|
188
|
+
# puts " LAZY_LOAD --> #{xampl}"
|
189
|
+
|
190
|
+
return xampl
|
191
|
+
end
|
192
|
+
|
193
|
+
def put_changed(msg="")
|
194
|
+
puts "Changed::#{msg}:"
|
195
|
+
@changed.each { | xampl, ignore | puts " #{xampl.tag} #{xampl.get_the_index}" }
|
196
|
+
end
|
197
|
+
|
198
|
+
def do_sync_write
|
199
|
+
unchanged_in_changed_list = 0
|
200
|
+
@changed.each do |xampl, ignore|
|
201
|
+
unchanged_in_changed_list += 1 unless xampl.is_changed
|
202
|
+
unless xampl.kind_of?(InvalidXampl) then
|
203
|
+
write(xampl)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def sync
|
209
|
+
#raise XamplException.new(:live_across_rollback) if @rolled_back
|
210
|
+
begin
|
211
|
+
#puts "SYNC"
|
212
|
+
#puts "SYNC"
|
213
|
+
#puts "SYNC changed: #{@changed.size}" if 0 < @changed.size
|
214
|
+
#@changed.each do | key, value |
|
215
|
+
##puts " #{key.class.name}"
|
216
|
+
##puts "key: #{key.class.name}, value: #{value.class.name}"
|
217
|
+
#puts key.to_xml
|
218
|
+
#end
|
219
|
+
#puts "SYNC"
|
220
|
+
#puts "SYNC"
|
221
|
+
|
222
|
+
#if 0 < @changed.size then
|
223
|
+
#puts "SYNC changed: #{@changed.size}"
|
224
|
+
##caller(0).each do | trace |
|
225
|
+
## next if /xamplr/ =~ trace
|
226
|
+
## puts " #{trace}"
|
227
|
+
## break if /actionpack/ =~ trace
|
228
|
+
##end
|
229
|
+
#end
|
230
|
+
busy(true)
|
231
|
+
@syncing = true
|
232
|
+
|
233
|
+
do_sync_write
|
234
|
+
|
235
|
+
@changed = {}
|
236
|
+
|
237
|
+
@total_read_count = @total_read_count + @read_count
|
238
|
+
@total_write_count = @total_write_count + @write_count
|
239
|
+
@total_cache_hits = @total_cache_hits + @cache_hits
|
240
|
+
@total_sync_count = @total_sync_count + 1
|
241
|
+
|
242
|
+
@read_count = 0
|
243
|
+
@last_write_count = @write_count
|
244
|
+
@write_count = 0
|
245
|
+
|
246
|
+
self.sync_done()
|
247
|
+
|
248
|
+
return @last_write_count
|
249
|
+
ensure
|
250
|
+
busy(false)
|
251
|
+
@syncing = false
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def sync_done
|
256
|
+
raise XamplException.new(:unimplemented)
|
257
|
+
end
|
258
|
+
|
259
|
+
def rollback
|
260
|
+
begin
|
261
|
+
busy(true)
|
262
|
+
|
263
|
+
return Xampl.rollback(self)
|
264
|
+
ensure
|
265
|
+
busy(false)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def rollback_cleanup
|
270
|
+
@changed = {}
|
271
|
+
end
|
272
|
+
|
273
|
+
def print_stats
|
274
|
+
printf("SYNC:: TOTAL cache_hits: %d, reads: %d, writes: %d\n",
|
275
|
+
@total_cache_hits, @total_read_count, @total_write_count)
|
276
|
+
printf(" cache_hits: %d, reads: %d, last writes: %d\n",
|
277
|
+
@cache_hits, @read_count, @last_write_count)
|
278
|
+
printf(" syncs: %d\n", @total_sync_count)
|
279
|
+
printf(" changed count: %d (%d)\n", count_changed, @changed.size)
|
280
|
+
@changed.each do |thing, ignore|
|
281
|
+
if thing.is_changed then
|
282
|
+
puts " changed: #{thing}, index: #{thing.get_the_index}"
|
283
|
+
else
|
284
|
+
puts " UNCHANGED: #{thing}, index: #{thing.get_the_index} <<<<<<<<<<<<<<<<<<< BAD!"
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
require "xamplr/persisters/simple"
|
291
|
+
require "xamplr/persisters/in-memory"
|
292
|
+
require "xamplr/persisters/filesystem"
|
293
|
+
|
294
|
+
if require 'tokyocabinet' then
|
295
|
+
require "xamplr/persisters/tokyo-cabinet"
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
File without changes
|
@@ -3,7 +3,7 @@ module Xampl
|
|
3
3
|
require 'xamplr/version'
|
4
4
|
|
5
5
|
require "fileutils"
|
6
|
-
require "xamplr/
|
6
|
+
require "xamplr/persisters/caching"
|
7
7
|
|
8
8
|
class FilesystemPersister < AbstractCachingPersister
|
9
9
|
|
@@ -39,9 +39,7 @@ module Xampl
|
|
39
39
|
|
40
40
|
representation = represent(xampl)
|
41
41
|
if representation then
|
42
|
-
File.open(place, "w"){ | out |
|
43
|
-
out.puts representation
|
44
|
-
}
|
42
|
+
File.open(place, "w"){ | out | out.puts representation }
|
45
43
|
@write_count = @write_count + 1
|
46
44
|
end
|
47
45
|
xampl.changes_accepted
|
@@ -52,7 +50,8 @@ module Xampl
|
|
52
50
|
place = File.join(@root_dir, klass.name.split("::"), pid)
|
53
51
|
|
54
52
|
return nil unless File.exist?(place)
|
55
|
-
|
53
|
+
representation = File.read(place)
|
54
|
+
return representation
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
File without changes
|
@@ -2,9 +2,11 @@ module Xampl
|
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'tokyocabinet'
|
5
|
-
require 'xamplr/
|
5
|
+
require 'xamplr/persisters/caching'
|
6
6
|
require 'set'
|
7
7
|
|
8
|
+
require 'ruby-prof'
|
9
|
+
|
8
10
|
class TokyoCabinetPersister < AbstractCachingPersister
|
9
11
|
include TokyoCabinet
|
10
12
|
|
@@ -43,29 +45,32 @@ module Xampl
|
|
43
45
|
|
44
46
|
open_tc_db()
|
45
47
|
|
46
|
-
# note_errors("TC:: optimisation error: %s\n") do
|
48
|
+
# note_errors("TC[[#{ @filename }]]:: optimisation error: %s\n") do
|
47
49
|
# @tc_db.optimize(-1, -1, -1, TDB::TDEFLATE)
|
48
50
|
# end
|
49
|
-
# note_errors("TC:: close error: %s\n") do
|
51
|
+
# note_errors("TC[[#{ @filename }]]:: close error: %s\n") do
|
50
52
|
# @tc_db.close
|
51
53
|
# end
|
52
54
|
end
|
53
55
|
|
54
56
|
def open_tc_db
|
55
57
|
return if @tc_db
|
58
|
+
# puts "#{File.basename(__FILE__)}:#{__LINE__} open tc db: #{ @filename }"
|
59
|
+
#puts "#{File.basename(__FILE__)}:#{__LINE__} callers..."
|
60
|
+
#caller(0).each { | trace | puts " #{trace}"}
|
56
61
|
@tc_db = TDB.new
|
57
|
-
note_errors("TC:: tuning error: %s\n") do
|
62
|
+
note_errors("TC[[#{ @filename }]]:: tuning error: %s\n") do
|
58
63
|
@tc_db.tune(-1, -1, -1, TDB::TDEFLATE)
|
59
64
|
end
|
60
65
|
|
61
|
-
note_errors("TC:: open error: %s\n") do
|
66
|
+
note_errors("TC[[#{ @filename }]]:: open [#{ @filename }] error: %s\n") do
|
62
67
|
@tc_db.open(@filename, TDB::OWRITER | TDB::OCREAT | TDB::OLCKNB ) #TDB::OTSYNC slows it down by almost 50 times
|
63
68
|
end
|
64
69
|
|
65
70
|
# Don't care if there are errors (in fact, if the index exists a failure is the expected thing)
|
66
71
|
|
67
72
|
$lexical_indexes.each do | index_name |
|
68
|
-
@tc_db.setindex(index_name, TDB::ITLEXICAL | TDB::ITKEEP)
|
73
|
+
r = @tc_db.setindex(index_name, TDB::ITLEXICAL | TDB::ITKEEP)
|
69
74
|
end
|
70
75
|
$numeric_indexes.each do | index_name |
|
71
76
|
@tc_db.setindex(index_name, TDB::ITDECIMAL | TDB::ITKEEP)
|
@@ -84,7 +89,7 @@ module Xampl
|
|
84
89
|
@tc_db.setindex(index_name, 9998)
|
85
90
|
end
|
86
91
|
else
|
87
|
-
note_errors("TC:: optimisation error: %s\n") do
|
92
|
+
note_errors("TC[[#{ @filename }]]:: optimisation error: %s\n") do
|
88
93
|
@tc_db.optimize(-1, -1, -1, 0xff)
|
89
94
|
end
|
90
95
|
end
|
@@ -93,10 +98,11 @@ module Xampl
|
|
93
98
|
def close
|
94
99
|
if @tc_db then
|
95
100
|
self.sync
|
96
|
-
note_errors("TC:: close error: %s\n") do
|
101
|
+
note_errors("TC[[#{ @filename }]]:: close error: %s\n") do
|
97
102
|
@tc_db.close
|
98
103
|
end
|
99
104
|
@tc_db = nil
|
105
|
+
# puts "#{File.basename(__FILE__)}:#{__LINE__} close tc db: #{ @filename }"
|
100
106
|
end
|
101
107
|
end
|
102
108
|
|
@@ -274,6 +280,17 @@ module Xampl
|
|
274
280
|
end
|
275
281
|
|
276
282
|
def do_sync_write
|
283
|
+
# RubyProf.start
|
284
|
+
#
|
285
|
+
# do_sync_write_work
|
286
|
+
#
|
287
|
+
# result = RubyProf.stop
|
288
|
+
# printer = RubyProf::FlatPrinter.new(result)
|
289
|
+
# printer.print(STDOUT, 0)
|
290
|
+
# puts "#{File.basename(__FILE__)}:#{__LINE__} stop this profiler"
|
291
|
+
# end
|
292
|
+
#
|
293
|
+
# def do_sync_write_work
|
277
294
|
open_tc_db
|
278
295
|
@time_stamp = Time.now.to_f.to_s
|
279
296
|
|
@@ -283,7 +300,7 @@ module Xampl
|
|
283
300
|
# end
|
284
301
|
|
285
302
|
begin
|
286
|
-
note_errors("TC:: tranbegin error: %s\n") do
|
303
|
+
note_errors("TC[[#{ @filename }]]:: tranbegin error: %s\n") do
|
287
304
|
@tc_db.tranbegin
|
288
305
|
end
|
289
306
|
|
@@ -292,16 +309,16 @@ module Xampl
|
|
292
309
|
end
|
293
310
|
rescue => e
|
294
311
|
msg = "no TC.abort attempted"
|
295
|
-
msg = note_errors("TC:: trancommit error: %s\n") do
|
312
|
+
msg = note_errors("TC[[#{ @filename }]]:: trancommit error: %s\n") do
|
296
313
|
@tc_db.tranabort
|
297
314
|
end
|
298
315
|
raise "TokyoCabinetPersister Error:: #{ msg }/#{ e }"
|
299
316
|
else
|
300
|
-
note_errors("TC:: trancommit error: %s\n") do
|
317
|
+
note_errors("TC[[#{ @filename }]]:: trancommit error: %s\n") do
|
301
318
|
@tc_db.trancommit
|
302
319
|
end
|
303
320
|
ensure
|
304
|
-
# note_errors("TC:: close error: %s\n") do
|
321
|
+
# note_errors("TC[[#{ @filename }]]:: close error: %s\n") do
|
305
322
|
# @tc_db.close()
|
306
323
|
# end
|
307
324
|
end
|
@@ -317,7 +334,7 @@ module Xampl
|
|
317
334
|
|
318
335
|
query = TableQuery.new(@tc_db)
|
319
336
|
query.add_condition('xampl_from', :equals, place)
|
320
|
-
note_errors("TC:: failed to remove from mentions, error: %s\n") do
|
337
|
+
note_errors("TC[[#{ @filename }]]:: failed to remove from mentions, error: %s\n") do
|
321
338
|
query.searchout
|
322
339
|
end
|
323
340
|
|
@@ -333,7 +350,7 @@ module Xampl
|
|
333
350
|
'xampl_to' => mention_place
|
334
351
|
}
|
335
352
|
|
336
|
-
note_errors("TC:: write error: %s\n") do
|
353
|
+
note_errors("TC[[#{ @filename }]]:: write error: %s\n") do
|
337
354
|
@tc_db.put(pk, mention_hash)
|
338
355
|
end
|
339
356
|
end
|
@@ -350,7 +367,7 @@ module Xampl
|
|
350
367
|
xampl_hash = hash.merge(xampl_hash)
|
351
368
|
end
|
352
369
|
|
353
|
-
note_errors("TC:: write error: %s\n") do
|
370
|
+
note_errors("TC[[#{ @filename }]]:: write error: %s\n") do
|
354
371
|
@tc_db.put(place, xampl_hash)
|
355
372
|
end
|
356
373
|
|
@@ -359,7 +376,15 @@ module Xampl
|
|
359
376
|
return true
|
360
377
|
end
|
361
378
|
|
379
|
+
$TC_COUNT = 0
|
380
|
+
$FS_COUNT = 0
|
381
|
+
$NF_COUNT = 0
|
382
|
+
|
362
383
|
def read_representation(klass, pid)
|
384
|
+
#TODO -- is this being called too often, e.g. by new_xxx???
|
385
|
+
# puts "#{File.basename(__FILE__)}:#{__LINE__} READ #{ klass }/#{ pid }"
|
386
|
+
# caller(0).each { | trace | puts " #{trace}"}
|
387
|
+
|
363
388
|
open_tc_db
|
364
389
|
place = File.join(klass.name.split("::"), pid)
|
365
390
|
representation = nil
|
@@ -367,9 +392,22 @@ module Xampl
|
|
367
392
|
meta = @tc_db[place]
|
368
393
|
representation = meta['xampl'] if meta
|
369
394
|
|
395
|
+
# puts "#{File.basename(__FILE__)}:#{__LINE__} TC: #{ klass }/#{ pid }" if representation
|
396
|
+
$TC_COUNT += 1 if representation
|
397
|
+
|
370
398
|
# puts "read: #{ place }, size: #{ representation.size }"
|
371
399
|
# puts representation[0..100]
|
372
400
|
|
401
|
+
unless representation then
|
402
|
+
# try the filesystem if it is not in the TC repository
|
403
|
+
place = File.join(@root_dir, klass.name.split("::"), pid)
|
404
|
+
representation = File.read(place) if File.exist?(place)
|
405
|
+
$FS_COUNT += 1 if representation
|
406
|
+
# puts "#{File.basename(__FILE__)}:#{__LINE__} FS: #{ klass }/#{ pid } (FS: #{ $FS_COUNT}, TC: #{ $TC_COUNT }, NF: #{ $NF_COUNT }" if representation
|
407
|
+
end
|
408
|
+
# puts "#{File.basename(__FILE__)}:#{__LINE__} ??: #{ klass }/#{ pid }" unless representation
|
409
|
+
$NF_COUNT += 1
|
410
|
+
|
373
411
|
return representation
|
374
412
|
end
|
375
413
|
end
|