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

NewSnapshotReader Nil Error #2586

Merged
merged 1 commit into from
May 14, 2021

Conversation

jcastrence
Copy link
Contributor

@jcastrence jcastrence commented May 10, 2021

Type of change

  • Improvement (improvement to code, performance, etc)

Description

  • Edited NewSnapshotReader so it now logs if the passed in data file does not exist

Related issues

@jcastrence jcastrence requested a review from a team as a code owner May 10, 2021 18:38
C0rWin
C0rWin previously approved these changes May 10, 2021
@jcastrence jcastrence force-pushed the fab-18469-snapreader_nil branch 2 times, most recently from 9a3d9fc to 499cca6 Compare May 12, 2021 21:34
@manish-sethi
Copy link
Contributor

My suggestion was to simply add the following code in the test file at line 535.

		t.Run("error_missing_data_file_"+f, func(t *testing.T) {
			init()
			defer cleanup()

			dataFile := filepath.Join(snapshotDir, f)
			require.NoError(t, os.Remove(dataFile))
			err := dbEnv.GetProvider().ImportFromSnapshot(
				generateLedgerID(t), version.NewHeight(10, 10), snapshotDir)
			require.Contains(t, err.Error(), fmt.Sprintf("file [%s] does not exist", dataFile))
		})

@jcastrence
Copy link
Contributor Author

My suggestion was to simply add the following code in the test file at line 535.

		t.Run("error_missing_data_file_"+f, func(t *testing.T) {
			init()
			defer cleanup()

			dataFile := filepath.Join(snapshotDir, f)
			require.NoError(t, os.Remove(dataFile))
			err := dbEnv.GetProvider().ImportFromSnapshot(
				generateLedgerID(t), version.NewHeight(10, 10), snapshotDir)
			require.Contains(t, err.Error(), fmt.Sprintf("file [%s] does not exist", dataFile))
		})

Right, however the changes I've made to snapshot.go have caused some of the existing test cases to fail since they are missing either public state or private state hashes. Because of the addition of a new error being thrown if files are missing, they will fail since they are not expecting this new error. I thought that it'd be best to then test these test cases with missing files separately which ends up covering the addition you suggested. What are your thoughts on this?

@manish-sethi
Copy link
Contributor

What are your thoughts on this?

My suggestion would be to fix the input to the existing test.

@denyeart
Copy link
Contributor

Upon further discussion the nil response is expected in some scenarios (such as no private state data) so we can simply leave the functionality as-is and improve the comments and logging to make the intended use more clear.

@jcastrence jcastrence force-pushed the fab-18469-snapreader_nil branch from 499cca6 to 50092cb Compare May 14, 2021 16:26
return nil, errors.WithMessage(err, "error while checking if data file exists")
}
if !exist {
log.Printf("Snapshot data file name does not exist")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Printf("Snapshot data file name does not exist")
logger.Infow("Data file does not exist. Nothing to be done.", "filepath", dataFilePath)

FAB-18469

Signed-off-by: Julian Castrence <[email protected]>
@jcastrence jcastrence force-pushed the fab-18469-snapreader_nil branch from 50092cb to 7a6fec8 Compare May 14, 2021 17:33
@manish-sethi manish-sethi enabled auto-merge (squash) May 14, 2021 17:49
@manish-sethi manish-sethi merged commit 13bcf3f into hyperledger:main May 14, 2021
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.

5 participants