2020-06-25 23:36:06 +00:00
|
|
|
package erasure_coding
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPositioning(t *testing.T) {
|
|
|
|
|
|
|
|
ecxFile, err := os.OpenFile("389.ecx", os.O_RDONLY, 0)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("failed to open ecx file: %v", err)
|
|
|
|
}
|
|
|
|
defer ecxFile.Close()
|
|
|
|
|
|
|
|
stat, _ := ecxFile.Stat()
|
|
|
|
fileSize := stat.Size()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
needleId string
|
2020-07-14 14:34:16 +00:00
|
|
|
offset int64
|
|
|
|
size int
|
2020-06-25 23:36:06 +00:00
|
|
|
}{
|
|
|
|
{needleId: "0f0edb92", offset: 31300679656, size: 1167},
|
|
|
|
{needleId: "0ef7d7f8", offset: 11513014944, size: 66044},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
needleId, _ := types.ParseNeedleId(test.needleId)
|
|
|
|
offset, size, err := SearchNeedleFromSortedIndex(ecxFile, fileSize, needleId, nil)
|
|
|
|
assert.Equal(t, nil, err, "SearchNeedleFromSortedIndex")
|
2021-02-07 04:11:51 +00:00
|
|
|
fmt.Printf("offset: %d size: %d\n", offset.ToActualOffset(), size)
|
2020-06-25 23:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
needleId, _ := types.ParseNeedleId("0f087622")
|
|
|
|
offset, size, err := SearchNeedleFromSortedIndex(ecxFile, fileSize, needleId, nil)
|
|
|
|
assert.Equal(t, nil, err, "SearchNeedleFromSortedIndex")
|
2021-02-07 04:11:51 +00:00
|
|
|
fmt.Printf("offset: %d size: %d\n", offset.ToActualOffset(), size)
|
2020-06-25 23:36:06 +00:00
|
|
|
|
|
|
|
var shardEcdFileSize int64 = 1118830592 // 1024*1024*1024*3
|
2021-02-07 04:11:51 +00:00
|
|
|
intervals := LocateData(ErasureCodingLargeBlockSize, ErasureCodingSmallBlockSize, DataShardsCount*shardEcdFileSize, offset.ToActualOffset(), types.Size(needle.GetActualSize(size, needle.CurrentVersion)))
|
2020-06-25 23:36:06 +00:00
|
|
|
|
|
|
|
for _, interval := range intervals {
|
|
|
|
shardId, shardOffset := interval.ToShardIdAndOffset(ErasureCodingLargeBlockSize, ErasureCodingSmallBlockSize)
|
|
|
|
fmt.Printf("interval: %+v, shardId: %d, shardOffset: %d\n", interval, shardId, shardOffset)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|