errors.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. stderrors "errors"
  19. "math"
  20. )
  21. const (
  22. // ValueThresholdLimit is the maximum permissible value of opt.ValueThreshold.
  23. ValueThresholdLimit = math.MaxUint16 - 16 + 1
  24. )
  25. var (
  26. // ErrValueLogSize is returned when opt.ValueLogFileSize option is not within the valid
  27. // range.
  28. ErrValueLogSize = stderrors.New("Invalid ValueLogFileSize, must be in range [1MB, 2GB)")
  29. // ErrKeyNotFound is returned when key isn't found on a txn.Get.
  30. ErrKeyNotFound = stderrors.New("Key not found")
  31. // ErrTxnTooBig is returned if too many writes are fit into a single transaction.
  32. ErrTxnTooBig = stderrors.New("Txn is too big to fit into one request")
  33. // ErrConflict is returned when a transaction conflicts with another transaction. This can
  34. // happen if the read rows had been updated concurrently by another transaction.
  35. ErrConflict = stderrors.New("Transaction Conflict. Please retry")
  36. // ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.
  37. ErrReadOnlyTxn = stderrors.New("No sets or deletes are allowed in a read-only transaction")
  38. // ErrDiscardedTxn is returned if a previously discarded transaction is re-used.
  39. ErrDiscardedTxn = stderrors.New("This transaction has been discarded. Create a new one")
  40. // ErrEmptyKey is returned if an empty key is passed on an update function.
  41. ErrEmptyKey = stderrors.New("Key cannot be empty")
  42. // ErrInvalidKey is returned if the key has a special !badger! prefix,
  43. // reserved for internal usage.
  44. ErrInvalidKey = stderrors.New("Key is using a reserved !badger! prefix")
  45. // ErrBannedKey is returned if the read/write key belongs to any banned namespace.
  46. ErrBannedKey = stderrors.New("Key is using the banned prefix")
  47. // ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.
  48. // In such a case, GC can't be run.
  49. ErrThresholdZero = stderrors.New(
  50. "Value log GC can't run because threshold is set to zero")
  51. // ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.
  52. ErrNoRewrite = stderrors.New(
  53. "Value log GC attempt didn't result in any cleanup")
  54. // ErrRejected is returned if a value log GC is called either while another GC is running, or
  55. // after DB::Close has been called.
  56. ErrRejected = stderrors.New("Value log GC request rejected")
  57. // ErrInvalidRequest is returned if the user request is invalid.
  58. ErrInvalidRequest = stderrors.New("Invalid request")
  59. // ErrManagedTxn is returned if the user tries to use an API which isn't
  60. // allowed due to external management of transactions, when using ManagedDB.
  61. ErrManagedTxn = stderrors.New(
  62. "Invalid API request. Not allowed to perform this action using ManagedDB")
  63. // ErrNamespaceMode is returned if the user tries to use an API which is allowed only when
  64. // NamespaceOffset is non-negative.
  65. ErrNamespaceMode = stderrors.New(
  66. "Invalid API request. Not allowed to perform this action when NamespaceMode is not set.")
  67. // ErrInvalidDump if a data dump made previously cannot be loaded into the database.
  68. ErrInvalidDump = stderrors.New("Data dump cannot be read")
  69. // ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.
  70. ErrZeroBandwidth = stderrors.New("Bandwidth must be greater than zero")
  71. // ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows
  72. ErrWindowsNotSupported = stderrors.New("Read-only mode is not supported on Windows")
  73. // ErrPlan9NotSupported is returned when opt.ReadOnly is used on Plan 9
  74. ErrPlan9NotSupported = stderrors.New("Read-only mode is not supported on Plan 9")
  75. // ErrTruncateNeeded is returned when the value log gets corrupt, and requires truncation of
  76. // corrupt data to allow Badger to run properly.
  77. ErrTruncateNeeded = stderrors.New(
  78. "Log truncate required to run DB. This might result in data loss")
  79. // ErrBlockedWrites is returned if the user called DropAll. During the process of dropping all
  80. // data from Badger, we stop accepting new writes, by returning this error.
  81. ErrBlockedWrites = stderrors.New("Writes are blocked, possibly due to DropAll or Close")
  82. // ErrNilCallback is returned when subscriber's callback is nil.
  83. ErrNilCallback = stderrors.New("Callback cannot be nil")
  84. // ErrEncryptionKeyMismatch is returned when the storage key is not
  85. // matched with the key previously given.
  86. ErrEncryptionKeyMismatch = stderrors.New("Encryption key mismatch")
  87. // ErrInvalidDataKeyID is returned if the datakey id is invalid.
  88. ErrInvalidDataKeyID = stderrors.New("Invalid datakey id")
  89. // ErrInvalidEncryptionKey is returned if length of encryption keys is invalid.
  90. ErrInvalidEncryptionKey = stderrors.New("Encryption key's length should be" +
  91. "either 16, 24, or 32 bytes")
  92. // ErrGCInMemoryMode is returned when db.RunValueLogGC is called in in-memory mode.
  93. ErrGCInMemoryMode = stderrors.New("Cannot run value log GC when DB is opened in InMemory mode")
  94. // ErrDBClosed is returned when a get operation is performed after closing the DB.
  95. ErrDBClosed = stderrors.New("DB Closed")
  96. )