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

SegmentSet.Add allow missing LastOffset #360

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions cmd/gazctl/gazctlcmd/shards_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,8 @@ func foldHintsIntoSegments(hints recoverylog.FSMHints, sets map[pb.Journal]recov
for _, segment := range segments {
var set = sets[segment.Log]

// set.Add() will return an error if we attempt to add a segment having a
// greater SeqNo and LastOffset != 0, to a set already having a lesser
// SeqNo and LastOffset == 0. Or, if FirstSeqNo is equal, it will replace
// a zero LastOffset with a non-zero one (which is not what we want
// in this case).
// If FirstSeqNo is equal, set.Add will replace a zero LastOffset with a
// non-zero one (which is not what we want in this case).
//
// So, zero LastOffset here if |segment| isn't strictly less than
// and non-overlapping with a pre-existing last LastOffset==0 element.
Expand Down
2 changes: 0 additions & 2 deletions consumer/recoverylog/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ func reduceSegment(a, b Segment) (Segment, error) {
// Offset ordering constraint checks.
case a.FirstSeqNo < b.FirstSeqNo && a.Log == b.Log && a.FirstOffset > b.FirstOffset:
return a, fmt.Errorf("expected monotonic FirstOffset: %#v vs %#v", a, b)
case a.FirstSeqNo < b.FirstSeqNo && a.LastOffset == 0 && b.LastOffset != 0:
return a, fmt.Errorf("expected preceding Segment to also include LastOffset: %#v vs %#v", a, b)

case a.LastOffset == 0 && a.Log != b.Log:
// This cases isn't strictly required, but it's true of the intended
Expand Down
21 changes: 15 additions & 6 deletions consumer/recoverylog/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func (s *SegmentSuite) TestSegmentReductionCases(c *gc.C) {
},
// Overlap, and preceding Segment is missing LastOffset.
{
a: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 7, FirstOffset: 200, LastOffset: 000, FirstChecksum: 0x22, Log: A},
b: Segment{Author: 0x1, FirstSeqNo: 4, LastSeqNo: 9, FirstOffset: 400, LastOffset: 901, FirstChecksum: 0x44, Log: A},
err: "expected preceding Segment to also include LastOffset: .*",
a: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 7, FirstOffset: 200, LastOffset: 000, FirstChecksum: 0x22, Log: A},
b: Segment{Author: 0x1, FirstSeqNo: 4, LastSeqNo: 9, FirstOffset: 400, LastOffset: 901, FirstChecksum: 0x44, Log: A},
e: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 9, FirstOffset: 200, LastOffset: 901, FirstChecksum: 0x22, Log: A},
},
// Overlap, mismatched authors.
{
Expand All @@ -98,6 +98,12 @@ func (s *SegmentSuite) TestSegmentReductionCases(c *gc.C) {
b: Segment{Author: 0x1, FirstSeqNo: 3, LastSeqNo: 6, FirstOffset: 300, LastOffset: 000, FirstChecksum: 0x33, Log: A},
e: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 7, FirstOffset: 200, LastOffset: 701, FirstChecksum: 0x22, Log: A},
},
// Covered, with 0 LastOffset
{
a: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 7, FirstOffset: 200, LastOffset: 701, FirstChecksum: 0x22, Log: A},
b: Segment{Author: 0x1, FirstSeqNo: 1, LastSeqNo: 8, FirstOffset: 2, LastOffset: 0, FirstChecksum: 0x33, Log: A},
e: Segment{Author: 0x1, FirstSeqNo: 1, LastSeqNo: 8, FirstOffset: 2, LastOffset: 0, FirstChecksum: 0x33, Log: A},
},
// Disjoint.
{
a: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 4, FirstOffset: 200, LastOffset: 401, FirstChecksum: 0x22, Log: A},
Expand All @@ -122,6 +128,12 @@ func (s *SegmentSuite) TestSegmentReductionCases(c *gc.C) {
b: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 9, FirstOffset: 210, LastOffset: 901, FirstChecksum: 0x22, Log: A},
e: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 9, FirstOffset: 210, LastOffset: 901, FirstChecksum: 0x22, Log: A},
},
// Equal-left, with LastOffset: 0
{
a: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 7, FirstOffset: 200, LastOffset: 701, FirstChecksum: 0x22, Log: A},
b: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 9, FirstOffset: 200, LastOffset: 000, FirstChecksum: 0x22, Log: A},
e: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 9, FirstOffset: 200, LastOffset: 000, FirstChecksum: 0x22, Log: A},
},
// Equal-left, but checksum mismatch.
{
a: Segment{Author: 0x1, FirstSeqNo: 2, LastSeqNo: 7, FirstOffset: 200, LastOffset: 701, FirstChecksum: 0x22, Log: A},
Expand Down Expand Up @@ -254,9 +266,6 @@ func (s *SegmentSuite) TestSetConsistencyChecks(c *gc.C) {
// Overlapping, incorrect log.
{Segment{Author: 0xa, FirstSeqNo: 4, LastSeqNo: 5, FirstOffset: 400, LastOffset: 501, Log: "wrong"},
"expected Segment Log equality: .*"},
// Missing LastOffset.
{Segment{Author: 0xb, FirstSeqNo: 12, LastSeqNo: 12, FirstOffset: 1200, LastOffset: 000, Log: A},
"expected preceding Segment to also include LastOffset: .*"},
// Non-monotonic offsets.
{Segment{Author: 0xb, FirstSeqNo: 12, LastSeqNo: 12, FirstOffset: 1050, LastOffset: 1200, Log: A},
"expected monotonic FirstOffset: .*"},
Expand Down
Loading