Skip to content

Conversation

@matthewdale
Copy link
Collaborator

GODRIVER-1969

Summary

  • Use the updated unified-format GridFS spec tests and remove the old GridFS spec tests and spec test runner.
  • Update the unified spec test runner to support all functions required by the unified-format GridFS spec tests.
  • Fix a bug in the GridFS DownloadStream API that failed to return an error when chunks were missing at the end of a GridFS file.

Background & Motivation

This is a prerequisite for completely removing the x/bsonx package (GODRIVER-2416) because the current GridFS spec test runner relies heavily on bsonx.Doc APIs that have no analog for the bson.D type (see this comment for more details).

// If there are no more chunks, but we didn't read the expected number of chunks, return an
// ErrWrongIndex error to indicate that we're missing chunks at the end of the file.
if ds.expectedChunk != ds.numChunks {
return ErrWrongIndex
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the difference between ErrWrongIndex and ErrWrongSize?

Copy link
Contributor

Choose a reason for hiding this comment

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

Our documentation says:

// ErrWrongIndex is used when the chunk retrieved from the server does not have the expected index.
...
// ErrWrongSize is used when the chunk retrieved from the server does not have the expected size.

ErrWrongIndex seems more accurate in this situation than ErrWrongSize. I could also see an argument for a new error type, something like ErrMissingChunks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that the error name/description is kinda confusing and an ErrMissingChunk would be more clear. However, since it's caused by the same issue where ErrWrongIndex is currently used (i.e. a chunk is missing), I decided it was better to use the same error so any existing error checking code would continue working.

I originally decided to use ErrWrongIndex because the unified spec test describing the error it's expecting as "ChunkIsMissing". In the Go Driver, there isn't a "ChunkIsMissing" error, but the current spec test runner maps "ChunkIsMissing" to ErrWrongIndex.

I think we should use ErrWrongIndex in both cases, but maybe we can/should update the error message? Something like:

chunk is missing or index does not match expected index

Copy link
Contributor

Choose a reason for hiding this comment

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

Using ErrWrongIndex SGTM, but I'm hesitant to change the message for ErrWrongIndex in case users are checking for the current message. That said, GridFS does not get much usage, and most users would probably do something like errors.Is(err, gridfs.ErrWrongIndex), anyway, so up to you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll leave it as-is and add a proposal to the Go Driver 2.0 scope to rename and/or update the description of the error.

// If there are no more chunks, but we didn't read the expected number of chunks, return an
// ErrWrongIndex error to indicate that we're missing chunks at the end of the file.
if ds.expectedChunk != ds.numChunks {
return ErrWrongIndex
Copy link
Contributor

Choose a reason for hiding this comment

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

Our documentation says:

// ErrWrongIndex is used when the chunk retrieved from the server does not have the expected index.
...
// ErrWrongSize is used when the chunk retrieved from the server does not have the expected size.

ErrWrongIndex seems more accurate in this situation than ErrWrongSize. I could also see an argument for a new error type, something like ErrMissingChunks.

matthewdale and others added 2 commits November 9, 2022 11:38
Co-authored-by: Benjamin Rewis <32186188+benjirewis@users.noreply.github.com>
Copy link
Collaborator

@qingyang-hu qingyang-hu left a comment

Choose a reason for hiding this comment

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

LGTM!

@matthewdale matthewdale merged commit 1c35f30 into mongodb:master Nov 10, 2022
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.

3 participants