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.

45 lines
937 B

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