func (d *db) Commit(b engine.Batch) error { bt, ok := b.(*batch) if !ok { return errors.Errorf("invalid batch type %T", b) } err := d.DB.Update(func(tx *bolt.Tx) error { b := tx.Bucket(bucketName) // err1 is used for passing `go tool vet --shadow` check. var err1 error for _, w := range bt.Writes { if w.Value != nil { err1 = b.Put(w.Key, w.Value) } else { err1 = b.Delete(w.Key) } if err1 != nil { return errors.Trace(err1) } } return nil }) return errors.Trace(err) }
func (s *dbStore) writeBatch(b engine.Batch) error { if b.Len() == 0 { return nil } err := s.db.Commit(b) if err != nil { log.Error(err) return errors.Trace(err) } return nil }
func (s *dbStore) writeBatch(b engine.Batch) error { if b.Len() == 0 { return nil } s.mu.Lock() defer s.mu.Unlock() if s.closed { return errors.Trace(ErrDBClosed) } err := s.db.Commit(b) if err != nil { log.Error(err) return errors.Trace(err) } return nil }
func (d *db) Commit(b engine.Batch) error { bt, ok := b.(*batch) if !ok { return errors.Errorf("invalid batch type %T", b) } err := d.DB.Update(func(tx *bolt.Tx) error { b := tx.Bucket(bucketName) var err error for _, w := range bt.writes { if !w.isDelete { err = b.Put(w.key, w.value) } else { err = b.Delete(w.key) } if err != nil { return errors.Trace(err) } } return nil }) return errors.Trace(err) }