-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
start, end = end, start | ||
} | ||
return SeqNumRange{start, end} | ||
} | ||
|
||
|
@@ -65,7 +68,7 @@ func (s *SeqNumRange) SetEnd(v SeqNum) { | |
func (s *SeqNumRange) Limit(n uint64) SeqNumRange { | ||
limitedRange := NewSeqNumRange(s.Start(), s.End()) | ||
|
||
numElems := s.End() - s.Start() + 1 | ||
numElems := s.Length() | ||
if numElems <= 0 { | ||
return limitedRange | ||
} | ||
|
@@ -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 commentThe 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 commentThe 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? |
||
s[0], s[1] = s[1], s[0] | ||
} | ||
return int(s.End() - s.Start() + 1) | ||
} | ||
|
||
|
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?