2019-12-24 22:55:50 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
2021-10-14 04:27:58 +00:00
|
|
|
"os"
|
2019-12-24 22:55:50 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
. "github.com/seaweedfs/seaweedfs/weed/storage/types"
|
2019-12-24 22:55:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFastLoadingNeedleMapMetrics(t *testing.T) {
|
|
|
|
|
2021-10-14 04:27:58 +00:00
|
|
|
idxFile, _ := os.CreateTemp("", "tmp.idx")
|
2019-12-24 22:55:50 +00:00
|
|
|
nm := NewCompactNeedleMap(idxFile)
|
|
|
|
|
|
|
|
for i := 0; i < 10000; i++ {
|
2020-08-19 00:04:28 +00:00
|
|
|
nm.Put(Uint64ToNeedleId(uint64(i+1)), Uint32ToOffset(uint32(0)), Size(1))
|
2019-12-24 22:55:50 +00:00
|
|
|
if rand.Float32() < 0.2 {
|
2020-09-12 19:42:36 +00:00
|
|
|
nm.Delete(Uint64ToNeedleId(uint64(rand.Int63n(int64(i))+1)), Uint32ToOffset(uint32(0)))
|
2019-12-24 22:55:50 +00: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())
|
|
|
|
}
|