diff --git a/storage.go b/storage.go index a304ed1..1f36b28 100644 --- a/storage.go +++ b/storage.go @@ -1531,7 +1531,7 @@ func (s *PersistentSlabStorage) getAllChildReferences(slab Slab) ( // BatchPreload decodeds and caches slabs of given ids in parallel. // This is useful for storage health or data validation in migration programs. -func (s *PersistentSlabStorage) BatchPreload(ids []SlabID, numWorkers int) error { +func (s *PersistentSlabStorage) BatchPreload(ids []StorageID, numWorkers int) error { if len(ids) == 0 { return nil } @@ -1566,12 +1566,12 @@ func (s *PersistentSlabStorage) BatchPreload(ids []SlabID, numWorkers int) error } type slabToBeDecoded struct { - slabID SlabID + slabID StorageID data []byte } type decodedSlab struct { - slabID SlabID + slabID StorageID slab Slab err error } @@ -1628,7 +1628,7 @@ func (s *PersistentSlabStorage) BatchPreload(ids []SlabID, numWorkers int) error // Preallocate cache map if empty if len(s.cache) == 0 { - s.cache = make(map[SlabID]Slab, len(ids)) + s.cache = make(map[StorageID]Slab, len(ids)) } // Launch workers diff --git a/storage_bench_test.go b/storage_bench_test.go index 0f0e895..adc3253 100644 --- a/storage_bench_test.go +++ b/storage_bench_test.go @@ -143,19 +143,19 @@ func benchmarkRetrieve(b *testing.B, seed int64, numberOfSlabs int) { decMode, err := cbor.DecOptions{}.DecMode() require.NoError(b, err) - encodedSlabs := make(map[SlabID][]byte) - ids := make([]SlabID, 0, numberOfSlabs) + encodedSlabs := make(map[StorageID][]byte) + ids := make([]StorageID, 0, numberOfSlabs) for i := 0; i < numberOfSlabs; i++ { addr := generateRandomAddress(r) - var index SlabIndex + var index StorageIndex binary.BigEndian.PutUint64(index[:], uint64(i)) - id := SlabID{addr, index} + id := StorageID{addr, index} slab := generateLargeSlab(id) - data, err := EncodeSlab(slab, encMode) + data, err := Encode(slab, encMode) require.NoError(b, err) encodedSlabs[id] = data @@ -190,19 +190,19 @@ func benchmarkBatchPreload(b *testing.B, seed int64, numberOfSlabs int) { decMode, err := cbor.DecOptions{}.DecMode() require.NoError(b, err) - encodedSlabs := make(map[SlabID][]byte) - ids := make([]SlabID, 0, numberOfSlabs) + encodedSlabs := make(map[StorageID][]byte) + ids := make([]StorageID, 0, numberOfSlabs) for i := 0; i < numberOfSlabs; i++ { addr := generateRandomAddress(r) - var index SlabIndex + var index StorageIndex binary.BigEndian.PutUint64(index[:], uint64(i)) - id := SlabID{addr, index} + id := StorageID{addr, index} slab := generateLargeSlab(id) - data, err := EncodeSlab(slab, encMode) + data, err := Encode(slab, encMode) require.NoError(b, err) encodedSlabs[id] = data diff --git a/storage_test.go b/storage_test.go index 4921667..672413b 100644 --- a/storage_test.go +++ b/storage_test.go @@ -4970,15 +4970,15 @@ func testStorageBatchPreload(t *testing.T, numberOfAccounts int, numberOfSlabsPe indexesByAddress := make(map[Address]uint64) - generateSlabID := func(address Address) SlabID { + generateSlabID := func(address Address) StorageID { nextIndex := indexesByAddress[address] + 1 - var idx SlabIndex + var idx StorageIndex binary.BigEndian.PutUint64(idx[:], nextIndex) indexesByAddress[address] = nextIndex - return NewSlabID(address, idx) + return NewStorageID(address, idx) } encMode, err := cbor.EncOptions{}.EncMode() @@ -4989,7 +4989,7 @@ func testStorageBatchPreload(t *testing.T, numberOfAccounts int, numberOfSlabsPe r := newRand(t) - encodedSlabs := make(map[SlabID][]byte) + encodedSlabs := make(map[StorageID][]byte) // Generate and encode slabs for i := 0; i < numberOfAccounts; i++ { @@ -5002,7 +5002,7 @@ func testStorageBatchPreload(t *testing.T, numberOfAccounts int, numberOfSlabsPe slab := generateRandomSlab(slabID, r) - encodedSlabs[slabID], err = EncodeSlab(slab, encMode) + encodedSlabs[slabID], err = Encode(slab, encMode) require.NoError(t, err) } } @@ -5010,7 +5010,7 @@ func testStorageBatchPreload(t *testing.T, numberOfAccounts int, numberOfSlabsPe baseStorage := NewInMemBaseStorageFromMap(encodedSlabs) storage := NewPersistentSlabStorage(baseStorage, encMode, decMode, decodeStorable, decodeTypeInfo) - ids := make([]SlabID, 0, len(encodedSlabs)) + ids := make([]StorageID, 0, len(encodedSlabs)) for id := range encodedSlabs { ids = append(ids, id) } @@ -5023,7 +5023,7 @@ func testStorageBatchPreload(t *testing.T, numberOfAccounts int, numberOfSlabsPe // Compare encoded data for id, data := range encodedSlabs { - cachedData, err := EncodeSlab(storage.cache[id], encMode) + cachedData, err := Encode(storage.cache[id], encMode) require.NoError(t, err) require.Equal(t, cachedData, data) @@ -5043,12 +5043,12 @@ func TestStorageBatchPreloadNotFoundSlabs(t *testing.T) { t.Run("empty storage", func(t *testing.T) { const numberOfSlabs = 10 - ids := make([]SlabID, numberOfSlabs) + ids := make([]StorageID, numberOfSlabs) for i := 0; i < numberOfSlabs; i++ { - var index SlabIndex + var index StorageIndex binary.BigEndian.PutUint64(index[:], uint64(i)) - ids[i] = NewSlabID(generateRandomAddress(r), index) + ids[i] = NewStorageID(generateRandomAddress(r), index) } baseStorage := NewInMemBaseStorage() @@ -5064,25 +5064,25 @@ func TestStorageBatchPreloadNotFoundSlabs(t *testing.T) { t.Run("non-empty storage", func(t *testing.T) { const numberOfSlabs = 10 - ids := make([]SlabID, numberOfSlabs) - encodedSlabs := make(map[SlabID][]byte) + ids := make([]StorageID, numberOfSlabs) + encodedSlabs := make(map[StorageID][]byte) for i := 0; i < numberOfSlabs; i++ { - var index SlabIndex + var index StorageIndex binary.BigEndian.PutUint64(index[:], uint64(i)) - id := NewSlabID(generateRandomAddress(r), index) + id := NewStorageID(generateRandomAddress(r), index) slab := generateRandomSlab(id, r) - encodedSlabs[id], err = EncodeSlab(slab, encMode) + encodedSlabs[id], err = Encode(slab, encMode) require.NoError(t, err) ids[i] = id } // Append a slab ID that doesn't exist in storage. - ids = append(ids, NewSlabID(generateRandomAddress(r), SlabIndex{numberOfSlabs})) + ids = append(ids, NewStorageID(generateRandomAddress(r), StorageIndex{numberOfSlabs})) baseStorage := NewInMemBaseStorageFromMap(encodedSlabs) storage := NewPersistentSlabStorage(baseStorage, encMode, decMode, decodeStorable, decodeTypeInfo) @@ -5095,7 +5095,7 @@ func TestStorageBatchPreloadNotFoundSlabs(t *testing.T) { // Compare encoded data for id, data := range encodedSlabs { - cachedData, err := EncodeSlab(storage.cache[id], encMode) + cachedData, err := Encode(storage.cache[id], encMode) require.NoError(t, err) require.Equal(t, cachedData, data)