needle_map_metric_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. package storage
  2. import (
  3. "math/rand"
  4. "os"
  5. "testing"
  6. "github.com/seaweedfs/seaweedfs/weed/glog"
  7. . "github.com/seaweedfs/seaweedfs/weed/storage/types"
  8. )
  9. func TestFastLoadingNeedleMapMetrics(t *testing.T) {
  10. idxFile, _ := os.CreateTemp("", "tmp.idx")
  11. nm := NewCompactNeedleMap(idxFile)
  12. for i := 0; i < 10000; i++ {
  13. nm.Put(Uint64ToNeedleId(uint64(i+1)), Uint32ToOffset(uint32(0)), Size(1))
  14. if rand.Float32() < 0.2 && i > 0 {
  15. nm.Delete(Uint64ToNeedleId(uint64(rand.Int63n(int64(i))+1)), Uint32ToOffset(uint32(0)))
  16. }
  17. }
  18. mm, _ := newNeedleMapMetricFromIndexFile(idxFile)
  19. glog.V(0).Infof("FileCount expected %d actual %d", nm.FileCount(), mm.FileCount())
  20. glog.V(0).Infof("DeletedSize expected %d actual %d", nm.DeletedSize(), mm.DeletedSize())
  21. glog.V(0).Infof("ContentSize expected %d actual %d", nm.ContentSize(), mm.ContentSize())
  22. glog.V(0).Infof("DeletedCount expected %d actual %d", nm.DeletedCount(), mm.DeletedCount())
  23. glog.V(0).Infof("MaxFileKey expected %d actual %d", nm.MaxFileKey(), mm.MaxFileKey())
  24. }