Skip to content

Commit

Permalink
Merge pull request cockroachdb#113760 from cockroachdb/blathers/backp…
Browse files Browse the repository at this point in the history
…ort-release-23.2-113742
  • Loading branch information
pav-kv authored Nov 6, 2023
2 parents 4bafb13 + 448a3ee commit 1b2091f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions pkg/kv/kvserver/logstore/logstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,13 @@ var nonBlockingSyncWaiterCallbackPool = sync.Pool{
New: func() interface{} { return new(nonBlockingSyncWaiterCallback) },
}

var valPool = sync.Pool{
New: func() interface{} { return &roachpb.Value{} },
var logAppendPool = sync.Pool{
New: func() interface{} {
return new(struct {
roachpb.Value
enginepb.MVCCStats
})
},
}

// logAppend adds the given entries to the raft log. Takes the previous log
Expand All @@ -382,13 +387,21 @@ func logAppend(
if len(entries) == 0 {
return prev, nil
}
var diff enginepb.MVCCStats
opts := storage.MVCCWriteOptions{
Stats: &diff,
}
value := valPool.Get().(*roachpb.Value)

// NB: the Value and MVCCStats lifetime is this function, so we coalesce their
// allocation into the same pool.
// TODO(pavelkalinnikov): figure out why they escape into the heap, and find a
// way to avoid the pool.
v := logAppendPool.Get().(*struct {
roachpb.Value
enginepb.MVCCStats
})
defer logAppendPool.Put(v)
value, diff := &v.Value, &v.MVCCStats
value.RawBytes = value.RawBytes[:0]
defer valPool.Put(value)
diff.Reset()

opts := storage.MVCCWriteOptions{Stats: diff}
for i := range entries {
ent := &entries[i]
key := keys.RaftLogKeyFromPrefix(raftLogPrefix, kvpb.RaftIndex(ent.Index))
Expand Down

0 comments on commit 1b2091f

Please sign in to comment.