2012-09-30 07:07:24 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2013-11-01 03:55:34 +08:00
|
|
|
"log"
|
2014-03-03 14:16:54 +08:00
|
|
|
"os"
|
2012-09-30 07:07:24 +08:00
|
|
|
"testing"
|
2014-10-27 02:34:55 +08:00
|
|
|
|
2015-04-17 03:18:06 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/go/glog"
|
2016-04-09 06:52:03 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/go/util"
|
2012-09-30 07:07:24 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMemoryUsage(t *testing.T) {
|
|
|
|
|
2013-02-10 19:49:51 +08:00
|
|
|
indexFile, ie := os.OpenFile("../../test/sample.idx", os.O_RDWR|os.O_RDONLY, 0644)
|
2013-01-17 16:56:56 +08:00
|
|
|
if ie != nil {
|
|
|
|
log.Fatalln(ie)
|
|
|
|
}
|
|
|
|
LoadNewNeedleMap(indexFile)
|
|
|
|
|
2012-09-30 07:07:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadNewNeedleMap(file *os.File) CompactMap {
|
2013-01-17 16:56:56 +08:00
|
|
|
m := NewCompactMap()
|
|
|
|
bytes := make([]byte, 16*1024)
|
|
|
|
count, e := file.Read(bytes)
|
|
|
|
if count > 0 {
|
|
|
|
fstat, _ := file.Stat()
|
2013-08-09 14:57:22 +08:00
|
|
|
glog.V(0).Infoln("Loading index file", fstat.Name(), "size", fstat.Size())
|
2013-01-17 16:56:56 +08:00
|
|
|
}
|
|
|
|
for count > 0 && e == nil {
|
|
|
|
for i := 0; i < count; i += 16 {
|
2016-04-09 06:52:03 +08:00
|
|
|
key := util.BytesToUint64(bytes[i : i+8])
|
|
|
|
offset := util.BytesToUint32(bytes[i+8 : i+12])
|
|
|
|
size := util.BytesToUint32(bytes[i+12 : i+16])
|
2013-01-17 16:56:56 +08:00
|
|
|
if offset > 0 {
|
|
|
|
m.Set(Key(key), offset, size)
|
|
|
|
} else {
|
|
|
|
//delete(m, key)
|
|
|
|
}
|
|
|
|
}
|
2012-09-30 07:07:24 +08:00
|
|
|
|
2013-01-17 16:56:56 +08:00
|
|
|
count, e = file.Read(bytes)
|
|
|
|
}
|
|
|
|
return m
|
2012-09-30 07:07:24 +08:00
|
|
|
}
|