Browse Source

Merge pull request #107 from lsytj0413/fix-106

fix: ensure the buckets is exists when use boltdb
pull/110/head
yedf2 4 years ago
committed by GitHub
parent
commit
d1d50d631d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      dtmsvr/storage/boltdb.go

19
dtmsvr/storage/boltdb.go

@ -21,6 +21,20 @@ func boltGet() *bolt.DB {
boltOnce.Do(func() { boltOnce.Do(func() {
db, err := bolt.Open("./dtm.bolt", 0666, &bolt.Options{Timeout: 1 * time.Second}) db, err := bolt.Open("./dtm.bolt", 0666, &bolt.Options{Timeout: 1 * time.Second})
dtmimp.E2P(err) dtmimp.E2P(err)
// NOTE: we must ensure all buckets is exists before we use it
err = db.Update(func(t *bolt.Tx) error {
for _, bucket := range allBuckets {
_, err := t.CreateBucketIfNotExists(bucket)
if err != nil {
return err
}
}
return nil
})
dtmimp.E2P(err)
boltDb = db boltDb = db
}) })
return boltDb return boltDb
@ -29,6 +43,11 @@ func boltGet() *bolt.DB {
var bucketGlobal = []byte("global") var bucketGlobal = []byte("global")
var bucketBranches = []byte("branches") var bucketBranches = []byte("branches")
var bucketIndex = []byte("index") var bucketIndex = []byte("index")
var allBuckets = [][]byte{
bucketGlobal,
bucketBranches,
bucketIndex,
}
func tGetGlobal(t *bolt.Tx, gid string) *TransGlobalStore { func tGetGlobal(t *bolt.Tx, gid string) *TransGlobalStore {
trans := TransGlobalStore{} trans := TransGlobalStore{}

Loading…
Cancel
Save