pingcap / pingcap/ticdc

maintainer: make compareEventKey return 0 for equal event keys

Open Beginner friendly
#5,187 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
56
Forks
63
Avg merge
2d 20h
Merged PRs (30d)
34

Description

Issue

compareEventKey currently returns 1 when two eventKey values are equal.

Current code in maintainer/barrier_helper.go:

func compareEventKey(a, b eventKey) int {
	if a.blockTs < b.blockTs {
		return -1
	}
	if a.blockTs > b.blockTs {
		return 1
	}
	if !a.isSyncPoint && b.isSyncPoint {
		return -1
	}
	return 1
}

For equal blockTs and equal isSyncPoint, the comparator should return 0.
Returning 1 violates the normal comparator contract used by slices.SortFunc and can also make future heap/sort usages harder to reason about.

Suggested fix

Handle both tie-break directions explicitly, then return 0 for equality:

func compareEventKey(a, b eventKey) int {
	if a.blockTs < b.blockTs {
		return -1
	}
	if a.blockTs > b.blockTs {
		return 1
	}
	if !a.isSyncPoint && b.isSyncPoint {
		return -1
	}
	if a.isSyncPoint && !b.isSyncPoint {
		return 1
	}
	return 0
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in maintainer/barrier_helper.go at compareEventKey and inspect its slices.SortFunc usage. Verify the comparator's ordering for blockTs and isSyncPoint combinations, then run the relevant maintainer tests. Done means equal event keys compare as 0 while the existing ordering remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.