// Begin will create a transaction in the DB with a context
171094
func (r *DB) Begin() (err error) {
	if r.inTx > 0 {
		_, err = r.Exec(fmt.Sprintf("SAVEPOINT sp_%d", r.inTx))
	}
	if r.inTx == 0 {
		if r.ctx == nil {
			r.Log(func() {
				r.Tx, err = r.DB.Beginx()
			}, "BEGIN;")
		} else {
			r.Log(func() {
				r.Tx, err = r.DB.BeginTxx(r.ctx, r.TxOpts)
			}, "BEGIN; -- with context")
		}
	}
	if err != nil {
		return errors.WithStack(err)
	}

	r.inTx++
	return nil
}
555811
func Begin(name string) Op {
	return &op{ctx: cm.Enter().Put("op", name).PutIfAbsent("root_op", name)}
}
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
}
287768
func (dec *Decoder) begin() (err error) {
	inBracket := false
	valBracket := ""
	bracketClosed := false
	lastPos := 0
	tmp := dec.field

	// parse path
	for i, char := range tmp {
		if char == '[' && inBracket == false {
			// found an opening bracket
			bracketClosed = false
			inBracket = true
			dec.field = tmp[lastPos:i]
			lastPos = i + 1
			/*
				if err = dec.walk(); err != nil {
					return
				}
			*/
			continue
		} else if inBracket {
			// it is inside of bracket, so get its value
			if char == ']' {
				/*
					nextChar := tmp[i+1:]
					if nextChar != "" {
						t := nextChar[:1]
						if t != "[" && t != "." {
							valBracket += string(char)
							continue
						}
					}
				*/
				// found an closing bracket, so it will be recently close, so put as true the bracketClosed
				// and put as false inBracket and pass the value of bracket to dec.key
				inBracket = false
				bracketClosed = true
				dec.bracket = valBracket
				lastPos = i + 1
				if err = dec.walk(); err != nil {
					return
				}
				valBracket = ""
			} else {
				// still inside the bracket, so follow getting its value
				valBracket += string(char)
			}
			continue
		} else if !inBracket {
			// not found any bracket, so try found a field
			if char == '.' {
				// found a field, we need to know if the field is next of a closing bracket,
				// for example: [0].Field
				if bracketClosed {
					bracketClosed = false
					lastPos = i + 1
					continue
				}
				// found a field, but is not next of a closing bracket, for example: Field1.Field2
				dec.field = tmp[lastPos:i]
				//dec.field = tmp[:i]
				lastPos = i + 1
				if err = dec.walk(); err != nil {
					return
				}
			}
			continue
		}
	}
	// last field of path
	dec.field = tmp[lastPos:]

	return dec.end()
}
723666
func (conn *FakeVTGateConn) Begin(ctx context.Context, singledb bool) (*vtgatepb.Session, error) {
	return &vtgatepb.Session{
		InTransaction: true,
		SingleDb:      singledb,
	}, nil
}
349329
func (c *Conn) BeginEx(ctx context.Context, txOptions *TxOptions) (*Tx, error) {
	_, err := c.ExecEx(ctx, txOptions.beginSQL(), nil)
	if err != nil {
		// begin should never fail unless there is an underlying connection issue or
		// a context timeout. In either case, the connection is possibly broken.
		c.die(errors.New("failed to begin transaction"))
		return nil, err
	}

	return &Tx{conn: c}, nil
}
879385
func (ms *MetaStore) TransactionContext(ctx context.Context, writable bool) (context.Context, Transactor, error) {
	ms.dbL.Lock()
	if ms.db == nil {
		db, err := bolt.Open(ms.dbfile, 0600, nil)
		if err != nil {
			ms.dbL.Unlock()
			return ctx, nil, errors.Wrap(err, "failed to open database file")
		}
		ms.db = db
	}
	ms.dbL.Unlock()

	tx, err := ms.db.Begin(writable)
	if err != nil {
		return ctx, nil, errors.Wrap(err, "failed to start transaction")
	}

	ctx = context.WithValue(ctx, transactionKey{}, tx)

	return ctx, tx, nil
}
126756
func (conn *VTGateConn) Begin(ctx context.Context) (*VTGateTx, error) {
	session, err := conn.impl.Begin(ctx, false /* singledb */)
	if err != nil {
		return nil, err
	}

	return &VTGateTx{
		conn:    conn,
		session: session,
	}, nil
}
1246890
func (db *DBLogger) Beginx() (*TxLogger, error) {
	tx, err := db.DB.Beginx()
	return &TxLogger{tx}, err
}
355243
func (s *server) Start(ctx context.Context, request *mysqlctlpb.StartRequest) (*mysqlctlpb.StartResponse, error) {
	return &mysqlctlpb.StartResponse{}, s.mysqld.Start(ctx, s.cnf, request.MysqldArgs...)
}
567933
func (r *Redshift) Begin() (*sql.Tx, error) {
	return r.dbExecCloser.BeginTx(r.ctx, nil)
}
1135273
func (sbc *SandboxConn) BeginExecute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, error) {
	transactionID, err := sbc.Begin(ctx, target, options)
	if err != nil {
		return nil, 0, err
	}
	result, err := sbc.Execute(ctx, target, query, bindVars, transactionID, options)
	return result, transactionID, err
}
362618
func (bldr *fooBarQueryBuilder) Start(cur datastore.Cursor) *fooBarQueryBuilder {
	bldr.q = bldr.q.Start(cur)
	if bldr.plugin != nil {
		bldr.plugin.Start(cur)
	}
	return bldr
}
1187893
func Begin(logger *log.Logger, dev string) *Operation {
	return &Operation{logger: logger, dev: dev}
}
108584
func (db *DB) Context() context.Context {
	if db.ctx != nil {
		return db.ctx
	}
	return context.Background()
}
1209442
func (te *TxEngine) Begin(ctx context.Context, options *querypb.ExecuteOptions) (int64, string, error) {
	span, ctx := trace.NewSpan(ctx, "TxEngine.Begin")
	defer span.Finish()
	te.stateLock.Lock()

	canOpenTransactions := te.state == AcceptingReadOnly || te.state == AcceptingReadAndWrite
	if !canOpenTransactions {
		// We are not in a state where we can start new transactions. Abort.
		te.stateLock.Unlock()
		return 0, "", vterrors.Errorf(vtrpc.Code_UNAVAILABLE, "tx engine can't accept new transactions in state %v", te.state)
	}

	isWriteTransaction := options == nil || options.TransactionIsolation != querypb.ExecuteOptions_CONSISTENT_SNAPSHOT_READ_ONLY
	if te.state == AcceptingReadOnly && isWriteTransaction {
		te.stateLock.Unlock()
		return 0, "", vterrors.Errorf(vtrpc.Code_UNAVAILABLE, "tx engine can only accept read-only transactions in current state")
	}

	// By Add() to beginRequests, we block others from initiating state
	// changes until we have finished adding this transaction
	te.beginRequests.Add(1)
	te.stateLock.Unlock()

	defer te.beginRequests.Done()
	return te.txPool.Begin(ctx, options)
}
353425
func (tx *Tx) BeginBatch() *Batch {
	return &Batch{conn: tx.conn, inTx: true}
}