Skip to content

Commit

Permalink
use physical clock
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyihu6 committed Feb 23, 2025
1 parent 747e598 commit f3dd474
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (proposal *ProposalData) recordProposalToLocalApplicationLatency() {
}
if ts := proposal.createdAtTs; !ts.IsZero() {
// Read-only commands have a zero replicatingSince timestamp.
proposal.ec.repl.recordProposalToLocalApplicationLatency(timeutil.Since(ts))
proposal.ec.repl.recordProposalToLocalApplicationLatency(proposal.ec.repl.Clock().PhysicalTime().Sub(ts))
}
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/kv/kvserver/replica_proposal_buf.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/errors"
)

Expand Down Expand Up @@ -143,6 +142,7 @@ type proposer interface {
enqueueUpdateCheck()
closedTimestampTarget() hlc.Timestamp
shouldCampaignOnRedirect(raftGroup proposerRaft, leaseType roachpb.LeaseType) bool
physicalTime() time.Time

// The following require the proposer to hold an exclusive lock.
withGroupLocked(func(proposerRaft) error) error
Expand Down Expand Up @@ -1224,7 +1224,7 @@ func (rp *replicaProposer) registerProposalLocked(p *ProposalData) {
p.createdAtTicks = rp.mu.ticks
}
if p.createdAtTs.IsZero() {
p.createdAtTs = timeutil.Now()
p.createdAtTs = rp.physicalTime()
}
rp.mu.lastProposalAtTicks = rp.mu.ticks // monotonically increasing
if prev := rp.mu.proposals[p.idKey]; prev != nil && prev != p {
Expand All @@ -1237,6 +1237,10 @@ func (rp *replicaProposer) registerProposalLocked(p *ProposalData) {
rp.mu.proposals[p.idKey] = p
}

func (rp *replicaProposer) physicalTime() time.Time {
return (*Replica)(rp).Clock().PhysicalTime()
}

func (rp *replicaProposer) shouldCampaignOnRedirect(
raftGroup proposerRaft, leaseType roachpb.LeaseType,
) bool {
Expand Down

0 comments on commit f3dd474

Please sign in to comment.