errors.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. package badger
  17. import (
  18. "encoding/hex"
  19. "github.com/pkg/errors"
  20. )
  21. var (
  22. // ErrValueLogSize is returned when opt.ValueLogFileSize option is not within the valid
  23. // range.
  24. ErrValueLogSize = errors.New("Invalid ValueLogFileSize, must be between 1MB and 2GB")
  25. // ErrValueThreshold is returned when ValueThreshold is set to a value close to or greater than
  26. // uint16.
  27. ErrValueThreshold = errors.New("Invalid ValueThreshold, must be lower than uint16.")
  28. // ErrKeyNotFound is returned when key isn't found on a txn.Get.
  29. ErrKeyNotFound = errors.New("Key not found")
  30. // ErrTxnTooBig is returned if too many writes are fit into a single transaction.
  31. ErrTxnTooBig = errors.New("Txn is too big to fit into one request")
  32. // ErrConflict is returned when a transaction conflicts with another transaction. This can happen if
  33. // the read rows had been updated concurrently by another transaction.
  34. ErrConflict = errors.New("Transaction Conflict. Please retry")
  35. // ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.
  36. ErrReadOnlyTxn = errors.New("No sets or deletes are allowed in a read-only transaction")
  37. // ErrDiscardedTxn is returned if a previously discarded transaction is re-used.
  38. ErrDiscardedTxn = errors.New("This transaction has been discarded. Create a new one")
  39. // ErrEmptyKey is returned if an empty key is passed on an update function.
  40. ErrEmptyKey = errors.New("Key cannot be empty")
  41. // ErrRetry is returned when a log file containing the value is not found.
  42. // This usually indicates that it may have been garbage collected, and the
  43. // operation needs to be retried.
  44. ErrRetry = errors.New("Unable to find log file. Please retry")
  45. // ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.
  46. // In such a case, GC can't be run.
  47. ErrThresholdZero = errors.New(
  48. "Value log GC can't run because threshold is set to zero")
  49. // ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.
  50. ErrNoRewrite = errors.New(
  51. "Value log GC attempt didn't result in any cleanup")
  52. // ErrRejected is returned if a value log GC is called either while another GC is running, or
  53. // after DB::Close has been called.
  54. ErrRejected = errors.New("Value log GC request rejected")
  55. // ErrInvalidRequest is returned if the user request is invalid.
  56. ErrInvalidRequest = errors.New("Invalid request")
  57. // ErrManagedTxn is returned if the user tries to use an API which isn't
  58. // allowed due to external management of transactions, when using ManagedDB.
  59. ErrManagedTxn = errors.New(
  60. "Invalid API request. Not allowed to perform this action using ManagedDB")
  61. // ErrInvalidDump if a data dump made previously cannot be loaded into the database.
  62. ErrInvalidDump = errors.New("Data dump cannot be read")
  63. // ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.
  64. ErrZeroBandwidth = errors.New("Bandwidth must be greater than zero")
  65. // ErrInvalidLoadingMode is returned when opt.ValueLogLoadingMode option is not
  66. // within the valid range
  67. ErrInvalidLoadingMode = errors.New("Invalid ValueLogLoadingMode, must be FileIO or MemoryMap")
  68. // ErrReplayNeeded is returned when opt.ReadOnly is set but the
  69. // database requires a value log replay.
  70. ErrReplayNeeded = errors.New("Database was not properly closed, cannot open read-only")
  71. // ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows
  72. ErrWindowsNotSupported = errors.New("Read-only mode is not supported on Windows")
  73. // ErrTruncateNeeded is returned when the value log gets corrupt, and requires truncation of
  74. // corrupt data to allow Badger to run properly.
  75. ErrTruncateNeeded = errors.New("Value log truncate required to run DB. This might result in data loss.")
  76. // ErrBlockedWrites is returned if the user called DropAll. During the process of dropping all
  77. // data from Badger, we stop accepting new writes, by returning this error.
  78. ErrBlockedWrites = errors.New("Writes are blocked possibly due to DropAll")
  79. )
  80. // Key length can't be more than uint16, as determined by table::header.
  81. const maxKeySize = 1<<16 - 8 // 8 bytes are for storing timestamp
  82. func exceedsMaxKeySizeError(key []byte) error {
  83. return errors.Errorf("Key with size %d exceeded %d limit. Key:\n%s",
  84. len(key), maxKeySize, hex.Dump(key[:1<<10]))
  85. }
  86. func exceedsMaxValueSizeError(value []byte, maxValueSize int64) error {
  87. return errors.Errorf("Value with size %d exceeded ValueLogFileSize (%d). Key:\n%s",
  88. len(value), maxValueSize, hex.Dump(value[:1<<10]))
  89. }