Skip to content

Commit

Permalink
kvserver: rename closed_timestamp -> raft_closed_timestamp
Browse files Browse the repository at this point in the history
Rename this replica state field to reflect that fact that it only talks
about the timestamps closed through Raft, not through the upcoming
side-transport. There's going to be also a
sidetransport_closed_timestamp state field.

Release note: None
  • Loading branch information
andreimatei committed Feb 25, 2021
1 parent 88ca1c8 commit 3ddfe0d
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 232 deletions.
1 change: 1 addition & 0 deletions docs/generated/eventlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ is directly or indirectly a member of the admin role) executes a query.
| `NumRetries` | Number of retries, when the txn was reretried automatically by the server. | no |
| `FullTableScan` | Whether the query contains a full table scan. | no |
| `FullIndexScan` | Whether the query contains a full secondary index scan. | no |
| `TxnCounter` | The sequence number of the SQL transaction inside its session. | no |

### `sensitive_table_access`

Expand Down
175 changes: 88 additions & 87 deletions pkg/kv/kvserver/kvserverpb/state.pb.go

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pkg/kv/kvserver/kvserverpb/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ message ReplicaState {
// [2]: PurgeOutdatedReplicas
roachpb.Version version = 12;

// closed_timestamp is the largest timestamp that is known to have been
// closed. This means that the current leaseholder (if any) and any future
// leaseholder will not evaluate writes at or below this timestamp, and also
// that any in-flight commands that can still apply are writing at higher
// timestamps. Non-leaseholder replicas are free to serve "follower reads" at
// or below this timestamp.
util.hlc.Timestamp closed_timestamp = 13 [(gogoproto.nullable) = false];
// raft_closed_timestamp is the largest timestamp that is known to have been
// closed through Raft commands. This means that the current leaseholder (if
// any) and any future leaseholder will not evaluate writes at or below this
// timestamp, and also that any in-flight commands that can still apply are
// writing at higher timestamps. Non-leaseholder replicas are free to serve
// "follower reads" at or below this timestamp.
util.hlc.Timestamp raft_closed_timestamp = 13 [(gogoproto.nullable) = false];

reserved 8, 9, 10;
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/kv/kvserver/replica_application_state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ func (b *replicaAppBatch) Stage(cmdI apply.Command) (apply.CheckedCommand, error
// cmd.proposal.Request filled in.
if cmd.IsLocal() && cmd.proposal.Request.IsIntentWrite() {
wts := cmd.proposal.Request.WriteTimestamp()
if wts.LessEq(b.state.ClosedTimestamp) {
if wts.LessEq(b.state.RaftClosedTimestamp) {
return nil, makeNonDeterministicFailure("writing at %s below closed ts: %s (%s)",
wts, b.state.ClosedTimestamp.String(), cmd.proposal.Request.String())
wts, b.state.RaftClosedTimestamp.String(), cmd.proposal.Request.String())
}
}
log.Event(ctx, "applying command")
Expand Down Expand Up @@ -824,12 +824,12 @@ func (b *replicaAppBatch) stageTrivialReplicatedEvalResult(
b.state.LeaseAppliedIndex = leaseAppliedIndex
}
if cts := cmd.raftCmd.ClosedTimestamp; cts != nil && !cts.IsEmpty() {
if cts.Less(b.state.ClosedTimestamp) {
if cts.Less(b.state.RaftClosedTimestamp) {
log.Fatalf(ctx,
"closed timestamp regressing from %s to %s when applying command %x",
b.state.ClosedTimestamp, cts, cmd.idKey)
b.state.RaftClosedTimestamp, cts, cmd.idKey)
}
b.state.ClosedTimestamp = *cts
b.state.RaftClosedTimestamp = *cts
if clockTS, ok := cts.TryToClockTimestamp(); ok {
b.maxTS.Forward(clockTS)
}
Expand Down Expand Up @@ -892,7 +892,7 @@ func (b *replicaAppBatch) ApplyToStateMachine(ctx context.Context) error {
r.mu.Lock()
r.mu.state.RaftAppliedIndex = b.state.RaftAppliedIndex
r.mu.state.LeaseAppliedIndex = b.state.LeaseAppliedIndex
closedTimestampUpdated := r.mu.state.ClosedTimestamp.Forward(b.state.ClosedTimestamp)
closedTimestampUpdated := r.mu.state.RaftClosedTimestamp.Forward(b.state.RaftClosedTimestamp)
prevStats := *r.mu.state.Stats
*r.mu.state.Stats = *b.state.Stats

Expand Down Expand Up @@ -963,7 +963,7 @@ func (b *replicaAppBatch) addAppliedStateKeyToBatch(ctx context.Context) error {
// lease index along with the mvcc stats, all in one key.
if err := loader.SetRangeAppliedState(
ctx, b.batch, b.state.RaftAppliedIndex, b.state.LeaseAppliedIndex,
b.state.Stats, &b.state.ClosedTimestamp,
b.state.Stats, &b.state.RaftClosedTimestamp,
); err != nil {
return wrapWithNonDeterministicFailure(err, "unable to set range applied state")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/replica_follower_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (r *Replica) maxClosedRLocked(ctx context.Context) (_ hlc.Timestamp, ok boo
lai := r.mu.state.LeaseAppliedIndex
lease := *r.mu.state.Lease
initialMaxClosed := r.mu.initialMaxClosed
replicaStateClosed := r.mu.state.ClosedTimestamp
replicaStateClosed := r.mu.state.RaftClosedTimestamp

if lease.Expiration != nil {
return hlc.Timestamp{}, false
Expand Down Expand Up @@ -170,5 +170,5 @@ func (r *Replica) GetFrozenClosedTimestamp() hlc.Timestamp {
defer r.mu.RUnlock()
// TODO(andrei): Make sure that this synchronizes with the closed timestamps
// side-transport once the side-transport is written.
return r.mu.state.ClosedTimestamp
return r.mu.state.RaftClosedTimestamp
}
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (r *Replica) leasePostApplyLocked(

// Inform the propBuf about the new lease so that it can initialize its closed
// timestamp tracking.
r.mu.proposalBuf.OnLeaseChangeLocked(iAmTheLeaseHolder, r.mu.state.ClosedTimestamp)
r.mu.proposalBuf.OnLeaseChangeLocked(iAmTheLeaseHolder, r.mu.state.RaftClosedTimestamp)

// Ordering is critical here. We only install the new lease after we've
// checked for an in-progress merge and updated the timestamp cache. If the
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_proposal_buf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ func (rp *replicaProposer) closeTimestampPolicy() roachpb.RangeClosedTimestampPo
}

func (rp *replicaProposer) raftTransportClosedTimestampEnabled() bool {
return !(*Replica)(rp).mu.state.ClosedTimestamp.IsEmpty()
return !(*Replica)(rp).mu.state.RaftClosedTimestamp.IsEmpty()
}

func (rp *replicaProposer) withGroupLocked(fn func(raftGroup proposerRaft) error) error {
Expand Down
21 changes: 11 additions & 10 deletions pkg/kv/kvserver/stateloader/stateloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (rsl StateLoader) Load(

ms := as.RangeStats.ToStats()
s.Stats = &ms
if as.ClosedTimestamp != nil {
s.ClosedTimestamp = *as.ClosedTimestamp
if as.RaftClosedTimestamp != nil {
s.RaftClosedTimestamp = *as.RaftClosedTimestamp
}
} else {
if s.RaftAppliedIndex, s.LeaseAppliedIndex, err = rsl.LoadAppliedIndex(ctx, reader); err != nil {
Expand Down Expand Up @@ -170,7 +170,7 @@ func (rsl StateLoader) Save(
}
}
if state.UsingAppliedStateKey {
rai, lai, ct := state.RaftAppliedIndex, state.LeaseAppliedIndex, &state.ClosedTimestamp
rai, lai, ct := state.RaftAppliedIndex, state.LeaseAppliedIndex, &state.RaftClosedTimestamp
if err := rsl.SetRangeAppliedState(ctx, readWriter, rai, lai, ms, ct); err != nil {
return enginepb.MVCCStats{}, err
}
Expand Down Expand Up @@ -298,23 +298,24 @@ func (rsl StateLoader) LoadMVCCStats(
// keys. We now deem those keys to be "legacy" because they have been replaced
// by the range applied state key.
//
// TODO(andrei): closedTS is a pointer to avoid an allocation when putting it in
// RangeAppliedState. RangeAppliedState.ClosedTimestamp is made non-nullable
// (see comments on the field), this argument should be taken by value.
// TODO(andrei): raftClosedTimestamp is a pointer to avoid an allocation when
// putting it in RangeAppliedState. RangeAppliedState.RaftClosedTimestamp is
// made non-nullable (see comments on the field), this argument should be taken
// by value.
func (rsl StateLoader) SetRangeAppliedState(
ctx context.Context,
readWriter storage.ReadWriter,
appliedIndex, leaseAppliedIndex uint64,
newMS *enginepb.MVCCStats,
closedTS *hlc.Timestamp,
raftClosedTimestamp *hlc.Timestamp,
) error {
as := enginepb.RangeAppliedState{
RaftAppliedIndex: appliedIndex,
LeaseAppliedIndex: leaseAppliedIndex,
RangeStats: newMS.ToPersistentStats(),
}
if closedTS != nil && !closedTS.IsEmpty() {
as.ClosedTimestamp = closedTS
if raftClosedTimestamp != nil && !raftClosedTimestamp.IsEmpty() {
as.RaftClosedTimestamp = raftClosedTimestamp
}
// The RangeAppliedStateKey is not included in stats. This is also reflected
// in C.MVCCComputeStats and ComputeStatsForRange.
Expand Down Expand Up @@ -489,7 +490,7 @@ func (rsl StateLoader) SetMVCCStats(
return err
} else if as != nil {
return rsl.SetRangeAppliedState(
ctx, readWriter, as.RaftAppliedIndex, as.LeaseAppliedIndex, newMS, as.ClosedTimestamp)
ctx, readWriter, as.RaftAppliedIndex, as.LeaseAppliedIndex, newMS, as.RaftClosedTimestamp)
}

return rsl.writeLegacyMVCCStatsInternal(ctx, readWriter, newMS)
Expand Down
Loading

0 comments on commit 3ddfe0d

Please sign in to comment.