Skip to content

Commit dd17998

Browse files
committed
kvclient: make cacheEntry private
CacheEntry is not intended to be exposed externally. This commit makes it a private type in the RangeCache. Epic: none Release note: None
1 parent b9ad824 commit dd17998

File tree

2 files changed

+82
-82
lines changed

2 files changed

+82
-82
lines changed

pkg/kv/kvclient/rangecache/range_cache.go

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const (
9494
ReadFromLeaseholder = kvpb.READ_UNCOMMITTED
9595
)
9696

97-
// UnknownClosedTimestampPolicy is used to mark on a CacheEntry that the closed
97+
// UnknownClosedTimestampPolicy is used to mark on a cacheEntry that the closed
9898
// timestamp policy is not known. This value is never serialized into
9999
// RangeInfo or any other message which uses the type.
100100
const UnknownClosedTimestampPolicy roachpb.RangeClosedTimestampPolicy = -1
@@ -275,18 +275,18 @@ type EvictionToken struct {
275275
// compatible descriptor, with the same range id and key bounds. If the
276276
// descriptor changes in a non-compatible way, this EvictionToken must be
277277
// discarded and a new one retrieved from the RangeCache.
278-
entry *CacheEntry
278+
entry *cacheEntry
279279
}
280280

281-
func (rc *RangeCache) makeEvictionToken(entry *CacheEntry) EvictionToken {
281+
func (rc *RangeCache) makeEvictionToken(entry *cacheEntry) EvictionToken {
282282
return EvictionToken{
283283
rdc: rc,
284284
entry: entry,
285285
}
286286
}
287287

288288
// MakeEvictionToken is the exported ctor. For tests only.
289-
func (rc *RangeCache) MakeEvictionToken(entry *CacheEntry) EvictionToken {
289+
func (rc *RangeCache) MakeEvictionToken(entry *cacheEntry) EvictionToken {
290290
return rc.makeEvictionToken(entry)
291291
}
292292

@@ -375,7 +375,7 @@ func (et EvictionToken) ClosedTimestampPolicy(
375375
// entry for the start key any more.
376376
func (et *EvictionToken) syncRLocked(
377377
ctx context.Context,
378-
) (stillValid bool, cachedEntry *CacheEntry, rawEntry *cache.Entry) {
378+
) (stillValid bool, cachedEntry *cacheEntry, rawEntry *cache.Entry) {
379379
cachedEntry, rawEntry = et.rdc.getCachedRLocked(ctx, et.entry.desc.StartKey, false /* inverted */)
380380
if cachedEntry == nil || !descsCompatible(cachedEntry.Desc(), et.Desc()) {
381381
et.clear()
@@ -622,11 +622,11 @@ func (rc *RangeCache) Lookup(ctx context.Context, key roachpb.RKey) (roachpb.Ran
622622

623623
// GetCachedOverlapping returns all the cached entries which overlap a given
624624
// span [Key, EndKey). The results are sorted ascendingly.
625-
func (rc *RangeCache) GetCachedOverlapping(ctx context.Context, span roachpb.RSpan) []*CacheEntry {
625+
func (rc *RangeCache) GetCachedOverlapping(ctx context.Context, span roachpb.RSpan) []*cacheEntry {
626626
rc.rangeCache.RLock()
627627
defer rc.rangeCache.RUnlock()
628628
rawEntries := rc.getCachedOverlappingRLocked(ctx, span)
629-
entries := make([]*CacheEntry, len(rawEntries))
629+
entries := make([]*cacheEntry, len(rawEntries))
630630
for i, e := range rawEntries {
631631
entries[i] = rc.getValue(e)
632632
}
@@ -906,10 +906,10 @@ func tryLookupImpl(
906906
rc.rangeCache.Lock()
907907
defer rc.rangeCache.Unlock()
908908

909-
// We want to insert a new CacheEntry, possibly with a speculativeDesc.
909+
// We want to insert a new cacheEntry, possibly with a speculativeDesc.
910910
// Create the entry based on the lookup and try and insert it into the
911911
// cache.
912-
newEntry := CacheEntry{
912+
newEntry := cacheEntry{
913913
desc: rs[0],
914914
// We don't have any lease information.
915915
lease: roachpb.Lease{},
@@ -930,10 +930,10 @@ func tryLookupImpl(
930930
// rs[0]'s eviction token. Note that ranges for which the cache has more
931931
// up-to-date information will not be clobbered - for example ranges for
932932
// which the cache has the prefetched descriptor already plus a lease.
933-
newEntries := make([]*CacheEntry, len(preRs)+1)
933+
newEntries := make([]*cacheEntry, len(preRs)+1)
934934
newEntries[0] = &newEntry
935935
for i, preR := range preRs {
936-
newEntries[i+1] = &CacheEntry{desc: preR, closedts: UnknownClosedTimestampPolicy}
936+
newEntries[i+1] = &cacheEntry{desc: preR, closedts: UnknownClosedTimestampPolicy}
937937
}
938938
insertedEntries := rc.insertLockedInner(ctx, newEntries)
939939
// entry corresponds to rs[0], which is the descriptor covering the key
@@ -1051,7 +1051,7 @@ func (rc *RangeCache) TestingGetCached(
10511051
// used for descriptor eviction.
10521052
func (rc *RangeCache) getCachedRLocked(
10531053
ctx context.Context, key roachpb.RKey, inverted bool,
1054-
) (*CacheEntry, *cache.Entry) {
1054+
) (*cacheEntry, *cache.Entry) {
10551055
// rawEntry will be the range containing key, or the first cached entry around
10561056
// key, in the direction indicated by inverted.
10571057
var rawEntry *cache.Entry
@@ -1117,10 +1117,10 @@ func (rc *RangeCache) Insert(ctx context.Context, rs ...roachpb.RangeInfo) {
11171117
// for putting in eviction tokens. Any element in the returned array can be nil
11181118
// if inserting the respective RangeInfo failed because it was found to be
11191119
// stale.
1120-
func (rc *RangeCache) insertLocked(ctx context.Context, rs ...roachpb.RangeInfo) []*CacheEntry {
1121-
entries := make([]*CacheEntry, len(rs))
1120+
func (rc *RangeCache) insertLocked(ctx context.Context, rs ...roachpb.RangeInfo) []*cacheEntry {
1121+
entries := make([]*cacheEntry, len(rs))
11221122
for i, r := range rs {
1123-
entries[i] = &CacheEntry{
1123+
entries[i] = &cacheEntry{
11241124
desc: r.Desc,
11251125
lease: r.Lease,
11261126
closedts: r.ClosedTimestampPolicy,
@@ -1129,10 +1129,10 @@ func (rc *RangeCache) insertLocked(ctx context.Context, rs ...roachpb.RangeInfo)
11291129
return rc.insertLockedInner(ctx, entries)
11301130
}
11311131

1132-
func (rc *RangeCache) insertLockedInner(ctx context.Context, rs []*CacheEntry) []*CacheEntry {
1132+
func (rc *RangeCache) insertLockedInner(ctx context.Context, rs []*cacheEntry) []*cacheEntry {
11331133
// entries will have the same element as rs, except the ones that couldn't be
11341134
// inserted for which the slots will remain nil.
1135-
entries := make([]*CacheEntry, len(rs))
1135+
entries := make([]*cacheEntry, len(rs))
11361136
for i, ent := range rs {
11371137
if !ent.desc.IsInitialized() {
11381138
log.Fatalf(ctx, "inserting uninitialized desc: %s", ent)
@@ -1170,13 +1170,13 @@ func (rc *RangeCache) insertLockedInner(ctx context.Context, rs []*CacheEntry) [
11701170
return entries
11711171
}
11721172

1173-
func (rc *RangeCache) getValue(entry *cache.Entry) *CacheEntry {
1174-
return entry.Value.(*CacheEntry)
1173+
func (rc *RangeCache) getValue(entry *cache.Entry) *cacheEntry {
1174+
return entry.Value.(*cacheEntry)
11751175
}
11761176

11771177
func (rc *RangeCache) clearOlderOverlapping(
1178-
ctx context.Context, newEntry *CacheEntry,
1179-
) (ok bool, newerEntry *CacheEntry) {
1178+
ctx context.Context, newEntry *cacheEntry,
1179+
) (ok bool, newerEntry *cacheEntry) {
11801180
rc.rangeCache.Lock()
11811181
defer rc.rangeCache.Unlock()
11821182
return rc.clearOlderOverlappingLocked(ctx, newEntry)
@@ -1193,11 +1193,11 @@ func (rc *RangeCache) clearOlderOverlapping(
11931193
// Note that even if false is returned, older descriptors are still cleared from
11941194
// the cache.
11951195
func (rc *RangeCache) clearOlderOverlappingLocked(
1196-
ctx context.Context, newEntry *CacheEntry,
1197-
) (ok bool, newerEntry *CacheEntry) {
1196+
ctx context.Context, newEntry *cacheEntry,
1197+
) (ok bool, newerEntry *cacheEntry) {
11981198
log.VEventf(ctx, 2, "clearing entries overlapping %s", newEntry.Desc())
11991199
newest := true
1200-
var newerFound *CacheEntry
1200+
var newerFound *cacheEntry
12011201
overlapping := rc.getCachedOverlappingRLocked(ctx, newEntry.Desc().RSpan())
12021202
for _, e := range overlapping {
12031203
entry := rc.getValue(e)
@@ -1226,7 +1226,7 @@ func (rc *RangeCache) clearOlderOverlappingLocked(
12261226
// swapEntryLocked swaps oldEntry for newEntry. If newEntry is nil, oldEntry is
12271227
// simply removed.
12281228
func (rc *RangeCache) swapEntryLocked(
1229-
ctx context.Context, oldEntry *cache.Entry, newEntry *CacheEntry,
1229+
ctx context.Context, oldEntry *cache.Entry, newEntry *cacheEntry,
12301230
) {
12311231
if newEntry != nil {
12321232
old := rc.getValue(oldEntry)
@@ -1243,7 +1243,7 @@ func (rc *RangeCache) swapEntryLocked(
12431243
}
12441244
}
12451245

1246-
func (rc *RangeCache) addEntryLocked(entry *CacheEntry) {
1246+
func (rc *RangeCache) addEntryLocked(entry *cacheEntry) {
12471247
key := newRangeCacheKey(entry.Desc().StartKey)
12481248
rc.rangeCache.cache.Add(key, entry)
12491249
}
@@ -1269,12 +1269,12 @@ func (rc *RangeCache) NumInFlight(name string) int {
12691269
return rc.lookupRequests.NumCalls(name)
12701270
}
12711271

1272-
// CacheEntry represents one cache entry.
1272+
// cacheEntry represents one cache entry.
12731273
//
1274-
// The cache stores *CacheEntry. Entries are immutable: cache lookups
1275-
// returns the same *CacheEntry to multiple queriers for efficiency, but
1274+
// The cache stores *cacheEntry. Entries are immutable: cache lookups
1275+
// returns the same *cacheEntry to multiple queriers for efficiency, but
12761276
// nobody should modify the lookup result.
1277-
type CacheEntry struct {
1277+
type cacheEntry struct {
12781278
// desc is always populated.
12791279
desc roachpb.RangeDescriptor
12801280
// speculativeDesc, if not nil, is the descriptor that should replace desc if
@@ -1300,20 +1300,20 @@ type CacheEntry struct {
13001300
closedts roachpb.RangeClosedTimestampPolicy
13011301
}
13021302

1303-
func (e CacheEntry) String() string {
1303+
func (e cacheEntry) String() string {
13041304
return fmt.Sprintf("desc:%s, lease:%s", e.Desc(), e.lease)
13051305
}
13061306

13071307
// Desc returns the cached descriptor. Note that, besides being possibly stale,
13081308
// this descriptor also might not represent a descriptor that was ever
13091309
// committed. See DescSpeculative().
1310-
func (e *CacheEntry) Desc() *roachpb.RangeDescriptor {
1310+
func (e *cacheEntry) Desc() *roachpb.RangeDescriptor {
13111311
return &e.desc
13121312
}
13131313

13141314
// Leaseholder returns the cached leaseholder replica, if known. Returns nil if
13151315
// the leaseholder is not known.
1316-
func (e *CacheEntry) Leaseholder() *roachpb.ReplicaDescriptor {
1316+
func (e *cacheEntry) Leaseholder() *roachpb.ReplicaDescriptor {
13171317
if e.lease.Empty() {
13181318
return nil
13191319
}
@@ -1323,7 +1323,7 @@ func (e *CacheEntry) Leaseholder() *roachpb.ReplicaDescriptor {
13231323
// Lease returns the cached lease, if known. Returns nil if no lease is known.
13241324
// It's possible for a leaseholder to be known, but not a full lease, in which
13251325
// case Leaseholder() returns non-nil but Lease() returns nil.
1326-
func (e *CacheEntry) Lease() *roachpb.Lease {
1326+
func (e *cacheEntry) Lease() *roachpb.Lease {
13271327
if e.lease.Empty() {
13281328
return nil
13291329
}
@@ -1335,7 +1335,7 @@ func (e *CacheEntry) Lease() *roachpb.Lease {
13351335

13361336
// ClosedTimestampPolicy returns the cached understanding of the range's closed
13371337
// timestamp policy. If no policy is known, LAG_BY_CLUSTER_SETTING is returned.
1338-
func (e *CacheEntry) ClosedTimestampPolicy() roachpb.RangeClosedTimestampPolicy {
1338+
func (e *cacheEntry) ClosedTimestampPolicy() roachpb.RangeClosedTimestampPolicy {
13391339
return e.closedts
13401340
}
13411341

@@ -1344,21 +1344,21 @@ func (e *CacheEntry) ClosedTimestampPolicy() roachpb.RangeClosedTimestampPolicy
13441344
// inserted in the cache with Generation=0.
13451345
//
13461346
// Speculative descriptors come from (not-yet-committed) intents.
1347-
func (e *CacheEntry) DescSpeculative() bool {
1347+
func (e *cacheEntry) DescSpeculative() bool {
13481348
return e.desc.Generation == 0
13491349
}
13501350

13511351
// LeaseSpeculative returns true if the lease in the entry is "speculative"
13521352
// - i.e. it doesn't correspond to a committed lease. Such leases have been
13531353
// inserted in the cache with Sequence=0.
1354-
func (e *CacheEntry) LeaseSpeculative() bool {
1354+
func (e *cacheEntry) LeaseSpeculative() bool {
13551355
if e.lease.Empty() {
13561356
panic(fmt.Sprintf("LeaseSpeculative called on entry with empty lease: %s", e))
13571357
}
13581358
return e.lease.Speculative()
13591359
}
13601360

1361-
func (e *CacheEntry) toRangeInfo() roachpb.RangeInfo {
1361+
func (e *cacheEntry) toRangeInfo() roachpb.RangeInfo {
13621362
return roachpb.RangeInfo{
13631363
Desc: e.desc,
13641364
Lease: e.lease,
@@ -1379,7 +1379,7 @@ func (e *CacheEntry) toRangeInfo() roachpb.RangeInfo {
13791379
// can't be determined what information is newer is when at least one of the
13801380
// descriptors is "speculative" (generation=0), or when the lease information is
13811381
// "speculative" (sequence=0).
1382-
func (e *CacheEntry) overrides(o *CacheEntry) bool {
1382+
func (e *cacheEntry) overrides(o *cacheEntry) bool {
13831383
if util.RaceEnabled {
13841384
if _, err := e.Desc().RSpan().Intersect(o.Desc().RSpan()); err != nil {
13851385
panic(fmt.Sprintf("descriptors don't intersect: %s vs %s", e.Desc(), o.Desc()))
@@ -1419,7 +1419,7 @@ func (e *CacheEntry) overrides(o *CacheEntry) bool {
14191419
//
14201420
// In case at least one of the descriptors is "speculative", a is considered
14211421
// older; this matches the semantics of b.overrides(a).
1422-
func compareEntryDescs(a, b *CacheEntry) int {
1422+
func compareEntryDescs(a, b *cacheEntry) int {
14231423
if util.RaceEnabled {
14241424
if _, err := a.Desc().RSpan().Intersect(b.Desc().RSpan()); err != nil {
14251425
panic(fmt.Sprintf("descriptors don't intersect: %s vs %s", a.Desc(), b.Desc()))
@@ -1450,7 +1450,7 @@ func compareEntryDescs(a, b *CacheEntry) int {
14501450
// An empty lease is considered older than any other. In case at least one of
14511451
// the leases is "speculative", a is considered older; this matches the
14521452
// semantics of b.overrides(a).
1453-
func compareEntryLeases(a, b *CacheEntry) int {
1453+
func compareEntryLeases(a, b *cacheEntry) int {
14541454
if aEmpty, bEmpty := a.lease.Empty(), b.lease.Empty(); aEmpty || bEmpty {
14551455
if aEmpty && !bEmpty {
14561456
return -1
@@ -1476,7 +1476,7 @@ func compareEntryLeases(a, b *CacheEntry) int {
14761476
return 0
14771477
}
14781478

1479-
// maybeUpdate returns a new CacheEntry which contains the freshest lease/range
1479+
// maybeUpdate returns a new cacheEntry which contains the freshest lease/range
14801480
// descriptor by comparing the receiver's fields to the passed-in parameters.
14811481
//
14821482
// The updated retval indicates if either the passed-in lease or the range
@@ -1499,15 +1499,15 @@ func compareEntryLeases(a, b *CacheEntry) int {
14991499
//
15001500
// It's expected that the supplied rangeDesc is compatible with the descriptor
15011501
// on the cache entry.
1502-
func (e *CacheEntry) maybeUpdate(
1502+
func (e *cacheEntry) maybeUpdate(
15031503
ctx context.Context, l *roachpb.Lease, rangeDesc *roachpb.RangeDescriptor,
1504-
) (updated, updatedLease bool, newEntry *CacheEntry) {
1504+
) (updated, updatedLease bool, newEntry *cacheEntry) {
15051505
if !descsCompatible(e.Desc(), rangeDesc) {
15061506
log.Fatalf(ctx, "attempting to update by comparing non-compatible descs: %s vs %s",
15071507
e.Desc(), rangeDesc)
15081508
}
15091509

1510-
newEntry = &CacheEntry{
1510+
newEntry = &cacheEntry{
15111511
lease: e.lease,
15121512
desc: e.desc,
15131513
closedts: e.closedts,
@@ -1571,13 +1571,13 @@ func (e *CacheEntry) maybeUpdate(
15711571
return updatedLease || updatedDesc, updatedLease, newEntry
15721572
}
15731573

1574-
func (e *CacheEntry) evictLeaseholder(
1574+
func (e *cacheEntry) evictLeaseholder(
15751575
lh roachpb.ReplicaDescriptor,
1576-
) (updated bool, newEntry *CacheEntry) {
1576+
) (updated bool, newEntry *cacheEntry) {
15771577
if e.lease.Replica != lh {
15781578
return false, e
15791579
}
1580-
return true, &CacheEntry{
1580+
return true, &cacheEntry{
15811581
desc: e.desc,
15821582
closedts: e.closedts,
15831583
}

0 commit comments

Comments
 (0)