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

nsqd: enforce minimum msg size when reading from the diskqueue #600

Merged
merged 1 commit into from
Jul 13, 2015
Merged

nsqd: enforce minimum msg size when reading from the diskqueue #600

merged 1 commit into from
Jul 13, 2015

Conversation

twmb
Copy link
Contributor

@twmb twmb commented Jul 10, 2015

See #598

@mreiferson mreiferson changed the title enforce minimum msg size when reading from the diskqueue nsqd: enforce minimum msg size when reading from the diskqueue Jul 11, 2015
@mreiferson mreiferson added the bug label Jul 11, 2015
// TODO: this is off by one, but we cannot fix this without also fixing
// readOne above. We cannot fix readOne above until we guarantee that
// every old diskqueue format has been fully processed, otherwise we
// will miss one message from old formatted files.
Copy link
Member

Choose a reason for hiding this comment

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

what do you mean by this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is meant to rotate files when we reach maxBytesPerFile, but will only
rotate when we exceed that number. If max bytes is 1024 and we are at bytes
1024, we will write one more message before rotating files.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough, however for all practical purposes I don't think this is something that needs to be addressed other than perhaps the documentation around the config param.

Can we remove this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

@mreiferson
Copy link
Member

nice work on this @twmb - thanks for adding all those comments to the tests!

… diskqueue

Prevents panics in the face of corrupt messages.
@@ -261,6 +266,14 @@ func (d *diskQueue) readOne() ([]byte, error) {
return nil, err
}

if msgSize < d.minMsgSize || msgSize > d.maxMsgSize {
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if msgSize > d.maxMsgSize means it's corrupt? It should skip it, but does it need to discard the whole segment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

msgSize could be > d.maxMsgSize because of either

a) a corrupt message, or
b) a person changed the flag of their maxMsgSize between nsqd restarts

If it's a corrupt message, then we'd skip forward in the file and then have no guarantee of what we're reading. If a person changed their maxMsgSize, they'd miss this message and be fine reading the next. I don't think it's too common to reduce MaxMsgSize between nsqd restarts other than when a person is trying to figure out parameters, and if they're fine with losing any large messages when tuning, I can't see why they wouldn't be fine losing an entire segment.

I favor discarding the file but I could go either way.

Copy link
Member

Choose a reason for hiding this comment

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

Alright, you've sold me - all of this falls under "reasonable behavior" without actually knowing if it's corrupt.

mreiferson added a commit that referenced this pull request Jul 13, 2015
nsqd: enforce minimum msg size when reading from the diskqueue
@mreiferson mreiferson merged commit 917a6c8 into nsqio:master Jul 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants