Skip to content

Commit

Permalink
Merge #34566
Browse files Browse the repository at this point in the history
34566: storage/roachpb: various cleanup around Refresh{Range}Request r=nvanbenschoten a=nvanbenschoten

This PR includes a few small changes that I noticed while investigating #34025.

Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
  • Loading branch information
craig[bot] and nvanbenschoten committed Feb 5, 2019
2 parents 9db4764 + e7d470a commit 651376d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
19 changes: 14 additions & 5 deletions pkg/roachpb/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,11 +1076,20 @@ func (*ImportRequest) flags() int { return isAdmin | isAlone }
func (*AdminScatterRequest) flags() int { return isAdmin | isAlone | isRange }
func (*AddSSTableRequest) flags() int { return isWrite | isAlone | isRange | isUnsplittable }

// RefreshRequest and RefreshRangeRequest both list
// updates(Read)TSCache, though they actually update the read or write
// timestamp cache depending on the write parameter in the request.
func (*RefreshRequest) flags() int { return isRead | isTxn | updatesReadTSCache }
func (*RefreshRangeRequest) flags() int { return isRead | isTxn | isRange | updatesReadTSCache }
// RefreshRequest and RefreshRangeRequest both determine which timestamp cache
// they update based on their Write parameter.
func (r *RefreshRequest) flags() int {
if r.Write {
return isRead | isTxn | updatesWriteTSCache
}
return isRead | isTxn | updatesReadTSCache
}
func (r *RefreshRangeRequest) flags() int {
if r.Write {
return isRead | isTxn | isRange | updatesWriteTSCache
}
return isRead | isTxn | isRange | updatesReadTSCache
}

func (*SubsumeRequest) flags() int { return isRead | isAlone | updatesReadTSCache }

Expand Down
9 changes: 7 additions & 2 deletions pkg/storage/batcheval/cmd_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ func Refresh(
if err != nil {
return result.Result{}, err
} else if val != nil {
// TODO(nvanbenschoten): This is pessimistic. We only need to check
// !ts.Less(h.Txn.PrevRefreshTimestamp)
// This could avoid failed refreshes due to requests performed after
// earlier refreshes (which read at the refresh ts) that already
// observed writes between the orig ts and the refresh ts.
if ts := val.Timestamp; !ts.Less(h.Txn.OrigTimestamp) {
return result.Result{}, errors.Errorf("encountered recently written key %s @%s", args.Key, ts)
}
}

// Now, check if the intent was written earlier than the command's timestamp
// and was not owned by this transaction.
// Check if an intent which is not owned by this transaction was written
// at or beneath the refresh timestamp.
if intent != nil && intent.Txn.ID != h.Txn.ID {
return result.Result{}, errors.Errorf("encountered recently written intent %s @%s",
intent.Span.Key, intent.Txn.Timestamp)
Expand Down
9 changes: 7 additions & 2 deletions pkg/storage/batcheval/cmd_refresh_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func RefreshRange(
Inconsistent: true,
Tombstones: true,
}, func(kv roachpb.KeyValue) (bool, error) {
// TODO(nvanbenschoten): This is pessimistic. We only need to check
// !ts.Less(h.Txn.PrevRefreshTimestamp)
// This could avoid failed refreshes due to requests performed after
// earlier refreshes (which read at the refresh ts) that already
// observed writes between the orig ts and the refresh ts.
if ts := kv.Value.Timestamp; !ts.Less(h.Txn.OrigTimestamp) {
return true, errors.Errorf("encountered recently written key %s @%s", kv.Key, ts)
}
Expand All @@ -61,8 +66,8 @@ func RefreshRange(
return result.Result{}, err
}

// Now, check intents slice for any which were written earlier than
// the command's timestamp, not owned by this transaction.
// Check if any intents which are not owned by this transaction were written
// at or beneath the refresh timestamp.
for _, i := range intents {
// Ignore our own intents.
if i.Txn.ID == h.Txn.ID {
Expand Down
10 changes: 0 additions & 10 deletions pkg/storage/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ var MaxCommandSize = settings.RegisterValidatedByteSizeSetting(
},
)

// FollowerReadsEnabled controls whether replicas attempt to serve follower
// reads. The closed timestamp machinery is unaffected by this, i.e. the same
// information is collected and passed around, regardless of the value of this
// setting.
var FollowerReadsEnabled = settings.RegisterBoolSetting(
"kv.closed_timestamp.follower_reads_enabled",
"allow (all) replicas to serve consistent historical reads based on closed timestamp information",
false,
)

type proposalReevaluationReason int

const (
Expand Down
11 changes: 11 additions & 0 deletions pkg/storage/replica_follower_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ import (
"context"

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/storage/closedts/ctpb"
ctstorage "github.com/cockroachdb/cockroach/pkg/storage/closedts/storage"
"github.com/cockroachdb/cockroach/pkg/util/log"
)

// FollowerReadsEnabled controls whether replicas attempt to serve follower
// reads. The closed timestamp machinery is unaffected by this, i.e. the same
// information is collected and passed around, regardless of the value of this
// setting.
var FollowerReadsEnabled = settings.RegisterBoolSetting(
"kv.closed_timestamp.follower_reads_enabled",
"allow (all) replicas to serve consistent historical reads based on closed timestamp information",
false,
)

// canServeFollowerRead tests, when a range lease could not be
// acquired, whether the read only batch can be served as a follower
// read despite the error.
Expand Down
4 changes: 0 additions & 4 deletions pkg/storage/replica_tscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ func (r *Replica) updateTimestampCache(
tc.Add(start, end, t.Txn.Timestamp, uuid.UUID{}, true /* readCache */)
}
}
case *roachpb.RefreshRequest:
tc.Add(start, end, ts, txnID, !t.Write /* readCache */)
case *roachpb.RefreshRangeRequest:
tc.Add(start, end, ts, txnID, !t.Write /* readCache */)
default:
tc.Add(start, end, ts, txnID, !roachpb.UpdatesWriteTimestampCache(args))
}
Expand Down

0 comments on commit 651376d

Please sign in to comment.