seaweedfs/weed/storage/needle/compact_map_perf_test.go

46 lines
979 B
Go
Raw Normal View History

2017-05-27 13:51:25 +08:00
package needle
import (
2013-11-01 03:55:34 +08:00
"log"
"os"
"testing"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/util"
. "github.com/chrislusf/seaweedfs/weed/storage/types"
)
func TestMemoryUsage(t *testing.T) {
2017-05-27 13:51:25 +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)
}
2017-05-27 13:51:25 +08:00
loadNewNeedleMap(indexFile)
2013-01-17 16:56:56 +08:00
}
2017-05-27 13:51:25 +08:00
func loadNewNeedleMap(file *os.File) {
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()
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 {
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(NeedleId(key), offset, size)
2013-01-17 16:56:56 +08:00
} else {
//delete(m, key)
}
}
2013-01-17 16:56:56 +08:00
count, e = file.Read(bytes)
}
}