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.

43 lines
919 B

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