2018-07-07 15:51:17 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2018-07-08 17:39:04 +08:00
|
|
|
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
2018-07-22 08:39:10 +08:00
|
|
|
"io/ioutil"
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
2018-07-07 15:51:17 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFastLoadingNeedleMapMetrics(t *testing.T) {
|
|
|
|
|
|
|
|
idxFile, _ := ioutil.TempFile("", "tmp.idx")
|
|
|
|
nm := NewBtreeNeedleMap(idxFile)
|
|
|
|
|
|
|
|
for i := 0; i < 10000; i++ {
|
2018-07-08 17:39:04 +08:00
|
|
|
nm.Put(Uint64ToNeedleId(uint64(i+1)), Uint32ToOffset(uint32(0)), uint32(1))
|
2018-07-07 15:51:17 +08:00
|
|
|
if rand.Float32() < 0.2 {
|
2018-07-08 17:39:04 +08:00
|
|
|
nm.Delete(Uint64ToNeedleId(uint64(rand.Int63n(int64(i))+1)), Uint32ToOffset(uint32(0)))
|
2018-07-07 15:51:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mm, _ := newNeedleMapMetricFromIndexFile(idxFile)
|
|
|
|
|
|
|
|
glog.V(0).Infof("FileCount expected %d actual %d", nm.FileCount(), mm.FileCount())
|
|
|
|
glog.V(0).Infof("DeletedSize expected %d actual %d", nm.DeletedSize(), mm.DeletedSize())
|
|
|
|
glog.V(0).Infof("ContentSize expected %d actual %d", nm.ContentSize(), mm.ContentSize())
|
|
|
|
glog.V(0).Infof("DeletedCount expected %d actual %d", nm.DeletedCount(), mm.DeletedCount())
|
|
|
|
glog.V(0).Infof("MaxFileKey expected %d actual %d", nm.MaxFileKey(), mm.MaxFileKey())
|
|
|
|
}
|