// PessimisticLock writes the pessimistic lock.
PessimisticLock writes the pessimistic lock.
// PessimisticLock writes the pessimistic lock .
func (mvcc *MVCCRocksDB) PessimisticLock(req *kvrpcpb.PessimisticLockRequest) *kvrpcpb.PessimisticLockResponse {
	resp := &kvrpcpb.PessimisticLockResponse{}
	mvcc.mu.Lock()
	defer mvcc.mu.Unlock()
	mutations := req.Mutations
	lCtx := &lockCtx{
		startTS:      req.StartVersion,
		forUpdateTS:  req.ForUpdateTs,
		primary:      req.PrimaryLock,
		ttl:          req.LockTtl,
		minCommitTs:  req.MinCommitTs,
		returnValues: req.ReturnValues,
	}
	lockWaitTime := req.WaitTimeout
	anyError := false
	batch := gorocksdb.NewWriteBatch()
	errs := make([]error, 0, len(mutations))
	for _, m := range mutations {
		err := mvcc.pessimisticLockMutation(batch, m, lCtx)
		errs = append(errs, err)
		if err != nil {
			anyError = true
		}
		if lockWaitTime == kv.LockNoWait {
			if _, ok := err.(*ErrLocked); ok {
				break
			}
		}
	}
	if anyError {
		if lockWaitTime != kv.LockNoWait {
			simulateServerSideWaitLock(errs)
		}
		resp.Errors = convertToKeyErrors(errs)
		return resp
	}
	if err := mvcc.db.Write(gorocksdb.NewDefaultWriteOptions(), batch); err != nil {
		resp.Errors = convertToKeyErrors([]error{err})
		return resp
	}
	if req.ReturnValues {
		resp.Values = lCtx.values
	}
	return resp
}
func ( mvcc * MVCCRocksDB ) PessimisticLock ( req * kvrpcpb . PessimisticLockRequest ) * kvrpcpb . PessimisticLockResponse { resp := & kvrpcpb . PessimisticLockResponse { } mvcc . mu . Lock ( ) defer mvcc . mu . Unlock ( ) mutations := req . Mutations lCtx := & lockCtx { startTS : req . StartVersion , forUpdateTS : req . ForUpdateTs , primary : req . PrimaryLock , ttl : req . LockTtl , minCommitTs : req . MinCommitTs , returnValues : req . ReturnValues , } lockWaitTime := req . WaitTimeout anyError := false batch := gorocksdb . NewWriteBatch ( ) errs := make ( [ ] error , 0 , len ( mutations ) ) for _ , m := range mutations { err := mvcc . pessimisticLockMutation ( batch , m , lCtx ) errs = append ( errs , err ) if err != nil { anyError = true } if lockWaitTime == kv . LockNoWait { if _ , ok := err . ( * ErrLocked ) ; ok { break } } } if anyError { if lockWaitTime != kv . LockNoWait { simulateServerSideWaitLock ( errs ) } resp . Errors = convertToKeyErrors ( errs ) return resp } if err := mvcc . db . Write ( gorocksdb . NewDefaultWriteOptions ( ) , batch ) ; err != nil { resp . Errors = convertToKeyErrors ( [ ] error { err } ) return resp } if req . ReturnValues { resp . Values = lCtx . values } return resp }
PessimisticLock writes the pessimistic lock.
PessimisticLock writes the pessimistic lock .
// TODO: remove this when implement sever side wait.