-
Notifications
You must be signed in to change notification settings - Fork 5
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
CL33-09: Make seq num range resilient to mixed up beginning and end. #404
base: main
Are you sure you want to change the base?
Conversation
|
@@ -38,6 +38,9 @@ func (s SeqNum) String() string { | |||
} | |||
|
|||
func NewSeqNumRange(start, end SeqNum) SeqNumRange { | |||
if end < start { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we even allow this to begin with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went back and forth about this question. This could generate an error but would require updating >150 spots where we use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are they all tests?
@@ -96,6 +99,9 @@ func (s SeqNumRange) String() string { | |||
} | |||
|
|||
func (s SeqNumRange) Length() int { | |||
if s.End() < s.Start() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is probably not needed considering you've already covered that on the constructor level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it's misleading to shuffle with the state in the read method. If you need a defensive check then probably calling absolute value on the computed length should work, no?
@@ -38,6 +38,9 @@ func (s SeqNum) String() string { | |||
} | |||
|
|||
func NewSeqNumRange(start, end SeqNum) SeqNumRange { | |||
if end < start { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not sure about that. Shouldn't we error when someone mixes start with the end? We could hide some underlying bug when "healing" that state during runtime
Avoid overflow when End < Start by swapping values to be in the correct order.