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.

46 lines
1.0 KiB

11 years ago
7 years ago
7 years ago
7 years ago
  1. package needle
  2. import (
  3. "log"
  4. "os"
  5. "testing"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  8. "github.com/chrislusf/seaweedfs/weed/util"
  9. )
  10. func TestMemoryUsage(t *testing.T) {
  11. indexFile, ie := os.OpenFile("../../../test/sample.idx", os.O_RDWR|os.O_RDONLY, 0644)
  12. if ie != nil {
  13. log.Fatalln(ie)
  14. }
  15. loadNewNeedleMap(indexFile)
  16. }
  17. func loadNewNeedleMap(file *os.File) {
  18. m := NewCompactMap()
  19. bytes := make([]byte, 16*1024)
  20. count, e := file.Read(bytes)
  21. if count > 0 {
  22. fstat, _ := file.Stat()
  23. glog.V(0).Infoln("Loading index file", fstat.Name(), "size", fstat.Size())
  24. }
  25. for count > 0 && e == nil {
  26. for i := 0; i < count; i += 16 {
  27. key := BytesToNeedleId(bytes[i : i+NeedleIdSize])
  28. offset := BytesToOffset(bytes[i+NeedleIdSize : i+NeedleIdSize+OffsetSize])
  29. size := util.BytesToUint32(bytes[i+NeedleIdSize+OffsetSize : i+NeedleIdSize+OffsetSize+SizeSize])
  30. if offset > 0 {
  31. m.Set(NeedleId(key), offset, size)
  32. } else {
  33. //delete(m, key)
  34. }
  35. }
  36. count, e = file.Read(bytes)
  37. }
  38. }