update to include txn interface changes
This commit is contained in:
parent
0d6da8af0a
commit
7e629044e4
103
test.rb
103
test.rb
|
@ -3,20 +3,20 @@ require 'bdb2'
|
|||
|
||||
50.times {|n|
|
||||
db=Bdb::Db.new
|
||||
db.open("dbtest.db",nil,Bdb::Db::BTREE,Bdb::DB_CREATE,0)
|
||||
db.put(n.to_s,"ploppy #{n} #{Time.now}",0)
|
||||
db.open(nil,"dbtest.db",nil,Bdb::Db::BTREE,Bdb::DB_CREATE,0)
|
||||
db.put(nil,n.to_s,"ploppy #{n} #{Time.now}",0)
|
||||
db.close(0)
|
||||
}
|
||||
db=Bdb::Db.new
|
||||
db.open("dbtest.db",nil,nil,nil,0)
|
||||
db.open(nil,"dbtest.db",nil,nil,nil,0)
|
||||
500.times {|n|
|
||||
db.put(n.to_s,"ploppy #{n}",0)
|
||||
db.put(nil,n.to_s,"ploppy #{n}",0)
|
||||
}
|
||||
db.close(0)
|
||||
|
||||
db=Bdb::Db.new
|
||||
db.open("dbtest.db",nil,nil,nil,0)
|
||||
dbc=db.cursor(0)
|
||||
db.open(nil,"dbtest.db",nil,nil,nil,0)
|
||||
dbc=db.cursor(nil,0)
|
||||
puts("cursor is: "+dbc.inspect.to_s)
|
||||
kv=dbc.get(nil,nil,Bdb::DB_FIRST);
|
||||
puts("first data is: " + kv.inspect.to_s)
|
||||
|
@ -44,16 +44,16 @@ dbc.close
|
|||
db.close(0)
|
||||
|
||||
db=Bdb::Db.new
|
||||
db.open("dbtest.db",nil,nil,nil,0)
|
||||
db.open(nil,"dbtest.db",nil,nil,nil,0)
|
||||
5.times {|n|
|
||||
$stdout.puts(db.get(n.to_s,0))
|
||||
$stdout.puts(db.get(nil,n.to_s,nil,0))
|
||||
begin
|
||||
db.del(n.to_s,0)
|
||||
rescue
|
||||
end
|
||||
}
|
||||
5.times {|n|
|
||||
v=db.get(n.to_s,0)
|
||||
v=db.get(nil,n.to_s,nil,0)
|
||||
if v
|
||||
$stdout.puts("For #{n}:" + v)
|
||||
else
|
||||
|
@ -68,90 +68,63 @@ File.delete('db1.db') if File.exist?('db1.db')
|
|||
File.delete('db2.db') if File.exist?('db2.db')
|
||||
|
||||
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.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|
|
||||
key.split('-')[0]
|
||||
})
|
||||
|
||||
c=0
|
||||
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}% ")
|
||||
def write_data(db)
|
||||
c=0
|
||||
IO.popen("gzip -dc skus.gz") {|fd|
|
||||
tlen=fd.stat.size
|
||||
pf=tlen/10
|
||||
pl=0
|
||||
fd.each do |line|
|
||||
c+=1
|
||||
if c%1000==0
|
||||
$stderr.print('.')
|
||||
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
|
||||
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")
|
||||
} if File.exist?("skus.gz")
|
||||
$stderr.print("\ntotal count: #{c}\n")
|
||||
end
|
||||
|
||||
write_data(db)
|
||||
|
||||
db2.close(0)
|
||||
db.close(0)
|
||||
|
||||
$stderr.puts("test environment")
|
||||
|
||||
env=Bdb::Env.new
|
||||
env=Bdb::Env.new(0)
|
||||
env.cachesize=25*1024*1024;
|
||||
env.open(".",Bdb::DB_INIT_CDB|Bdb::DB_INIT_MPOOL|Bdb::DB_CREATE,0)
|
||||
|
||||
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.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|
|
||||
key.split('-')[0]
|
||||
})
|
||||
c=0
|
||||
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")
|
||||
|
||||
write_data(db)
|
||||
|
||||
db2.close(0)
|
||||
db.close(0)
|
||||
env.close
|
||||
|
||||
exit
|
||||
|
||||
$stderr.puts(Rusage.get.inspect)
|
||||
$stderr.puts(`ps -up #{$$}`)
|
||||
|
|
Loading…
Reference in a new issue