Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload Refactor #606

Merged
merged 13 commits into from
Sep 21, 2023
107 changes: 76 additions & 31 deletions internal/testing/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1932,24 +1932,38 @@ func TestUploadPacking(t *testing.T) {
uploadDownload("file5", data5)
download("file4", data4, 0, int64(len(data4)))

// check the object stats
// assert number of objects
os, err := b.ObjectsStats()
if err != nil {
t.Fatal(err)
}
if os.NumObjects != 5 {
t.Fatal("expected 5 objects, got", os.NumObjects)
t.Fatalf("expected 5 objects, got %v", os.NumObjects)
}
totalObjectSize := uint64(3 * slabSize)
totalRedundantSize := totalObjectSize * uint64(rs.TotalShards) / uint64(rs.MinShards)
if os.TotalObjectsSize != totalObjectSize {
t.Fatalf("expected totalObjectSize of %v, got %v", totalObjectSize, os.TotalObjectsSize)
}
if os.TotalSectorsSize != uint64(totalRedundantSize) {
t.Errorf("expected totalSectorSize of %v, got %v", totalRedundantSize, os.TotalSectorsSize)
}
if os.TotalUploadedSize != uint64(totalRedundantSize) {
t.Errorf("expected totalUploadedSize of %v, got %v", totalRedundantSize, os.TotalUploadedSize)

// check the object size stats, we use a retry loop since packed slabs are
// uploaded in a separate goroutine, so the object stats might lag a bit
err = Retry(60, time.Second, func() error {
os, err := b.ObjectsStats()
if err != nil {
t.Fatal(err)
}

totalObjectSize := uint64(3 * slabSize)
totalRedundantSize := totalObjectSize * uint64(rs.TotalShards) / uint64(rs.MinShards)
if os.TotalObjectsSize != totalObjectSize {
return fmt.Errorf("expected totalObjectSize of %v, got %v", totalObjectSize, os.TotalObjectsSize)
}
if os.TotalSectorsSize != uint64(totalRedundantSize) {
return fmt.Errorf("expected totalSectorSize of %v, got %v", totalRedundantSize, os.TotalSectorsSize)
}
if os.TotalUploadedSize != uint64(totalRedundantSize) {
return fmt.Errorf("expected totalUploadedSize of %v, got %v", totalRedundantSize, os.TotalUploadedSize)
}
return nil
})
if err != nil {
t.Fatal(err)
}

// ObjectsBySlabKey should return 2 objects for the slab of file1 since file1
Expand Down Expand Up @@ -2126,23 +2140,38 @@ func TestSlabBufferStats(t *testing.T) {
t.Fatal(err)
}

// check the object stats
// assert number of objects
os, err := b.ObjectsStats()
if err != nil {
t.Fatal(err)
}
if os.NumObjects != 1 {
t.Fatal("expected 1 object, got", os.NumObjects)
}
if os.TotalObjectsSize != uint64(len(data1)) {
t.Fatalf("expected totalObjectSize of %v, got %v", len(data1), os.TotalObjectsSize)
}
if os.TotalSectorsSize != 0 {
t.Fatal("expected totalSectorSize of 0, got", os.TotalSectorsSize)
t.Fatalf("expected 1 object, got %d", os.NumObjects)
}
if os.TotalUploadedSize != 0 {
t.Fatal("expected totalUploadedSize of 0, got", os.TotalUploadedSize)

// check the object size stats, we use a retry loop since packed slabs are
// uploaded in a separate goroutine, so the object stats might lag a bit
err = Retry(60, time.Second, func() error {
os, err := b.ObjectsStats()
if err != nil {
t.Fatal(err)
}
if os.TotalObjectsSize != uint64(len(data1)) {
return fmt.Errorf("expected totalObjectSize of %d, got %d", len(data1), os.TotalObjectsSize)
}
if os.TotalSectorsSize != 0 {
return fmt.Errorf("expected totalSectorSize of 0, got %d", os.TotalSectorsSize)
}
if os.TotalUploadedSize != 0 {
return fmt.Errorf("expected totalUploadedSize of 0, got %d", os.TotalUploadedSize)
}
return nil
})
if err != nil {
t.Fatal(err)
}

// check the slab buffers
buffers, err := b.SlabBuffers()
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -2174,22 +2203,38 @@ func TestSlabBufferStats(t *testing.T) {
t.Fatal(err)
}

// assert number of objects
os, err = b.ObjectsStats()
if err != nil {
t.Fatal(err)
}
if os.NumObjects != 2 {
t.Fatal("expected 1 object, got", os.NumObjects)
}
if os.TotalObjectsSize != uint64(len(data1)+len(data2)) {
t.Fatalf("expected totalObjectSize of %v, got %v", len(data1)+len(data2), os.TotalObjectsSize)
}
if os.TotalSectorsSize != 3*rhpv2.SectorSize {
t.Fatalf("expected totalSectorSize of %v, got %v", 3*rhpv2.SectorSize, os.TotalSectorsSize)
t.Fatalf("expected 1 object, got %d", os.NumObjects)
}
if os.TotalUploadedSize != 3*rhpv2.SectorSize {
t.Fatalf("expected totalUploadedSize of %v, got %v", 3*rhpv2.SectorSize, os.TotalUploadedSize)

// check the object size stats, we use a retry loop since packed slabs are
// uploaded in a separate goroutine, so the object stats might lag a bit
err = Retry(60, time.Second, func() error {
peterjan marked this conversation as resolved.
Show resolved Hide resolved
os, err := b.ObjectsStats()
if err != nil {
t.Fatal(err)
}
if os.TotalObjectsSize != uint64(len(data1)+len(data2)) {
return fmt.Errorf("expected totalObjectSize of %d, got %d", len(data1)+len(data2), os.TotalObjectsSize)
}
if os.TotalSectorsSize != 3*rhpv2.SectorSize {
return fmt.Errorf("expected totalSectorSize of %d, got %d", 3*rhpv2.SectorSize, os.TotalSectorsSize)
}
if os.TotalUploadedSize != 3*rhpv2.SectorSize {
return fmt.Errorf("expected totalUploadedSize of %d, got %d", 3*rhpv2.SectorSize, os.TotalUploadedSize)
}
return nil
})
if err != nil {
t.Fatal(err)
}

// check the slab buffers
buffers, err = b.SlabBuffers()
if err != nil {
t.Fatal(err)
Expand Down
3 changes: 1 addition & 2 deletions object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/cipher"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -52,7 +51,7 @@ func (k *EncryptionKey) UnmarshalText(b []byte) error {
// given offset.
func (k EncryptionKey) Encrypt(r io.Reader, offset uint64) (cipher.StreamReader, error) {
if offset%64 != 0 {
return cipher.StreamReader{}, errors.New("offset must be a multiple of 64")
return cipher.StreamReader{}, fmt.Errorf("offset must be a multiple of 64, got %v", offset)
}
if k.IsNoopKey() {
return cipher.StreamReader{S: &noOpStream{}, R: r}, nil
Expand Down
Loading