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.

60 lines
1.5 KiB

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