* Rework `needle_map.CompactMap()` to maximize memory efficiency. * Use a memory-efficient structure for `CompactMap` needle value entries. This slightly complicates the code, but makes a **massive** difference in memory efficiency - preliminary results show a ~30% reduction in heap usage, with no measurable performance impact otherwise. * Clean up type for `CompactMap` chunk IDs. * Add a small comment description for `CompactMap()`. * Add the old version of `CompactMap()` for comparison purposes.
36 lines
752 B
Go
36 lines
752 B
Go
//go:build 5BytesOffset
|
|
// +build 5BytesOffset
|
|
|
|
package needle_map
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test5bytesIndexLoading(t *testing.T) {
|
|
|
|
indexFile, ie := os.OpenFile("../../../test/data/187.idx", os.O_RDWR|os.O_RDONLY, 0644)
|
|
if ie != nil {
|
|
log.Fatalln(ie)
|
|
}
|
|
defer indexFile.Close()
|
|
m, rowCount := loadNewNeedleMap(indexFile)
|
|
|
|
println("total entries:", rowCount)
|
|
|
|
key := types.NeedleId(0x671b905) // 108116229
|
|
|
|
needle, found := m.Get(types.NeedleId(0x671b905))
|
|
|
|
fmt.Printf("%v key:%v offset:%v size:%v\n", found, key, needle.Offset, needle.Size)
|
|
|
|
assert.Equal(t, int64(12884911892)*8, needle.Offset.ToActualOffset(), "offset")
|
|
|
|
}
|