update to include txn interface changes

This commit is contained in:
danj 2007-12-04 16:23:21 +00:00
parent 0d6da8af0a
commit 7e629044e4

79
test.rb
View file

@ -3,20 +3,20 @@ require 'bdb2'
50.times {|n| 50.times {|n|
db=Bdb::Db.new db=Bdb::Db.new
db.open("dbtest.db",nil,Bdb::Db::BTREE,Bdb::DB_CREATE,0) db.open(nil,"dbtest.db",nil,Bdb::Db::BTREE,Bdb::DB_CREATE,0)
db.put(n.to_s,"ploppy #{n} #{Time.now}",0) db.put(nil,n.to_s,"ploppy #{n} #{Time.now}",0)
db.close(0) db.close(0)
} }
db=Bdb::Db.new db=Bdb::Db.new
db.open("dbtest.db",nil,nil,nil,0) db.open(nil,"dbtest.db",nil,nil,nil,0)
500.times {|n| 500.times {|n|
db.put(n.to_s,"ploppy #{n}",0) db.put(nil,n.to_s,"ploppy #{n}",0)
} }
db.close(0) db.close(0)
db=Bdb::Db.new db=Bdb::Db.new
db.open("dbtest.db",nil,nil,nil,0) db.open(nil,"dbtest.db",nil,nil,nil,0)
dbc=db.cursor(0) dbc=db.cursor(nil,0)
puts("cursor is: "+dbc.inspect.to_s) puts("cursor is: "+dbc.inspect.to_s)
kv=dbc.get(nil,nil,Bdb::DB_FIRST); kv=dbc.get(nil,nil,Bdb::DB_FIRST);
puts("first data is: " + kv.inspect.to_s) puts("first data is: " + kv.inspect.to_s)
@ -44,16 +44,16 @@ dbc.close
db.close(0) db.close(0)
db=Bdb::Db.new db=Bdb::Db.new
db.open("dbtest.db",nil,nil,nil,0) db.open(nil,"dbtest.db",nil,nil,nil,0)
5.times {|n| 5.times {|n|
$stdout.puts(db.get(n.to_s,0)) $stdout.puts(db.get(nil,n.to_s,nil,0))
begin begin
db.del(n.to_s,0) db.del(n.to_s,0)
rescue rescue
end end
} }
5.times {|n| 5.times {|n|
v=db.get(n.to_s,0) v=db.get(nil,n.to_s,nil,0)
if v if v
$stdout.puts("For #{n}:" + v) $stdout.puts("For #{n}:" + v)
else else
@ -68,19 +68,20 @@ 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')
db=Bdb::Db.new db=Bdb::Db.new
db.open("db1.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0) db.open(nil,"db1.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0)
db2=Bdb::Db.new db2=Bdb::Db.new
db2.flags=Bdb::DB_DUPSORT db2.flags=Bdb::DB_DUPSORT
db2.open("db2.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0) db2.open(nil,"db2.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0)
db.associate(db2,0, db.associate(nil,db2,0,
proc {|sdb,key,data| proc {|sdb,key,data|
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
@ -88,70 +89,42 @@ File.open("skus") {|fd|
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 end
line.chomp! line.chomp!
n=line*50 n=line*50 # multiply the amount of data written
isbn,item=line.split('|')[0..1] isbn,item=line.split('|')[0..1]
sku="%s-%03d"%[isbn,item] sku="%s-%03d"%[isbn,item]
db.put(sku,line,0) db.put(nil,sku,line,0)
end end
} } if File.exist?("skus.gz")
$stderr.print("\ntotal count: #{c}\n") $stderr.print("\ntotal count: #{c}\n")
end
write_data(db)
db2.close(0) db2.close(0)
db.close(0) db.close(0)
$stderr.puts("test environment") $stderr.puts("test environment")
env=Bdb::Env.new 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)
db=env.db db=env.db
db.open("db1.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0) db.open(nil,"db1.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0)
db2=env.db db2=env.db
db2.flags=Bdb::DB_DUPSORT db2.flags=Bdb::DB_DUPSORT
db2.open("db2.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0) db2.open(nil,"db2.db",nil,Bdb::Db::HASH,Bdb::DB_CREATE,0)
db.associate(db2,0, db.associate(nil,db2,0,
proc {|sdb,key,data| proc {|sdb,key,data|
key.split('-')[0] key.split('-')[0]
}) })
c=0
File.open("skus") {|fd| write_data(db)
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
exit
$stderr.puts(Rusage.get.inspect)
$stderr.puts(`ps -up #{$$}`)