github.com/pingcap/badger@v1.5.1-0.20230103063557-828f39b09b6d/errors.go (about)

     1  /*
     2   * Copyright 2017 Dgraph Labs, Inc. and Contributors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package badger
    18  
    19  import (
    20  	"encoding/hex"
    21  
    22  	"github.com/pingcap/errors"
    23  )
    24  
    25  var (
    26  	// ErrValueLogSize is returned when opt.ValueLogFileSize option is not within the valid
    27  	// range.
    28  	ErrValueLogSize = errors.New("Invalid ValueLogFileSize, must be between 1MB and 2GB")
    29  
    30  	// ErrValueThreshold is returned when ValueThreshold is set to a value close to or greater than
    31  	// uint16.
    32  	ErrValueThreshold = errors.New("Invalid ValueThreshold, must be lower than uint16.")
    33  
    34  	// ErrKeyNotFound is returned when key isn't found on a txn.Get.
    35  	ErrKeyNotFound = errors.New("Key not found")
    36  
    37  	// ErrTxnTooBig is returned if too many writes are fit into a single transaction.
    38  	ErrTxnTooBig = errors.New("Txn is too big to fit into one request")
    39  
    40  	// ErrConflict is returned when a transaction conflicts with another transaction. This can happen if
    41  	// the read rows had been updated concurrently by another transaction.
    42  	ErrConflict = errors.New("Transaction Conflict. Please retry")
    43  
    44  	// ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.
    45  	ErrReadOnlyTxn = errors.New("No sets or deletes are allowed in a read-only transaction")
    46  
    47  	// ErrDiscardedTxn is returned if a previously discarded transaction is re-used.
    48  	ErrDiscardedTxn = errors.New("This transaction has been discarded. Create a new one")
    49  
    50  	// ErrEmptyKey is returned if an empty key is passed on an update function.
    51  	ErrEmptyKey = errors.New("Key cannot be empty")
    52  
    53  	// ErrRetry is returned when a log file containing the value is not found.
    54  	// This usually indicates that it may have been garbage collected, and the
    55  	// operation needs to be retried.
    56  	ErrRetry = errors.New("Unable to find log file. Please retry")
    57  
    58  	// ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.
    59  	// In such a case, GC can't be run.
    60  	ErrThresholdZero = errors.New(
    61  		"Value log GC can't run because threshold is set to zero")
    62  
    63  	// ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.
    64  	ErrNoRewrite = errors.New(
    65  		"Value log GC attempt didn't result in any cleanup")
    66  
    67  	// ErrRejected is returned if a value log GC is called either while another GC is running, or
    68  	// after DB::Close has been called.
    69  	ErrRejected = errors.New("Value log GC request rejected")
    70  
    71  	// ErrInvalidRequest is returned if the user request is invalid.
    72  	ErrInvalidRequest = errors.New("Invalid request")
    73  
    74  	// ErrManagedTxn is returned if the user tries to use an API which isn't
    75  	// allowed due to external management of transactions, when using ManagedDB.
    76  	ErrManagedTxn = errors.New(
    77  		"Invalid API request. Not allowed to perform this action using ManagedDB")
    78  
    79  	// ErrInvalidDump if a data dump made previously cannot be loaded into the database.
    80  	ErrInvalidDump = errors.New("Data dump cannot be read")
    81  
    82  	// ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.
    83  	ErrZeroBandwidth = errors.New("Bandwidth must be greater than zero")
    84  
    85  	// ErrReplayNeeded is returned when opt.ReadOnly is set but the
    86  	// database requires a value log replay.
    87  	ErrReplayNeeded = errors.New("Database was not properly closed, cannot open read-only")
    88  
    89  	// ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows
    90  	ErrWindowsNotSupported = errors.New("Read-only mode is not supported on Windows")
    91  
    92  	// ErrTruncateNeeded is returned when the value log gets corrupt, and requires truncation of
    93  	// corrupt data to allow Badger to run properly.
    94  	ErrTruncateNeeded = errors.New("Value log truncate required to run DB. This might result in data loss.")
    95  
    96  	// ErrTruncateNeeded is returned when UserMate size exceed 255.
    97  	ErrUserMetaTooLarge = errors.New("UserMate size exceed 255.")
    98  )
    99  
   100  // Key length can't be more than uint16, as determined by table::header.
   101  const maxKeySize = 1<<16 - 8 // 8 bytes are for storing timestamp
   102  
   103  func exceedsMaxKeySizeError(key []byte) error {
   104  	return errors.Errorf("Key with size %d exceeded %d limit. Key:\n%s",
   105  		len(key), maxKeySize, hex.Dump(key[:1<<10]))
   106  }
   107  
   108  func exceedsMaxValueSizeError(value []byte, maxValueSize int64) error {
   109  	return errors.Errorf("Value with size %d exceeded ValueLogFileSize (%d). Key:\n%s",
   110  		len(value), maxValueSize, hex.Dump(value[:1<<10]))
   111  }