// Prewrite implements the MVCCStore interface.
Prewrite implements the MVCCStore interface.
// Prewrite implements the MVCCStore interface .
func (mvcc *MVCCRocksDB) Prewrite(req *kvrpcpb.PrewriteRequest) []error {
	mutations := req.Mutations
	primary := req.PrimaryLock
	startTS := req.StartVersion
	forUpdateTS := req.GetForUpdateTs()
	ttl := req.LockTtl
	minCommitTS := req.MinCommitTs
	mvcc.mu.Lock()
	defer mvcc.mu.Unlock()
	anyError := false
	batch := gorocksdb.NewWriteBatch()
	errs := make([]error, 0, len(mutations))
	txnSize := req.TxnSize
	for i, m := range mutations {
		var err error
		op := m.GetOp()
		if (op == kvrpcpb.Op_Insert || op == kvrpcpb.Op_CheckNotExists) && forUpdateTS == 0 {
			v, err := mvcc.getValue(m.Key, startTS, kvrpcpb.IsolationLevel_SI, req.Context.ResolvedLocks)
			if err != nil {
				errs = append(errs, err)
				anyError = true
				continue
			}
			if v != nil {
				err = &ErrKeyAlreadyExist{
					Key: m.Key,
				}
				errs = append(errs, err)
				anyError = true
				continue
			}
		}
		if op == kvrpcpb.Op_CheckNotExists {
			continue
		}
		isPessimisticLock := len(req.IsPessimisticLock) > 0 && req.IsPessimisticLock[i]
		err = prewriteMutation(mvcc.db, batch, m, startTS, primary, ttl, txnSize, isPessimisticLock, minCommitTS)
		errs = append(errs, err)
		if err != nil {
			anyError = true
		}
	}
	if anyError {
		return errs
	}
	if err := mvcc.db.Write(gorocksdb.NewDefaultWriteOptions(), batch); err != nil {
		return []error{err}
	}
	return errs
}
func ( mvcc * MVCCRocksDB ) Prewrite ( req * kvrpcpb . PrewriteRequest ) [ ] error { mutations := req . Mutations primary := req . PrimaryLock startTS := req . StartVersion forUpdateTS := req . GetForUpdateTs ( ) ttl := req . LockTtl minCommitTS := req . MinCommitTs mvcc . mu . Lock ( ) defer mvcc . mu . Unlock ( ) anyError := false batch := gorocksdb . NewWriteBatch ( ) errs := make ( [ ] error , 0 , len ( mutations ) ) txnSize := req . TxnSize for i , m := range mutations { var err error op := m . GetOp ( ) if ( op == kvrpcpb . Op_Insert || op == kvrpcpb . Op_CheckNotExists ) && forUpdateTS == 0 { v , err := mvcc . getValue ( m . Key , startTS , kvrpcpb . IsolationLevel_SI , req . Context . ResolvedLocks ) if err != nil { errs = append ( errs , err ) anyError = true continue } if v != nil { err = & ErrKeyAlreadyExist { Key : m . Key , } errs = append ( errs , err ) anyError = true continue } } if op == kvrpcpb . Op_CheckNotExists { continue } isPessimisticLock := len ( req . IsPessimisticLock ) > 0 && req . IsPessimisticLock [ i ] err = prewriteMutation ( mvcc . db , batch , m , startTS , primary , ttl , txnSize , isPessimisticLock , minCommitTS ) errs = append ( errs , err ) if err != nil { anyError = true } } if anyError { return errs } if err := mvcc . db . Write ( gorocksdb . NewDefaultWriteOptions ( ) , batch ) ; err != nil { return [ ] error { err } } return errs }
Prewrite implements the MVCCStore interface.
Prewrite implements the MVCCStore interface .
// If the operation is Insert, check if key is exists at first. // no need to check insert values for pessimistic transaction.