You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB

5 years ago
  1. package erasure_coding
  2. import (
  3. "fmt"
  4. "os"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  8. "github.com/seaweedfs/seaweedfs/weed/storage/types"
  9. )
  10. func TestPositioning(t *testing.T) {
  11. ecxFile, err := os.OpenFile("389.ecx", os.O_RDONLY, 0)
  12. if err != nil {
  13. t.Errorf("failed to open ecx file: %v", err)
  14. }
  15. defer ecxFile.Close()
  16. stat, _ := ecxFile.Stat()
  17. fileSize := stat.Size()
  18. tests := []struct {
  19. needleId string
  20. offset int64
  21. size int
  22. }{
  23. {needleId: "0f0edb92", offset: 31300679656, size: 1167},
  24. {needleId: "0ef7d7f8", offset: 11513014944, size: 66044},
  25. }
  26. for _, test := range tests {
  27. needleId, _ := types.ParseNeedleId(test.needleId)
  28. offset, size, err := SearchNeedleFromSortedIndex(ecxFile, fileSize, needleId, nil)
  29. assert.Equal(t, nil, err, "SearchNeedleFromSortedIndex")
  30. fmt.Printf("offset: %d size: %d\n", offset.ToActualOffset(), size)
  31. }
  32. needleId, _ := types.ParseNeedleId("0f087622")
  33. offset, size, err := SearchNeedleFromSortedIndex(ecxFile, fileSize, needleId, nil)
  34. assert.Equal(t, nil, err, "SearchNeedleFromSortedIndex")
  35. fmt.Printf("offset: %d size: %d\n", offset.ToActualOffset(), size)
  36. var shardEcdFileSize int64 = 1118830592 // 1024*1024*1024*3
  37. intervals := LocateData(ErasureCodingLargeBlockSize, ErasureCodingSmallBlockSize, DataShardsCount*shardEcdFileSize, offset.ToActualOffset(), types.Size(needle.GetActualSize(size, needle.CurrentVersion)))
  38. for _, interval := range intervals {
  39. shardId, shardOffset := interval.ToShardIdAndOffset(ErasureCodingLargeBlockSize, ErasureCodingSmallBlockSize)
  40. fmt.Printf("interval: %+v, shardId: %d, shardOffset: %d\n", interval, shardId, shardOffset)
  41. }
  42. }