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

Enable pvtdata store to receive pvtdata hashes during bootstrap #1927

Merged

Conversation

manish-sethi
Copy link
Contributor

Signed-off-by: manish manish.sethi@gmail.com

Type of change

  • New feature

Description

As a follow up PR to #1908, this PR

  • Registers the snapshot data importer from pvtdatastore for receiving the pvtdata hashes while loading the hashes from snapshot files into the statedb
  • Persists basic information about the booting snapshot in the pvtdata store
  • Adds UTs relating to query and deletion of the boot KV hashes upon commit of missing data or expiry of the data

Additional details

In a follow up PR, the changes in the reconciliation will be made to pull the bootKV hashes from the pvtdata store instead of from the blockstore for the data below snapshot height

Related issues

FAB-18033

@manish-sethi manish-sethi requested a review from a team as a code owner September 25, 2020 04:13
@manish-sethi manish-sethi force-pushed the populate_pvtdata_store_2_with_UTs branch from 1908900 to e0de473 Compare September 25, 2020 04:27
Signed-off-by: manish <manish.sethi@gmail.com>
@manish-sethi manish-sethi force-pushed the populate_pvtdata_store_2_with_UTs branch from e0de473 to 364ba89 Compare September 25, 2020 04:41
Copy link
Contributor

@cendhu cendhu left a comment

Choose a reason for hiding this comment

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

Thanks, Manish. There are a few nits which can be addressed in the already planned follow up PRs if you agree to my points.

},
)
purgeMgrBuilder := pvtstatepurgemgmt.NewPurgeMgrBuilder(ledgerID, btlPolicy, p.bookkeepingProvider)

if err = p.dbProvider.ImportFromSnapshot(ledgerID, savepoint, snapshotDir, purgeMgrBuilder); err != nil {
snapshotDataImporter, err := p.pvtdataStoreProvider.SnapshotDataImporterFor(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. Similar to line 284, we could have a NewPvtDataMissingInfoBuilder() here to be explicit about what is being stored in the pvtdatastore during the import phase.

membershipProvider ledger.MembershipInfoProvider,
configHistoryRetriever *confighistory.Retriever,
) (*SnapshotDataImporter, error) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. Linter does not seem to like this empty line.

db := p.dbProvider.GetDBHandle(ledgerID)
batch := db.NewUpdateBatch()
batch.Put(lastBlockInBootSnapshotKey, encodeLastBlockInBootSnapshotVal(lastBlockInSnapshot))
batch.Put(lastCommittedBlkkey, encodeLastCommittedBlockVal(lastBlockInSnapshot))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. lastCommittedBlkKey

Comment on lines +572 to +574
if encVal == nil || err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. We are missing a bit of clarity for saving a few lines of code.

// FetchBootKVHashes returns the KVHashes from the data that was loaded from a snapshot at the time of
// bootstrapping. This funciton returns an error if the supplied blkNum is greater than the last block
// number in the booting snapshot
func (s *Store) FetchBootKVHashes(blkNum, txNum uint64, ns, coll string) (map[string][]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, this function is not used in the production code. As it is an exported method, is the goal to make kvledger use this method to check on the reconciled data to identify matching/mismatching hashes?

require.EqualError(t, err, "unexpected call. Boot KV Hashes are persisted only for the data imported from snapshot")
})

t.Run("committing-old-blocks-pvtdata-deletes-bootKV-hashes", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I expected this test to be present in the reconciler_xxx_test.go. In general, the test for xxx.go is expected to be found in xxx_test.go. Even certain IDE plugins assume that and there are shortcuts to open an alternative file (test or production code). Breaking this tradition is going to introduce some difficult in the future for sure where we need to search for a particular test as it cannot be found in an alternative file. Hence, I would prefer the test to be present in the alternative file. I leave this to you to decide.

)
}

if err = p.dbProvider.ImportFromSnapshot(ledgerID, savepoint, snapshotDir, purgeMgrBuilder, snapshotDataImporter); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we will add a ledger level integration test at kvledger/tests to ensure that the hashes are being stored on the pvtdata store.

)
})

t.Run("purger-deletes-expired-bootKV-hashes", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Existing test for purger is present in TestStorePurge() (in the alternative file store_test.go) which takes care of deleting eligible, ineligible, and depriritized missing data along with the expiry entry. IMO, it would be good to have all purge related testing in a single place so that we would know where to look for a particular test.

@cendhu cendhu merged commit a11fa5f into hyperledger:master Sep 26, 2020
@manish-sethi
Copy link
Contributor Author

Thanks @cendhu - I'll fix some of these nits in the final PR on this topic.

@manish-sethi manish-sethi deleted the populate_pvtdata_store_2_with_UTs branch November 4, 2020 03:44
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.

2 participants