You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.6 KiB

  1. package storage
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/chrislusf/weed-fs/go/util"
  6. )
  7. type NeedleMapType int
  8. const (
  9. NeedleMapInMemory NeedleMapType = iota
  10. NeedleMapLevelDb
  11. NeedleMapBoltDb
  12. )
  13. type NeedleMapper interface {
  14. Put(key uint64, offset uint32, size uint32) error
  15. Get(key uint64) (element *NeedleValue, ok bool)
  16. Delete(key uint64) error
  17. Close()
  18. Destroy() error
  19. ContentSize() uint64
  20. DeletedSize() uint64
  21. FileCount() int
  22. DeletedCount() int
  23. MaxFileKey() uint64
  24. }
  25. type mapMetric struct {
  26. DeletionCounter int `json:"DeletionCounter"`
  27. FileCounter int `json:"FileCounter"`
  28. DeletionByteCounter uint64 `json:"DeletionByteCounter"`
  29. FileByteCounter uint64 `json:"FileByteCounter"`
  30. MaximumFileKey uint64 `json:"MaxFileKey"`
  31. }
  32. func appendToIndexFile(indexFile *os.File,
  33. key uint64, offset uint32, size uint32) error {
  34. bytes := make([]byte, 16)
  35. util.Uint64toBytes(bytes[0:8], key)
  36. util.Uint32toBytes(bytes[8:12], offset)
  37. util.Uint32toBytes(bytes[12:16], size)
  38. if _, err := indexFile.Seek(0, 2); err != nil {
  39. return fmt.Errorf("cannot seek end of indexfile %s: %v",
  40. indexFile.Name(), err)
  41. }
  42. _, err := indexFile.Write(bytes)
  43. return err
  44. }
  45. func (mm *mapMetric) logDelete(deletedByteCount uint32) {
  46. mm.DeletionByteCounter = mm.DeletionByteCounter + uint64(deletedByteCount)
  47. mm.DeletionCounter++
  48. }
  49. func (mm *mapMetric) logPut(key uint64, oldSize uint32, newSize uint32) {
  50. if key > mm.MaximumFileKey {
  51. mm.MaximumFileKey = key
  52. }
  53. mm.FileCounter++
  54. mm.FileByteCounter = mm.FileByteCounter + uint64(newSize)
  55. if oldSize > 0 {
  56. mm.DeletionCounter++
  57. mm.DeletionByteCounter = mm.DeletionByteCounter + uint64(oldSize)
  58. }
  59. }