Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Access] Pebble checkpoint ingestion #4727

Merged
merged 38 commits into from
Sep 29, 2023

Conversation

koko1123
Copy link
Contributor

@koko1123 koko1123 commented Sep 19, 2023

closes #4637

Base automatically changed from amlandeep/implement-reamining-pebble-functions to master September 21, 2023 21:07
@codecov-commenter
Copy link

codecov-commenter commented Sep 25, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (8104663) 55.76% compared to head (94db5b2) 50.90%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4727      +/-   ##
==========================================
- Coverage   55.76%   50.90%   -4.87%     
==========================================
  Files         938      544     -394     
  Lines       86773    52298   -34475     
==========================================
- Hits        48391    26623   -21768     
+ Misses      34743    23757   -10986     
+ Partials     3639     1918    -1721     
Flag Coverage Δ
unittests 50.90% <ø> (-4.87%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 396 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
@@ -128,3 +130,17 @@ func encodedUint64(height uint64) []byte {
payload := make([]byte, 0, 8)
return binary.BigEndian.AppendUint64(payload, height)
}

// KeyToRegisterID converts a ledger key into a register ID.
func keyToRegisterID(key ledger.Key) (flow.RegisterID, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janezpodhostnik should this function live here?

We are planning to move all these conversion function somewhere, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reuse the LedgerKeyToRegisterID from this PR https://github.com/onflow/flow-go/pull/4766/files

}

// IndexCheckpointFile indexes the checkpoint file in the Dir provided as a component
func (b *Bootstrap) IndexCheckpointFile(ctx irrecoverable.SignalerContext, ready component.ReadyFunc) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add some log that we are about to index checkpoint from directory with root height.

storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
}

// IndexCheckpointFile indexes the checkpoint file in the Dir provided as a component
func (b *Bootstrap) IndexCheckpointFile() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to add some logging in this function to log, the root height, and important steps are done, etc

storage/pebble/bootstrap.go Show resolved Hide resolved
storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
storage/pebble/bootstrap.go Outdated Show resolved Hide resolved
// check for pre-populated heights, fail if it is populated
// i.e. the IndexCheckpointFile function has already run for the db in this directory
checkpointDir, checkpointFileName := filepath.Split(checkpointFile)
_, _, err := db.Get(latestHeightKey())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koko1123 koko1123 enabled auto-merge September 29, 2023 13:25
) (*RegisterBootstrap, error) {
// check for pre-populated heights, fail if it is populated
// i.e. the IndexCheckpointFile function has already run for the db in this directory
isBootstrapped, err := IsBootstrapped(db)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

}
if isBootstrapped {
// key detected, attempt to run bootstrap on corrupt or already bootstrapped data
return nil, fmt.Errorf("found latest key set on badger instance, DB is already bootstrapped")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an error type above in this file:

ErrAlreadyBootstrapped := errors.New("storage is already bootstrapped and populated with data")

And then return this error and in tests better to assert:

assert.ErrorIs(t, err, ErrAlreadyBootstrapped)

require.NoError(t, initHeights(p, rootHeight))
// errors if FirstHeight or LastHeight are populated
_, err = NewRegisterBootstrap(p, dir, rootHeight, log)
require.ErrorContains(t, err, "DB is already bootstrapped")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koko1123 koko1123 added this pull request to the merge queue Sep 29, 2023
fileToDelete := path.Join(dir, fmt.Sprintf("%v.%03d", checkpointFileName, 2))
err := os.RemoveAll(fileToDelete)
require.NoError(t, err)
pb, _ := createPebbleForTest(t)
Copy link
Contributor

@peterargue peterargue Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to cleanup the dir (otherwise they collect on people's laptops after running tests)

dbDir := unittest.TempPebblePath(t)
pb, err := OpenRegisterPebbleDB(dbDir)
require.NoError(t, err)
return pb, dbDir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: consider consolidating all of the calls to close the db and cleanup the dir here.

Suggested change
return pb, dbDir
t.Cleanup(func() {
require.NoError(t, pb.Close())
require.NoError(t, os.RemoveAll(dbDir))
}
return pb, dbDir

@koko1123 koko1123 removed this pull request from the merge queue due to a manual request Sep 29, 2023
@koko1123 koko1123 enabled auto-merge September 29, 2023 15:56
@koko1123 koko1123 added this pull request to the merge queue Sep 29, 2023
Merged via the queue into master with commit 603e204 Sep 29, 2023
36 checks passed
@koko1123 koko1123 deleted the amlandeep/pebble-checkpoint-ingestion branch September 29, 2023 17:44
@zhangchiqing zhangchiqing mentioned this pull request Oct 27, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script Execution on Access Node
5 participants