@@ -4,12 +4,13 @@ import (
4
4
"fmt"
5
5
6
6
"github.com/cockroachdb/pebble"
7
+ "github.com/rs/zerolog/log"
7
8
8
9
"github.com/onflow/flow-go/model/flow"
9
10
"github.com/onflow/flow-go/module"
10
11
"github.com/onflow/flow-go/module/metrics"
11
12
"github.com/onflow/flow-go/storage"
12
- "github.com/onflow/flow-go/storage/pebble/operations "
13
+ "github.com/onflow/flow-go/storage/pebble/operation "
13
14
)
14
15
15
16
type ChunkDataPacks struct {
@@ -25,7 +26,7 @@ func NewChunkDataPacks(collector module.CacheMetrics, db *pebble.DB, collections
25
26
retrieve := func (key flow.Identifier ) func (pebble.Reader ) (* storage.StoredChunkDataPack , error ) {
26
27
return func (r pebble.Reader ) (* storage.StoredChunkDataPack , error ) {
27
28
var c storage.StoredChunkDataPack
28
- err := operations .RetrieveChunkDataPack (key , & c )(r )
29
+ err := operation .RetrieveChunkDataPack (key , & c )(r )
29
30
return & c , err
30
31
}
31
32
}
@@ -46,7 +47,12 @@ func NewChunkDataPacks(collector module.CacheMetrics, db *pebble.DB, collections
46
47
// Any error are exceptions
47
48
func (ch * ChunkDataPacks ) Store (cs []* flow.ChunkDataPack ) error {
48
49
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
+ }()
50
56
51
57
for _ , c := range cs {
52
58
err := ch .batchStore (c , batch )
@@ -92,7 +98,7 @@ func (ch *ChunkDataPacks) Remove(cs []flow.Identifier) error {
92
98
// other errors are exceptions
93
99
func (ch * ChunkDataPacks ) ByChunkID (chunkID flow.Identifier ) (* flow.ChunkDataPack , error ) {
94
100
var sc storage.StoredChunkDataPack
95
- err := operations .RetrieveChunkDataPack (chunkID , & sc )(ch .db )
101
+ err := operation .RetrieveChunkDataPack (chunkID , & sc )(ch .db )
96
102
if err != nil {
97
103
return nil , fmt .Errorf ("could not retrieve stored chunk data pack: %w" , err )
98
104
}
@@ -121,7 +127,7 @@ func (ch *ChunkDataPacks) BatchRemove(chunkID flow.Identifier, batch storage.Bat
121
127
}
122
128
123
129
func (ch * ChunkDataPacks ) batchRemove (chunkID flow.Identifier , batch pebble.Writer ) error {
124
- return operations .RemoveChunkDataPack (chunkID )(batch )
130
+ return operation .RemoveChunkDataPack (chunkID )(batch )
125
131
}
126
132
127
133
func (ch * ChunkDataPacks ) batchStore (c * flow.ChunkDataPack , batch * Batch ) error {
@@ -130,7 +136,7 @@ func (ch *ChunkDataPacks) batchStore(c *flow.ChunkDataPack, batch *Batch) error
130
136
batch .OnSucceed (func () {
131
137
ch .byChunkIDCache .Insert (sc .ChunkID , sc )
132
138
})
133
- err := operations .InsertChunkDataPack (sc )(writer )
139
+ err := operation .InsertChunkDataPack (sc )(writer )
134
140
if err != nil {
135
141
return fmt .Errorf ("failed to store chunk data pack: %w" , err )
136
142
}
0 commit comments