github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/storage/kv/errors.go (about)

     1  // Copyright 2022 zGraph Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package kv
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/pingcap/errors"
    21  )
    22  
    23  var (
    24  	// ErrTxnConflicts indicates the current transaction contains some vertex/edge/index
    25  	// conflicts with others.
    26  	ErrTxnConflicts = errors.New("transaction conflicts")
    27  
    28  	// ErrNotExist means the related data not exist.
    29  	ErrNotExist = errors.New("not exist")
    30  
    31  	// ErrCannotSetNilValue is the error when sets an empty value.
    32  	ErrCannotSetNilValue = errors.New("can not set nil value")
    33  
    34  	// ErrInvalidTxn is the error when commits or rollbacks in an invalid transaction.
    35  	ErrInvalidTxn = errors.New("invalid transaction")
    36  
    37  	ErrInvalidStartVer = errors.New("invalid start timestamp for transaction")
    38  )
    39  
    40  // ErrEntryTooLarge is the error when a key value entry is too large.
    41  type ErrEntryTooLarge struct {
    42  	Limit uint64
    43  	Size  uint64
    44  }
    45  
    46  func (e *ErrEntryTooLarge) Error() string {
    47  	return fmt.Sprintf("entry size too large, size: %v,limit: %v.", e.Size, e.Limit)
    48  }
    49  
    50  // ErrTxnTooLarge is the error when transaction is too large, lock time reached the maximum value.
    51  type ErrTxnTooLarge struct {
    52  	Size int
    53  }
    54  
    55  func (e *ErrTxnTooLarge) Error() string {
    56  	return fmt.Sprintf("txn too large, size: %v.", e.Size)
    57  }
    58  
    59  func IsErrNotFound(err error) bool {
    60  	return errors.Cause(err) == ErrNotExist
    61  }
    62  
    63  // ErrKeyAlreadyExist is returned when key exists but this key has a constraint that
    64  // it should not exist. Client should return duplicated entry error.
    65  type ErrKeyAlreadyExist struct {
    66  	Key []byte
    67  }
    68  
    69  func (e *ErrKeyAlreadyExist) Error() string {
    70  	return fmt.Sprintf("key already exist, key: %q", e.Key)
    71  }
    72  
    73  // ErrGroup is used to collect multiple errors.
    74  type ErrGroup struct {
    75  	Errors []error
    76  }
    77  
    78  func (e *ErrGroup) Error() string {
    79  	return fmt.Sprintf("Errors: %v", e.Errors)
    80  }
    81  
    82  // ErrConflict is returned when the commitTS of key in the DB is greater than startTS.
    83  type ErrConflict struct {
    84  	StartVer          Version
    85  	ConflictStartVer  Version
    86  	ConflictCommitVer Version
    87  	Key               Key
    88  }
    89  
    90  func (e *ErrConflict) Error() string {
    91  	return "write conflict"
    92  }