-
Notifications
You must be signed in to change notification settings - Fork 4
/
genboltdb.go
72 lines (59 loc) · 1.66 KB
/
genboltdb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"log"
"strconv"
"github.com/boltdb/bolt"
)
const dbPath = "/tmp/test_benchmark_large.boltdb"
func main() {
db, err := bolt.Open(dbPath, 0644, nil)
if err != nil {
log.Fatalf("failured, can't open the boltdb, path=%s, err=%v", dbPath, err)
}
defer db.Close()
bucketName := []byte("MyBucket")
/* ISSUE : deadlock
// futex(0x550530, FUTEX_WAIT
err = dlog.Update(func(tx *bolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists(bucketName)
if err != nil {
log.Fatalf("failed, can't create or get bucket from boltDB(=%s), err=%v", dbPath, err)
return err
}
for i := int(0); i <= 100000000; i++ {
key := []byte(strconv.Itoa(i))
value := []byte(strconv.Itoa(i))
err = bucket.Put(key, value)
if err != nil {
log.Fatalf("failed, can't data(kv=%d) add to the boltdb(=%s), err=%v", i, dbPath, err)
return err
}
}
return nil
})
if err != nil {
log.Fatalf("exception : boltdb(=%s), err=%v", dbPath, err)
}
*/
for i := int(0); i <= 100000000; i++ {
key := []byte(strconv.Itoa(i))
value := []byte(strconv.Itoa(i))
err = db.Update(func(tx *bolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists(bucketName)
if err != nil {
log.Fatalf("failed, can't data(kv=%d) add to the boltdb(=%s), err=%v", i, dbPath, err)
return err
}
err = bucket.Put(key, value)
if err != nil {
log.Fatalf("failed, can't data(kv=%d) add to the boltdb(=%s), err=%v", i, dbPath, err)
return err
}
return nil
})
if err != nil {
log.Fatalf("exception : boltdb(=%s), err=%v", dbPath, err)
}
}
log.Println("complete")
}