Skip to content

Commit

Permalink
Merge pull request #291 from onflow/supun/revert-287
Browse files Browse the repository at this point in the history
Revert adding a callback to the Encoder
  • Loading branch information
fxamacker authored Mar 3, 2023
2 parents 82ce4cc + f2d7eb9 commit c836704
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 243 deletions.
2 changes: 1 addition & 1 deletion array_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func setupArray(b *testing.B, r *rand.Rand, storage *PersistentSlabStorage, init
require.NoError(b, err)
}

err = storage.Commit(nil)
err = storage.Commit()
require.NoError(b, err)

arrayID := array.StorageID()
Expand Down
14 changes: 7 additions & 7 deletions array_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
err = array.Append(v)
require.NoError(b, err)
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
b.ResetTimer()

arrayID := array.StorageID()
Expand All @@ -118,7 +118,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
err = array.Append(v)
require.NoError(b, err)
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
totalAppendTime = time.Since(start)

// remove
Expand All @@ -134,7 +134,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
require.NoError(b, err)
totalRawDataSize -= storable.ByteSize()
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
totalRemoveTime = time.Since(start)

// insert
Expand All @@ -156,7 +156,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
err = array.Insert(uint64(ind), v)
require.NoError(b, err)
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
totalInsertTime = time.Since(start)

// lookup
Expand All @@ -171,7 +171,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
_, err := array.Get(uint64(ind))
require.NoError(b, err)
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
totalLookupTime = time.Since(start)

// random lookup
Expand Down Expand Up @@ -229,7 +229,7 @@ func benchmarkLongTermImpactOnMemory(b *testing.B, initialArraySize, numberOfOps
err = array.Append(v)
require.NoError(b, err)
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
b.ResetTimer()

for i := 0; i < numberOfOps; i++ {
Expand All @@ -252,7 +252,7 @@ func benchmarkLongTermImpactOnMemory(b *testing.B, initialArraySize, numberOfOps
require.NoError(b, err)
}
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())

storageOverheadRatio := float64(storage.baseStorage.Size()) / float64(totalRawDataSize)
b.ReportMetric(float64(storage.baseStorage.SegmentsTouched()), "segments_touched")
Expand Down
4 changes: 2 additions & 2 deletions array_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func validArraySlabSerialization(
}

// Encode slab
data, err := EncodeSlab(slab, cborEncMode, nil)
data, err := Encode(slab, cborEncMode)
if err != nil {
return err
}
Expand All @@ -421,7 +421,7 @@ func validArraySlabSerialization(
}

// Re-encode decoded slab
dataFromDecodedSlab, err := EncodeSlab(decodedSlab, cborEncMode, nil)
dataFromDecodedSlab, err := Encode(decodedSlab, cborEncMode)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func verifyArray(

if !hasNestedArrayMapElement {
// Need to call Commit before calling storage.Count() for PersistentSlabStorage.
err = storage.Commit(nil)
err = storage.Commit()
require.NoError(t, err)

stats, err := GetArrayStats(array)
Expand Down Expand Up @@ -1506,7 +1506,7 @@ func TestArrayEncodeDecode(t *testing.T) {
0x99, 0x00, 0x00,
}

slabData, err := storage.Encode(nil)
slabData, err := storage.Encode()
require.NoError(t, err)
require.Equal(t, 1, len(slabData))
require.Equal(t, expectedData, slabData[array.StorageID()])
Expand Down Expand Up @@ -1555,7 +1555,7 @@ func TestArrayEncodeDecode(t *testing.T) {
0xd8, 0xa4, 0x00,
}

slabData, err := storage.Encode(nil)
slabData, err := storage.Encode()
require.NoError(t, err)
require.Equal(t, 1, len(slabData))
require.Equal(t, expectedData, slabData[array.StorageID()])
Expand Down Expand Up @@ -1708,7 +1708,7 @@ func TestArrayEncodeDecode(t *testing.T) {
},
}

m, err := storage.Encode(nil)
m, err := storage.Encode()
require.NoError(t, err)
require.Equal(t, len(expected), len(m))
require.Equal(t, expected[id1], m[id1])
Expand Down
4 changes: 2 additions & 2 deletions basicarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (a *BasicArrayDataSlab) Encode(enc *Encoder) error {
return NewEncodingError(err)
}

for _, e := range a.elements {
err := e.Encode(enc)
for i := 0; i < len(a.elements); i++ {
err := a.elements[i].Encode(enc)
if err != nil {
return NewEncodingError(err)
}
Expand Down
10 changes: 5 additions & 5 deletions basicarray_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func benchmarkBasicArray(b *testing.B, initialArraySize, numberOfElements int) {
err = array.Append(v)
require.NoError(b, err)
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
b.ResetTimer()

arrayID := array.StorageID()
Expand All @@ -104,7 +104,7 @@ func benchmarkBasicArray(b *testing.B, initialArraySize, numberOfElements int) {
err = array.Append(v)
require.NoError(b, err)
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
totalAppendTime = time.Since(start)

// remove
Expand All @@ -121,7 +121,7 @@ func benchmarkBasicArray(b *testing.B, initialArraySize, numberOfElements int) {
require.NoError(b, err)
totalRawDataSize -= storable.ByteSize()
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
totalRemoveTime = time.Since(start)

// insert
Expand All @@ -139,7 +139,7 @@ func benchmarkBasicArray(b *testing.B, initialArraySize, numberOfElements int) {
err = array.Insert(uint64(ind), v)
require.NoError(b, err)
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
totalInsertTime = time.Since(start)

// lookup
Expand All @@ -153,7 +153,7 @@ func benchmarkBasicArray(b *testing.B, initialArraySize, numberOfElements int) {
_, err := array.Get(uint64(ind))
require.NoError(b, err)
}
require.NoError(b, storage.Commit(nil))
require.NoError(b, storage.Commit())
totalLookupTime = time.Since(start)

// random lookup
Expand Down
2 changes: 1 addition & 1 deletion basicarray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func TestBasicArrayDecodeEncodeRandomData(t *testing.T) {
rootID := array.root.Header().id

// Encode slabs with random data of mixed types
m1, err := storage.Encode(nil)
m1, err := storage.Encode()
require.NoError(t, err)

// Decode data to new storage
Expand Down
173 changes: 0 additions & 173 deletions callback_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/stress/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func testArray(
reduceHeapAllocs = false

// Commit slabs to storage and drop read and write to reduce mem
err = storage.FastCommit(runtime.NumCPU(), nil)
err = storage.FastCommit(runtime.NumCPU())
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to commit to storage: %s", err)
return
Expand Down
2 changes: 1 addition & 1 deletion cmd/stress/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func testMap(
reduceHeapAllocs = false

// Commit slabs to storage and drop read and write to reduce mem
err = storage.FastCommit(runtime.NumCPU(), nil)
err = storage.FastCommit(runtime.NumCPU())
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to commit to storage: %s", err)
return
Expand Down
6 changes: 0 additions & 6 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ type Encoder struct {
Scratch [64]byte
}

// Callback is a wrapper with callback functions to be called during encoding.
// Implementations of this interface must be concurrency-safe.
type Callback interface {
BeforeEncodeSlab(size uint32) error
}

func NewEncoder(w io.Writer, encMode cbor.EncMode) *Encoder {
streamEncoder := encMode.NewStreamEncoder(w)
return &Encoder{
Expand Down
Loading

0 comments on commit c836704

Please sign in to comment.