Skip to content

Commit a418366

Browse files
authored
Merge pull request #7799 from onflow/leo/pebble-minor-refactors
[Storage] Minor refactor
2 parents f4ae905 + 869d8dc commit a418366

File tree

20 files changed

+62
-74
lines changed

20 files changed

+62
-74
lines changed

cmd/util/cmd/common/state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/onflow/flow-go/storage/store"
1313
)
1414

15-
func InitProtocolState(lockManager lockctx.Manager, db storage.DB, storages *store.All) (protocol.State, error) {
15+
func OpenProtocolState(lockManager lockctx.Manager, db storage.DB, storages *store.All) (protocol.State, error) {
1616
metrics := &metrics.NoopCollector{}
1717

1818
protocolState, err := protocolbadger.OpenState(
@@ -32,7 +32,7 @@ func InitProtocolState(lockManager lockctx.Manager, db storage.DB, storages *sto
3232
)
3333

3434
if err != nil {
35-
return nil, fmt.Errorf("could not init protocol state: %w", err)
35+
return nil, fmt.Errorf("could not open protocol state: %w", err)
3636
}
3737

3838
return protocolState, nil

cmd/util/cmd/execution-state-extract/execution_state_extract_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ func TestExtractExecutionState(t *testing.T) {
3737
metr := &metrics.NoopCollector{}
3838

3939
t.Run("missing block->state commitment mapping", func(t *testing.T) {
40-
4140
withDirs(t, func(datadir, execdir, outdir string) {
4241
// Initialize a proper Badger database instead of using empty directory
4342
db := unittest.PebbleDB(t, datadir)
@@ -96,7 +95,6 @@ func TestExtractExecutionState(t *testing.T) {
9695
lockManager := storage.NewTestingLockManager()
9796

9897
withDirs(t, func(datadir, execdir, _ string) {
99-
10098
const (
10199
checkpointDistance = math.MaxInt // A large number to prevent checkpoint creation.
102100
checkpointsToKeep = 1

cmd/util/cmd/export-json-transactions/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ func ExportTransactions(lockManager lockctx.Manager, dataDir string, outputDir s
7474
storages := common.InitStorages(db)
7575
defer db.Close()
7676

77-
state, err := common.InitProtocolState(lockManager, db, storages)
77+
state, err := common.OpenProtocolState(lockManager, db, storages)
7878
if err != nil {
79-
return fmt.Errorf("could not init protocol state: %w", err)
79+
return fmt.Errorf("could not open protocol state: %w", err)
8080
}
8181

8282
// create finder

cmd/util/cmd/find-inconsistent-result/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ func createStorages(dir string, lockManager lockctx.Manager) (
101101
}
102102

103103
storages := common.InitStorages(db)
104-
state, err := common.InitProtocolState(lockManager, db, storages)
104+
state, err := common.OpenProtocolState(lockManager, db, storages)
105105
if err != nil {
106-
return nil, nil, nil, nil, db, fmt.Errorf("could not init protocol state: %v", err)
106+
return nil, nil, nil, nil, db, fmt.Errorf("could not open protocol state: %v", err)
107107
}
108108

109109
return storages.Headers, storages.Results, storages.Seals, state, db, err

cmd/util/cmd/read-protocol-state/cmd/blocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func runE(*cobra.Command, []string) error {
152152
flagDBs := common.ReadDBFlags()
153153
return common.WithStorage(flagDBs, func(db storage.DB) error {
154154
storages := common.InitStorages(db)
155-
state, err := common.InitProtocolState(lockManager, db, storages)
155+
state, err := common.OpenProtocolState(lockManager, db, storages)
156156

157157
if err != nil {
158158
log.Fatal().Err(err).Msg("could not init protocol state")

cmd/util/cmd/read-protocol-state/cmd/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func runSnapshotE(*cobra.Command, []string) error {
5353
lockManager := storage.MakeSingletonLockManager()
5454
return common.WithStorage(common.ReadDBFlags(), func(db storage.DB) error {
5555
storages := common.InitStorages(db)
56-
state, err := common.InitProtocolState(lockManager, db, storages)
56+
state, err := common.OpenProtocolState(lockManager, db, storages)
5757
if err != nil {
5858
return fmt.Errorf("could not init protocol state")
5959
}

cmd/util/cmd/reindex/cmd/results.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ var resultsCmd = &cobra.Command{
2323
}
2424
defer db.Close()
2525
storages := common.InitStorages(db)
26-
state, err := common.InitProtocolState(lockManager, db, storages)
26+
state, err := common.OpenProtocolState(lockManager, db, storages)
2727
if err != nil {
28-
log.Fatal().Err(err).Msg("could not init protocol state")
28+
log.Fatal().Err(err).Msg("could not open protocol state")
2929
}
3030

3131
results := storages.Results

cmd/util/cmd/rollback-executed-height/cmd/rollback_executed_height.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func runE(*cobra.Command, []string) error {
6666
return err
6767
}
6868
storages := common.InitStorages(db)
69-
state, err := common.InitProtocolState(lockManager, db, storages)
69+
state, err := common.OpenProtocolState(lockManager, db, storages)
7070
if err != nil {
71-
return fmt.Errorf("could not init protocol states: %w", err)
71+
return fmt.Errorf("could not open protocol states: %w", err)
7272
}
7373

7474
metrics := &metrics.NoopCollector{}

cmd/util/cmd/snapshot/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ func run(*cobra.Command, []string) {
5353
defer db.Close()
5454

5555
storages := common.InitStorages(db)
56-
state, err := common.InitProtocolState(lockManager, db, storages)
56+
state, err := common.OpenProtocolState(lockManager, db, storages)
5757
if err != nil {
58-
log.Fatal().Err(err).Msg("could not init protocol state")
58+
log.Fatal().Err(err).Msg("could not open protocol state")
5959
}
6060

6161
log := log.With().Uint64("block_height", flagHeight).Logger()

engine/access/access_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ func (suite *Suite) TestGetExecutionResultByBlockID() {
636636
// TestGetSealedTransaction tests that transactions status of transaction that belongs to a sealed block
637637
// is reported as sealed
638638
func (suite *Suite) TestGetSealedTransaction() {
639-
lockManager := storage.NewTestingLockManager()
640639
unittest.RunWithBadgerDB(suite.T(), func(db *badger.DB) {
641640
all := bstorage.InitAll(metrics.NewNoopCollector(), db)
642641
en := util.ExecutionStorageLayer(suite.T(), db)
@@ -772,11 +771,11 @@ func (suite *Suite) TestGetSealedTransaction() {
772771
lctx.Release()
773772

774773
fctx := suite.lockManager.NewContext()
775-
defer fctx.Release()
776774
require.NoError(suite.T(), fctx.AcquireLock(storage.LockFinalizeBlock))
777775
require.NoError(suite.T(), bdb.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
778776
return operation.IndexFinalizedBlockByHeight(fctx, rw, block.Height, block.ID())
779777
}))
778+
fctx.Release()
780779

781780
suite.sealedBlock = block.ToHeader()
782781

@@ -798,7 +797,7 @@ func (suite *Suite) TestGetSealedTransaction() {
798797
suite.request.On("EntityByID", collection.ID(), mock.Anything).Return()
799798
// 4. Indexer IndexCollection receives the requested collection and all the execution receipts
800799
// Create a lock context for indexing
801-
indexLctx := lockManager.NewContext()
800+
indexLctx := suite.lockManager.NewContext()
802801
lockErr := indexLctx.AcquireLock(storage.LockInsertCollection)
803802
require.NoError(suite.T(), lockErr)
804803
defer indexLctx.Release()
@@ -1149,7 +1148,6 @@ func (suite *Suite) TestGetTransactionResult() {
11491148
// TestExecuteScript tests the three execute Script related calls to make sure that the execution api is called with
11501149
// the correct block id
11511150
func (suite *Suite) TestExecuteScript() {
1152-
lockManager := storage.NewTestingLockManager()
11531151
unittest.RunWithBadgerDB(suite.T(), func(badgerdb *badger.DB) {
11541152
db := badgerimpl.ToDB(badgerdb)
11551153
all := bstorage.InitAll(metrics.NewNoopCollector(), badgerdb)
@@ -1237,7 +1235,7 @@ func (suite *Suite) TestExecuteScript() {
12371235
all.Collections,
12381236
all.Transactions,
12391237
lastFullBlockHeight,
1240-
lockManager,
1238+
suite.lockManager,
12411239
)
12421240

12431241
ingestEng, err := ingestion.New(
@@ -1260,15 +1258,15 @@ func (suite *Suite) TestExecuteScript() {
12601258

12611259
// create a block and a seal pointing to that block
12621260
lastBlock := unittest.BlockWithParentFixture(prevBlock.ToHeader())
1263-
lctx := lockManager.NewContext()
1261+
lctx := suite.lockManager.NewContext()
12641262
require.NoError(suite.T(), lctx.AcquireLock(storage.LockInsertBlock))
12651263
require.NoError(suite.T(), db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
12661264
return all.Blocks.BatchStore(lctx, rw, unittest.ProposalFromBlock(lastBlock))
12671265
}))
12681266
lctx.Release()
12691267
require.NoError(suite.T(), err)
12701268

1271-
fctx := lockManager.NewContext()
1269+
fctx := suite.lockManager.NewContext()
12721270
require.NoError(suite.T(), fctx.AcquireLock(storage.LockFinalizeBlock))
12731271
require.NoError(suite.T(), db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
12741272
return operation.IndexFinalizedBlockByHeight(fctx, rw, lastBlock.Height, lastBlock.ID())
@@ -1285,7 +1283,7 @@ func (suite *Suite) TestExecuteScript() {
12851283
require.NoError(suite.T(), err)
12861284
}
12871285

1288-
fctx2 := lockManager.NewContext()
1286+
fctx2 := suite.lockManager.NewContext()
12891287
require.NoError(suite.T(), fctx2.AcquireLock(storage.LockInsertBlock))
12901288
require.NoError(suite.T(), fctx2.AcquireLock(storage.LockFinalizeBlock))
12911289
require.NoError(suite.T(), db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {

0 commit comments

Comments
 (0)