integrate K. Burge changes

This commit is contained in:
danj 2008-11-07 21:16:45 +00:00
parent b869f6b33b
commit ef151477bf
4 changed files with 495 additions and 150 deletions

518
bdb.c

File diff suppressed because it is too large Load diff

9
bdb.h
View file

@ -23,7 +23,7 @@
#define FNLEN 40 #define FNLEN 40
#define filename_copy(fp,fv) \ #define filename_copy(fp,fv) \
strncpy(fp,RSTRING(fv)->ptr,FNLEN); strncpy(fp,RSTRING_PTR(fv),FNLEN);
#define filename_dup(fpd,fps) \ #define filename_dup(fpd,fps) \
strncpy(fpd,fps,FNLEN); strncpy(fpd,fps,FNLEN);
@ -57,8 +57,11 @@ typedef struct s_txnh {
t_envh *env; t_envh *env;
} t_txnh; } t_txnh;
#define ci(b,m) \ #define cu(b,m) \
rb_define_const(b,#m,INT2FIX(m)) rb_define_const(b,#m,UINT2NUM(m))
#define ci(b,m) \
rb_define_const(b,#m,INT2NUM(m))
#define cs(b,m) \ #define cs(b,m) \
rb_define_const(b,#m,rb_str_new2(m)) rb_define_const(b,#m,rb_str_new2(m))

View file

@ -18,6 +18,10 @@ Options:
calls. Note the impact on indicating the include, below. calls. Note the impact on indicating the include, below.
If you have not used bdb2 before, you need not use this argument. If you have not used bdb2 before, you need not use this argument.
--nsl add nsl rpc library to build (4.4 uses rpc for replication)
--usedb berkeley db root
-h,--help this -h,--help this
--dbh {dir for db.h} --dbh {dir for db.h}
@ -30,7 +34,9 @@ end
opts = GetoptLong.new( opts = GetoptLong.new(
[ "--va", GetoptLong::NO_ARGUMENT], [ "--va", GetoptLong::NO_ARGUMENT],
[ "--nsl", GetoptLong::NO_ARGUMENT],
[ "-h","--help",GetoptLong::NO_ARGUMENT], [ "-h","--help",GetoptLong::NO_ARGUMENT],
[ "--usedb", GetoptLong::REQUIRED_ARGUMENT],
[ "--dbh", GetoptLong::REQUIRED_ARGUMENT] [ "--dbh", GetoptLong::REQUIRED_ARGUMENT]
) )
opts.each do |opt,arg| opts.each do |opt,arg|
@ -42,6 +48,10 @@ opts.each do |opt,arg|
exit exit
when '--dbh' when '--dbh'
$dbh_location=arg $dbh_location=arg
when '--nsl'
$libs << " -lnsl"
when '--usedb'
$usedb=arg
end end
end end
@ -75,12 +85,14 @@ when /solaris2/
$libs << " -lnsl" $libs << " -lnsl"
end end
versions=%w(db-4.5 db-4.4 db-4.3 db-4.2) versions=%w(db-4.6 db-4.5 db-4.4 db-4.3 db-4.2)
locations=%w(/usr/local/lib /opt/local/lib /usr/local/BerkeleyDB.4.3/lib /usr/local/BerkeleyDB.4.2/lib /opt/csw/bdb44/lib) locations=%w(/usr/local/lib /opt/local/lib /usr/lib)
until versions.empty? until versions.empty?
(lib_ok=find_library(this_version=versions.shift,'db_create',*locations)) && break (lib_ok=find_library(this_version=versions.shift,'db_create',*locations)) && break
end end
$stderr.puts(this_version)
$maj,$min=0,0 $maj,$min=0,0
if try_link0(<<SRC) if try_link0(<<SRC)
#include <db.h> #include <db.h>
@ -129,6 +141,7 @@ h_test_locations=%w(
/usr/local /usr/local
/opt/csw/bdb44/include /opt/csw/bdb44/include
) )
h_test_locations.unshift($usedb) if $usedb
h_test_locations.unshift($dbh_location) if $dbh_location h_test_locations.unshift($dbh_location) if $dbh_location
message("Header test locations are #{h_test_locations.inspect}\n") message("Header test locations are #{h_test_locations.inspect}\n")
found=false found=false
@ -157,7 +170,7 @@ end
# the above result, but it is another check. # the above result, but it is another check.
# Find db.h, not sure this will work everywhere, gcc is ok # Find db.h, not sure this will work everywhere, gcc is ok
src=create_tmpsrc("#include <db.h>") src=create_tmpsrc("#include <db.h>")
cmd=cpp_command("-M") cmd=cpp_command(RUBY_PLATFORM =~ /mswin/ ? nil : "-M")
r=`#{cmd}` r=`#{cmd}`
header_loc=r.split.collect {|k| k if k =~ %r{^/.*db.h} }.compact[0] header_loc=r.split.collect {|k| k if k =~ %r{^/.*db.h} }.compact[0]
message("header is #{header_loc}\n") message("header is #{header_loc}\n")
@ -170,14 +183,24 @@ File.open(File.join($db_inc,"db.h")) {|fd|
File.open("bdb_aux._c","w") {|hd| File.open("bdb_aux._c","w") {|hd|
hd.puts("/* This file automatically generated by extconf.rb */\n") hd.puts("/* This file automatically generated by extconf.rb */\n")
fd.each_line {|l| fd.each_line {|l|
if l =~ %r{^#define\s+(DBC?_\w*)\s+(\"?)} and macro_defined?($1,inc) if l =~ %r{^#define\s+(DBC?_\w*)\s+([^\/]*)\s*(.*?)(\/\*.*)?$}
if $2 == '\"' name = $1
hd.print(%Q{ cs(mBdb,%s);\n}%[$1]) value = $2
else if macro_defined?(name,inc)
hd.print(%Q{ ci(mBdb,%s);\n}%[$1]) case value
when /^"/
hd.print(%Q{ cs(mBdb,%s);\n}%[name])
when /^\(?(0x|\d)/
hd.print(%Q{ cu(mBdb,%s);\n}%[name])
when /^\(?-/
hd.print(%Q{ ci(mBdb,%s);\n}%[name])
else
$stderr.puts "don't know how to handle #{name} #{value}, guessing UINT"
hd.print(%Q{ cu(mBdb,%s);\n}%[name])
end
message(".")
n+=1
end end
message(".")
n+=1
end end
} }
} }

75
test.rb
View file

@ -67,6 +67,7 @@ $stderr.puts("All OK!")
File.delete('db1.db') if File.exist?('db1.db') File.delete('db1.db') if File.exist?('db1.db')
File.delete('db2.db') if File.exist?('db2.db') File.delete('db2.db') if File.exist?('db2.db')
if File.exist?('skus')
db=Bdb::Db.new db=Bdb::Db.new
db.open(nil,"db1.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0) db.open(nil,"db1.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0)
@ -79,34 +80,37 @@ db.associate(nil,db2,0,
key.split('-')[0] key.split('-')[0]
}) })
def write_data(db) c=0
c=0 File.open("skus") {|fd|
IO.popen("gzip -dc skus.gz") {|fd| tlen=fd.stat.size
tlen=fd.stat.size pf=tlen/10
pf=tlen/10 pl=0
pl=0 fd.each do |line|
fd.each do |line| c+=1
c+=1 if c%1000==0
if c%1000==0 $stderr.print('.')
$stderr.print('.') cp=fd.pos
if ( cp/pf > pl )
pl=cp/pf
$stderr.print(" #{pl*10}% ")
end end
line.chomp!
n=line*50 # multiply the amount of data written
isbn,item=line.split('|')[0..1]
sku="%s-%03d"%[isbn,item]
db.put(nil,sku,line,0)
end end
} if File.exist?("skus.gz") line.chomp!
$stderr.print("\ntotal count: #{c}\n") n=line*50
end isbn,item=line.split('|')[0..1]
sku="%s-%03d"%[isbn,item]
write_data(db) db.put(sku,line,0)
end
}
$stderr.print("\ntotal count: #{c}\n")
db2.close(0) db2.close(0)
db.close(0) db.close(0)
end
$stderr.puts("test environment") $stderr.puts("test environment")
if File.exist?('skus')
env=Bdb::Env.new(0) env=Bdb::Env.new(0)
env.cachesize=25*1024*1024; env.cachesize=25*1024*1024;
env.open(".",Bdb::DB_INIT_CDB|Bdb::DB_INIT_MPOOL|Bdb::DB_CREATE,0) env.open(".",Bdb::DB_INIT_CDB|Bdb::DB_INIT_MPOOL|Bdb::DB_CREATE,0)
@ -122,9 +126,36 @@ db.associate(nil,db2,0,
proc {|sdb,key,data| proc {|sdb,key,data|
key.split('-')[0] key.split('-')[0]
}) })
c=0
write_data(db) File.open("skus") {|fd|
tlen=fd.stat.size
pf=tlen/10
pl=0
fd.each do |line|
c+=1
if c%1000==0
$stderr.print('.')
cp=fd.pos
if ( cp/pf > pl )
pl=cp/pf
$stderr.print(" #{pl*10}% ")
end
end
line.chomp!
n=line*50
isbn,item=line.split('|')[0..1]
sku="%s-%03d"%[isbn,item]
db.put(sku,line,0)
end
}
$stderr.print("\ntotal count: #{c}\n")
db2.close(0) db2.close(0)
db.close(0) db.close(0)
env.close env.close
end
exit
$stderr.puts(Rusage.get.inspect)
$stderr.puts(`ps -up #{$$}`)