2017-05-27 05:51:25 +00:00
|
|
|
package needle
|
2012-09-29 23:07:24 +00:00
|
|
|
|
|
|
|
import (
|
2013-10-31 19:55:34 +00:00
|
|
|
"log"
|
2014-03-03 06:16:54 +00:00
|
|
|
"os"
|
2012-09-29 23:07:24 +00:00
|
|
|
"testing"
|
2014-10-26 18:34:55 +00:00
|
|
|
|
2016-06-03 01:09:14 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2018-07-08 09:28:04 +00:00
|
|
|
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
2018-07-22 00:39:10 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2012-09-29 23:07:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMemoryUsage(t *testing.T) {
|
|
|
|
|
2017-05-27 05:51:25 +00:00
|
|
|
indexFile, ie := os.OpenFile("../../../test/sample.idx", os.O_RDWR|os.O_RDONLY, 0644)
|
2013-01-17 08:56:56 +00:00
|
|
|
if ie != nil {
|
|
|
|
log.Fatalln(ie)
|
|
|
|
}
|
2017-05-27 05:51:25 +00:00
|
|
|
loadNewNeedleMap(indexFile)
|
2013-01-17 08:56:56 +00:00
|
|
|
|
2012-09-29 23:07:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-27 05:51:25 +00:00
|
|
|
func loadNewNeedleMap(file *os.File) {
|
2013-01-17 08:56:56 +00:00
|
|
|
m := NewCompactMap()
|
|
|
|
bytes := make([]byte, 16*1024)
|
|
|
|
count, e := file.Read(bytes)
|
|
|
|
if count > 0 {
|
|
|
|
fstat, _ := file.Stat()
|
2013-08-09 06:57:22 +00:00
|
|
|
glog.V(0).Infoln("Loading index file", fstat.Name(), "size", fstat.Size())
|
2013-01-17 08:56:56 +00:00
|
|
|
}
|
|
|
|
for count > 0 && e == nil {
|
|
|
|
for i := 0; i < count; i += 16 {
|
2018-07-22 00:39:10 +00:00
|
|
|
key := BytesToNeedleId(bytes[i : i+NeedleIdSize])
|
|
|
|
offset := BytesToOffset(bytes[i+NeedleIdSize : i+NeedleIdSize+OffsetSize])
|
|
|
|
size := util.BytesToUint32(bytes[i+NeedleIdSize+OffsetSize : i+NeedleIdSize+OffsetSize+SizeSize])
|
2018-07-08 09:39:04 +00:00
|
|
|
|
2013-01-17 08:56:56 +00:00
|
|
|
if offset > 0 {
|
2018-07-08 09:28:04 +00:00
|
|
|
m.Set(NeedleId(key), offset, size)
|
2013-01-17 08:56:56 +00:00
|
|
|
} else {
|
|
|
|
//delete(m, key)
|
|
|
|
}
|
|
|
|
}
|
2012-09-29 23:07:24 +00:00
|
|
|
|
2013-01-17 08:56:56 +00:00
|
|
|
count, e = file.Read(bytes)
|
|
|
|
}
|
2012-09-29 23:07:24 +00:00
|
|
|
}
|