// Begin starts and returns a new transaction.
170803
func (c *Conn) Begin() (driver.Tx, error) {

	tx := Tx{
		conn: c,
	}

	return &tx, nil
}
826192
func (p *ConnPool) BeginEx(ctx context.Context, txOptions *TxOptions) (*Tx, error) {
	for {
		c, err := p.Acquire()
		if err != nil {
			return nil, err
		}

		tx, err := c.BeginEx(ctx, txOptions)
		if err != nil {
			alive := c.IsAlive()
			p.Release(c)

			// If connection is still alive then the error is not something trying
			// again on a new connection would fix, so just return the error. But
			// if the connection is dead try to acquire a new connection and try
			// again.
			if alive || ctx.Err() != nil {
				return nil, err
			}
			continue
		}

		tx.connPool = p
		return tx, nil
	}
}
928112
func (db *DB) Begin() (*Tx, error) {
	tx, err := begin(db)
	if err != nil {
		return nil, err
	}
	return &Tx{Tx: tx, DB: db}, nil
}
952405
func (s *tikvStore) BeginWithStartTS(startTS uint64) (kv.Transaction, error) {
	txn, err := newTikvTxnWithStartTS(s, startTS)
	if err != nil {
		return nil, errors.Trace(err)
	}
	metrics.TiKVTxnCounter.Inc()
	return txn, nil
}
24912
func (c *CouchDB) Start() error {
	p := ifrit.Invoke(c)

	select {
	case <-p.Ready():
		return nil
	case err := <-p.Wait():
		return err
	}
}
1275572
func (sr *SimpleRedis) start(db keyval.BytesBroker) {
	sr.log.Info("Start putting data to Redis...")
	time.Sleep(2 * time.Second)

	// basic key-value entry
	if err := db.Put(sr.prefix+"/key1", []byte("data1")); err != nil {
		sr.log.Errorf("put key1 failed: %v", err)
	} else {
		sr.log.Info("key1 stored in DB")
	}
	if data, found, _, err := db.GetValue(sr.prefix + "/key1"); err != nil {
		sr.log.Errorf("get key1 failed: %v", err)
	} else if !found {
		sr.log.Errorf("expected key1 does not exist: %v", err)
	} else {
		sr.log.Infof("key1 read from DB (data: %v)", data)
	}

	// key-value entry with TTL
	if err := db.Put(sr.prefix+"/key2", []byte("data2"), datasync.WithTTL(2*time.Second)); err != nil {
		sr.log.Errorf("put key1 failed: %v", err)
	}
	if data, found, _, err := db.GetValue(sr.prefix + "/key2"); err != nil {
		sr.log.Errorf("get key2 failed: %v", err)
	} else if !found {
		sr.log.Errorf("expected key2 does not exist: %v", err)
	} else {
		sr.log.Infof("key2 read from DB (data: %v)", data)
	}
	sr.log.Info("waiting for key2 TTL...")
	time.Sleep(3 * time.Second)
	if _, found, _, err := db.GetValue(sr.prefix + "/key2"); err != nil {
		sr.log.Errorf("get key2 after TTL failed: %v", err)
	} else if !found {
		sr.log.Info("key2 does not exist (expired TTL)")
	} else {
		sr.log.Error("key2 should not exist")
	}

	// put several another keys as txn
	sr.log.Info("Put a few more keys as transaction...")
	txn := db.NewTxn()
	for i := 3; i <= 11; i++ {
		txn.Put(sr.prefix+"/key"+strconv.Itoa(i), []byte("data"+strconv.Itoa(i)))
	}
	if err := txn.Commit(context.Background()); err != nil {
		sr.log.Errorf("failed to commit transaction: %v", err)
	}
	sr.log.Info("... done")

	// list keys
	sr.log.Info("Listing keys (expected 10 entries)")
	var count int8
	keys, err := db.ListKeys(sr.prefix)
	if err != nil {
		sr.log.Errorf("failed to list keys: %v", err)
	} else {
		for {
			key, _, done := keys.GetNext()
			if done {
				break
			}
			sr.log.Debugf("Found key %s", key)
			count++
		}
		if count == 10 {
			sr.log.Info("all expected keys were found")
		} else {
			sr.log.Errorf("failed to get all the keys (expected 10, got %d)", count)
		}
	}

	// list keys
	sr.log.Info("Listing values (expected 10 entries)")
	count = 0
	values, err := db.ListValues(sr.prefix)
	if err != nil {
		sr.log.Errorf("failed to list values: %v", err)
	} else {
		for {
			kv, done := values.GetNext()
			if done {
				break
			}
			sr.log.Debugf("Found value %s", string(kv.GetValue()))
			count++
		}
		if count == 10 {
			sr.log.Info("all expected values were found")
		} else {
			sr.log.Errorf("failed to get all the values (expected 10, got %d)", count)
		}
	}
}
1362813
func (c *SQLiteConn) Begin() (driver.Tx, error) {
	return c.begin(context.Background())
}
218805
func (w *Window) begin() {
	if currWin != w {
		w.window.MakeContextCurrent()
		currWin = w
	}
}
657277
func (s *InjectedStore) Begin() (Transaction, error) {
	txn, err := s.Storage.Begin()
	return &InjectedTransaction{
		Transaction: txn,
		cfg:         s.cfg,
	}, err
}
1025092
func (vtg *VTGate) Begin(ctx context.Context, singledb bool) (*vtgatepb.Session, error) {
	if !singledb && vtg.txConn.mode == vtgatepb.TransactionMode_SINGLE {
		return nil, vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "multi-db transaction disallowed")
	}
	return &vtgatepb.Session{
		InTransaction: true,
		SingleDb:      singledb,
	}, nil
}
693773
func (as *Step) Start(startTime *timestamp.Timestamp) bool {
	if as.Started != nil {
		return false
	}
	as.Started = startTime
	return true
}
151761
func (lb *LogBroker) Start(ctx context.Context) error {
	lb.mu.Lock()
	defer lb.mu.Unlock()

	if lb.cancelAll != nil {
		return errAlreadyRunning
	}

	lb.pctx, lb.cancelAll = context.WithCancel(ctx)
	lb.logQueue = watch.NewQueue()
	lb.subscriptionQueue = watch.NewQueue()
	lb.registeredSubscriptions = make(map[string]*subscription)
	lb.subscriptionsByNode = make(map[string]map[*subscription]struct{})
	return nil
}
141059
func (session *Session) Begin() error {
	if session.IsAutoCommit {
		tx, err := session.DB().Begin()
		if err != nil {
			return err
		}
		session.IsAutoCommit = false
		session.IsCommitedOrRollbacked = false
		session.Tx = tx
		session.saveLastSQL("BEGIN TRANSACTION")
	}
	return nil
}
257913
func (p *Process) Start() error {
	p.mtx.Lock()
	defer p.mtx.Unlock()

	// Valdiate that process is not already running and that we have a config.
	if p.running {
		return ErrRunning
	}
	return p.start()
}
200073
func (p *ConnPool) Begin() (*Tx, error) {
	return p.BeginEx(context.Background(), nil)
}
1322963
func (it *Iterator4Chunk) Begin() Row {
	it.numRows = int32(it.chk.NumRows())
	if it.numRows == 0 {
		return it.End()
	}
	it.cursor = 1
	return it.chk.GetRow(0)
}
733997
func (dbGorp *DbGorp) Begin() (txn *Transaction, err error) {
	tx, err := dbGorp.Map.Begin()
	if err != nil {
		return
	}
	txn = &Transaction{tx, dbGorp}
	return
}