func (s Store) Open(dbPath string, cfg *config.Config) (driver.IDB, error) { os.MkdirAll(dbPath, 0755) name := path.Join(dbPath, "ledis_bolt.db") db := new(DB) var err error db.path = name db.cfg = cfg db.db, err = bolt.Open(name, 0600, nil) if err != nil { return nil, err } var tx *bolt.Tx tx, err = db.db.Begin(true) if err != nil { return nil, err } _, err = tx.CreateBucketIfNotExists(bucketName) if err != nil { tx.Rollback() return nil, err } if err = tx.Commit(); err != nil { return nil, err } return db, nil }
func Open(dbPath string, conf *Config, create, repair bool) (*BoltDB, error) { os.MkdirAll(dbPath, 0755) name := path.Join(dbPath, "rpdb_bolt.db") db := &BoltDB{ path: dbPath, cfg: conf, } var err error db.db, err = bolt.Open(name, 0600, nil) if err != nil { return nil, err } var tx *bolt.Tx tx, err = db.db.Begin(true) if err != nil { return nil, err } _, err = tx.CreateBucketIfNotExists(bucketName) if err != nil { tx.Rollback() return nil, err } if err = tx.Commit(); err != nil { return nil, err } return db, nil }
func Open(cfg *Config) (*DB, error) { os.MkdirAll(cfg.Path, os.ModePerm) name := path.Join(cfg.Path, "ledis_bolt.db") db := new(DB) var err error db.db, err = bolt.Open(name, 0600, nil) if err != nil { return nil, err } db.db.NoSync = cfg.NoSync var tx *bolt.Tx tx, err = db.db.Begin(true) if err != nil { return nil, err } _, err = tx.CreateBucketIfNotExists(bucketName) if err != nil { tx.Rollback() return nil, err } if err = tx.Commit(); err != nil { return nil, err } return db, nil }
func (db *DB) Open(dbPath string) error { var ( err error boltDB *bolt.DB ) boltDB, err = bolt.Open(dbPath, 0600, nil) if err != nil { return err } var tx *bolt.Tx tx, err = boltDB.Begin(true) if err != nil { return err } bucketName := []byte(base64.StdEncoding.EncodeToString([]byte(dbPath))) _, err = tx.CreateBucketIfNotExists(bucketName) if err != nil { tx.Rollback() return err } if err = tx.Commit(); err != nil { return err } db.boltDB = boltDB db.dbPath = dbPath db.bucketName = bucketName return nil }
func (self *Progress) commit(tx *bolt.Tx) { // Commit the transaction and check for error. log.Println("Committing the changes") if err := tx.Commit(); err != nil { log.Println("Rolling back transaction", err) tx.Rollback() } }