Repository navigation
Conversation
When a Zero becomes leader (after an election, or when a single Zero restarts), updateLeases sets startTxnTs to MaxTxnTs+1 and resets keyCommit. The new leader has lost the conflict map of the previous term, so it relies on startTxnTs to abort every transaction that started before it took over. purgeBelow, called when Zero applies one of its own snapshot proposals, then set startTxnTs = minTs unconditionally. minTs is the lowest checkpoint ts reported by the Alpha groups. A snapshot proposal can carry a checkpoint below the floor set at the leader change, for example when a group is behind, and then startTxnTs drops below the start ts of a transaction that is still open from before the change. That transaction then commits without a conflict check against writes committed in the previous term. The unconditional assignment came in with dgraph-io#7096. Only raise startTxnTs in purgeBelow: the floor is kept until a checkpoint exceeds it.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Description
When a Zero becomes leader (after an election, or when a single Zero restarts),
updateLeasescallsupdateStartTxnTs(MaxTxnTs+1), which also resetskeyCommit. The new leader has lost the previous term's conflict map, sohasConflictrelies onstartTxnTsto abort every transaction that started before the change.purgeBelowruns when Zero applies one of its own snapshot proposals (applySnapshot), and it setstartTxnTs = minTsunconditionally.minTsis the lowest checkpoint ts reported by the Alpha groups. A snapshot proposal can carry a checkpoint below the floor set at the leader change, for example when a group is behind. In that casestartTxnTsdrops below the start ts of a transaction that is still open from before the change. That transaction then commits with no conflict check against writes committed in the previous term: a lost update.The unconditional assignment came in with #7096. This PR changes it to
max(startTxnTs, minTs), so the floor holds until a checkpoint exceeds it. Trimming ofcommitsandkeyCommitis unchanged.Testing
TestPurgeBelowDoesNotLowerStartTxnTs(dgraph/cmd/zero/oracle_test.go) drives theOraclestate transition directly: a commit, thenupdateStartTxnTsas on a leader change, thenpurgeBelowwith a lower checkpoint. It then checks thatcommitrejects the older transaction. It does not run a cluster failover. It checks only that the commit is rejected, not which error is returned: if #9747 lands first, the same commit is reported as a stale start ts.It fails without the fix (the commit succeeds) and passes with it, both on its own and merged with #9747. Also checked:
go test ./dgraph/cmd/zero/, the test with-race,gofmt, andgolangci-lint2.15.0 with the trunk config.trunk/configs/.golangci.json(0 issues on changed lines).Checklist
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit