Junk db util (#3284)

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
This commit is contained in:
ledgerwatch 2022-01-18 05:03:23 +00:00 committed by GitHub
parent 4622287834
commit 3655916eb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2331,6 +2331,45 @@ func mainnetGenesis() error {
return nil
}
func junkdb() error {
dir, err := ioutil.TempDir(".", "junk")
if err != nil {
return fmt.Errorf("creating temp dir for db size test: %w", err)
}
//defer os.RemoveAll(dir)
oneBucketCfg := make(kv.TableCfg)
oneBucketCfg["t"] = kv.TableCfgItem{}
var db kv.RwDB
db, err = mdbx.NewMDBX(log.New()).Path(dir).WithTablessCfg(func(kv.TableCfg) kv.TableCfg {
return oneBucketCfg
}).Open()
if err != nil {
return fmt.Errorf("opening database: %w", err)
}
defer db.Close()
for i := 0; i < 1_000_000; i++ {
if err = db.Update(context.Background(), func(tx kv.RwTx) error {
c, e := tx.RwCursor("t")
if e != nil {
return e
}
defer c.Close()
for j := 0; j < 1_000_000_000; j++ {
var b [8]byte
binary.BigEndian.PutUint64(b[:], uint64(i*1_000_000_000+j))
if e = c.Append(b[:], b[:]); e != nil {
return e
}
}
return nil
}); err != nil {
return err
}
log.Info("Appended records", "bln", i+1)
}
return nil
}
func main() {
debug.RaiseFdLimit()
flag.Parse()
@ -2502,6 +2541,8 @@ func main() {
err = genstate()
case "mainnetGenesis":
err = mainnetGenesis()
case "junkdb":
err = junkdb()
}
if err != nil {