Skip to content

Commit 22daffd

Browse files
committed
address review comments
1 parent cde5e81 commit 22daffd

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

Diff for: storage/pebble/chunk_data_packs.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"fmt"
55

66
"github.com/cockroachdb/pebble"
7+
"github.com/rs/zerolog/log"
78

89
"github.com/onflow/flow-go/model/flow"
910
"github.com/onflow/flow-go/module"
1011
"github.com/onflow/flow-go/module/metrics"
1112
"github.com/onflow/flow-go/storage"
12-
"github.com/onflow/flow-go/storage/pebble/operations"
13+
"github.com/onflow/flow-go/storage/pebble/operation"
1314
)
1415

1516
type ChunkDataPacks struct {
@@ -25,7 +26,7 @@ func NewChunkDataPacks(collector module.CacheMetrics, db *pebble.DB, collections
2526
retrieve := func(key flow.Identifier) func(pebble.Reader) (*storage.StoredChunkDataPack, error) {
2627
return func(r pebble.Reader) (*storage.StoredChunkDataPack, error) {
2728
var c storage.StoredChunkDataPack
28-
err := operations.RetrieveChunkDataPack(key, &c)(r)
29+
err := operation.RetrieveChunkDataPack(key, &c)(r)
2930
return &c, err
3031
}
3132
}
@@ -46,7 +47,12 @@ func NewChunkDataPacks(collector module.CacheMetrics, db *pebble.DB, collections
4647
// Any error are exceptions
4748
func (ch *ChunkDataPacks) Store(cs []*flow.ChunkDataPack) error {
4849
batch := NewBatch(ch.db)
49-
defer batch.Close()
50+
defer func() {
51+
err := batch.Close()
52+
if err != nil {
53+
log.Error().Err(err).Msgf("failed to close batch when storing chunk data pack")
54+
}
55+
}()
5056

5157
for _, c := range cs {
5258
err := ch.batchStore(c, batch)
@@ -92,7 +98,7 @@ func (ch *ChunkDataPacks) Remove(cs []flow.Identifier) error {
9298
// other errors are exceptions
9399
func (ch *ChunkDataPacks) ByChunkID(chunkID flow.Identifier) (*flow.ChunkDataPack, error) {
94100
var sc storage.StoredChunkDataPack
95-
err := operations.RetrieveChunkDataPack(chunkID, &sc)(ch.db)
101+
err := operation.RetrieveChunkDataPack(chunkID, &sc)(ch.db)
96102
if err != nil {
97103
return nil, fmt.Errorf("could not retrieve stored chunk data pack: %w", err)
98104
}
@@ -121,7 +127,7 @@ func (ch *ChunkDataPacks) BatchRemove(chunkID flow.Identifier, batch storage.Bat
121127
}
122128

123129
func (ch *ChunkDataPacks) batchRemove(chunkID flow.Identifier, batch pebble.Writer) error {
124-
return operations.RemoveChunkDataPack(chunkID)(batch)
130+
return operation.RemoveChunkDataPack(chunkID)(batch)
125131
}
126132

127133
func (ch *ChunkDataPacks) batchStore(c *flow.ChunkDataPack, batch *Batch) error {
@@ -130,7 +136,7 @@ func (ch *ChunkDataPacks) batchStore(c *flow.ChunkDataPack, batch *Batch) error
130136
batch.OnSucceed(func() {
131137
ch.byChunkIDCache.Insert(sc.ChunkID, sc)
132138
})
133-
err := operations.InsertChunkDataPack(sc)(writer)
139+
err := operation.InsertChunkDataPack(sc)(writer)
134140
if err != nil {
135141
return fmt.Errorf("failed to store chunk data pack: %w", err)
136142
}

Diff for: storage/pebble/operations/chunk_data_pack.go renamed to storage/pebble/operation/chunk_data_pack.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package operations
1+
package operation
22

33
import (
44
"github.com/cockroachdb/pebble"
@@ -29,3 +29,7 @@ func RemoveChunkDataPack(chunkID flow.Identifier) func(w pebble.Writer) error {
2929
return w.Delete(key, nil)
3030
}
3131
}
32+
33+
func makeKey(prefix byte, identifier flow.Identifier) []byte {
34+
return append([]byte{prefix}, identifier[:]...)
35+
}

Diff for: storage/pebble/operations/codes.go renamed to storage/pebble/operation/codes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package operations
1+
package operation
22

33
const (
44
codeChunkDataPack = 100

Diff for: storage/pebble/operations/common.go renamed to storage/pebble/operation/common.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package operations
1+
package operation
22

33
import (
44
"errors"
55

66
"github.com/cockroachdb/pebble"
77
"github.com/vmihailenco/msgpack"
88

9-
"github.com/onflow/flow-go/model/flow"
109
"github.com/onflow/flow-go/module/irrecoverable"
1110
"github.com/onflow/flow-go/storage"
1211
)
@@ -43,10 +42,6 @@ func retrieve(key []byte, sc interface{}) func(r pebble.Reader) error {
4342
}
4443
}
4544

46-
func makeKey(prefix byte, identifier flow.Identifier) []byte {
47-
return append([]byte{prefix}, identifier[:]...)
48-
}
49-
5045
func convertNotFoundError(err error) error {
5146
if errors.Is(err, pebble.ErrNotFound) {
5247
return storage.ErrNotFound

0 commit comments

Comments
 (0)