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

CL33-09: Make seq num range resilient to mixed up beginning and end. #404

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

winder
Copy link
Contributor

@winder winder commented Dec 20, 2024

Avoid overflow when End < Start by swapping values to be in the correct order.

@winder winder requested a review from dimkouv December 20, 2024 20:10
@winder winder marked this pull request as ready for review January 7, 2025 14:34
@winder winder requested a review from a team as a code owner January 7, 2025 14:34
Copy link

github-actions bot commented Jan 7, 2025

Metric will/cl33-09 main
Coverage 76.5% 76.4%

@@ -38,6 +38,9 @@ func (s SeqNum) String() string {
}

func NewSeqNumRange(start, end SeqNum) SeqNumRange {
if end < start {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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() {
Copy link
Contributor

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

Copy link
Contributor

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 {
Copy link
Contributor

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

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