Skip to content

Commit 9ddf582

Browse files
craig[bot]jbowens
andcommitted
Merge #149796
149796: storage: avoid value retrieval of sys keys during ComputeStats r=sumeerbhola a=jbowens With the introduction of value separation (and especiallly with #149712) raft log values may be separated into blob files to reduce write amplification. This makes value retrieval more expensive, potentially requiring multiple additional read I/Os. When evaluating a raft log truncation, we use ComputeStats to compute an MVCCStats delta for the truncation. Previously during this ComputeStats call, we'd unnecessarily retrieve and unmarshal the values of the raft log keys. This commit refactors this to move the value retrieval and unmarshal to only where it's required. Informs #149712. Epic: none Release note: none Co-authored-by: Jackson Owens <[email protected]>
2 parents bfb43f5 + 06547c1 commit 9ddf582

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

pkg/storage/mvcc.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7306,6 +7306,18 @@ func computeStatsForIterWithVisitors(
73067306
rangeKeyVisitor func(MVCCRangeKeyValue) error,
73077307
) (enginepb.MVCCStats, error) {
73087308
var ms enginepb.MVCCStats
7309+
// meta is used to store the MVCCMetadata for the current key but is only
7310+
// reset and initialized for a subset of keys. Specifically, meta gets
7311+
// initialized below when:
7312+
//
7313+
// implicitMeta=true [isValue=true && key != prevKey]: When we encounter a
7314+
// key that a) has a non-empty timestamp and b) is a new user key, its
7315+
// MVCCMetadata is implicit. The loop below will reset meta and synthesize
7316+
// its fields.
7317+
//
7318+
// isValue=false && !isSys: When we encounter a key that has a zero
7319+
// timestamp and it's not a system key, we read and unmarshal the value into
7320+
// the MVCCMetadata struct.
73097321
var meta enginepb.MVCCMetadata
73107322
var prevKey roachpb.Key
73117323
var first bool
@@ -7461,23 +7473,23 @@ func computeStatsForIterWithVisitors(
74617473
totalBytes := metaKeySize + metaValSize
74627474
first = true
74637475

7464-
if !implicitMeta {
7465-
v, err := iter.UnsafeValue()
7466-
if err != nil {
7467-
return enginepb.MVCCStats{}, err
7468-
}
7469-
if err := protoutil.Unmarshal(v, &meta); err != nil {
7470-
return ms, errors.Wrap(err, "unable to decode MVCCMetadata")
7471-
}
7472-
}
7473-
74747476
if isSys {
74757477
ms.SysBytes += totalBytes
74767478
ms.SysCount++
74777479
if isAbortSpanKey(unsafeKey.Key) {
74787480
ms.AbortSpanBytes += totalBytes
74797481
}
74807482
} else {
7483+
if !implicitMeta {
7484+
v, err := iter.UnsafeValue()
7485+
if err != nil {
7486+
return enginepb.MVCCStats{}, err
7487+
}
7488+
if err := protoutil.Unmarshal(v, &meta); err != nil {
7489+
return ms, errors.Wrap(err, "unable to decode MVCCMetadata")
7490+
}
7491+
}
7492+
74817493
if meta.Deleted {
74827494
// First value is deleted, so it's GC'able; add meta key & value bytes to age stat.
74837495
ms.GCBytesAge += totalBytes * (nowNanos/1e9 - meta.Timestamp.WallTime/1e9)

0 commit comments

Comments
 (0)