globals.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package storage
  11. import (
  12. "fmt"
  13. "devt.de/krotik/common/pools"
  14. )
  15. /*
  16. BufferPool is a pool of byte buffers.
  17. */
  18. var BufferPool = pools.NewByteBufferPool()
  19. /*
  20. Common storage manager related errors. Having these global definitions
  21. makes the error comparison easier but has potential race-conditions.
  22. If two storage manager objects throw an error at the same time both errors
  23. will appear to come from the same instance.
  24. */
  25. var (
  26. ErrSlotNotFound = newStorageManagerError("Slot not found")
  27. ErrNotInCache = newStorageManagerError("No entry in cache")
  28. )
  29. /*
  30. newStorageManagerError returns a new StorageManager specific error.
  31. */
  32. func newStorageManagerError(text string) *storagemanagerError {
  33. return &storagemanagerError{text, "?", ""}
  34. }
  35. /*
  36. StorageManager specific error datastructure
  37. */
  38. type storagemanagerError struct {
  39. msg string
  40. filename string
  41. info string
  42. }
  43. /*
  44. fireError returns the error instance from a specific StorageManager instance.
  45. */
  46. func (e *storagemanagerError) fireError(s Manager, info string) error {
  47. e.filename = s.Name()
  48. e.info = info
  49. return e
  50. }
  51. /*
  52. Error returns a string representation of the error.
  53. */
  54. func (e *storagemanagerError) Error() string {
  55. return fmt.Sprintf("%s (%s - %s)", e.msg, e.filename, e.info)
  56. }