Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: defer putBuffer release in all cases #109087

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions pkg/storage/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,7 @@ func MVCCMerge(
metaKey := MakeMVCCMetadataKey(key)

buf := newPutBuffer()
defer buf.release()

// Every type flows through here, so we can't use the typed getters.
rawBytes := value.RawBytes
Expand All @@ -2566,7 +2567,6 @@ func MVCCMerge(
key, int64(len(rawBytes)), timestamp.WallTime))
}
}
buf.release()
return err
}

Expand Down Expand Up @@ -4342,6 +4342,7 @@ func MVCCResolveWriteIntent(
return false, 0, nil, err
}
iterAndBuf := GetBufUsingIter(iter)
defer iterAndBuf.Cleanup()
iterAndBuf.iter.SeekIntentGE(intent.Key, intent.Txn.ID)
// Production code will use a buffered writer, which makes the numBytes
// calculation accurate. Note that an inaccurate numBytes (e.g. 0 in the
Expand All @@ -4350,8 +4351,6 @@ func MVCCResolveWriteIntent(
beforeBytes := rw.BufferedSize()
ok, err = mvccResolveWriteIntent(ctx, rw, iterAndBuf.iter, ms, intent, iterAndBuf.buf)
numBytes = int64(rw.BufferedSize() - beforeBytes)
// Using defer would be more convenient, but it is measurably slower.
iterAndBuf.Cleanup()
return ok, numBytes, nil, err
}

Expand Down Expand Up @@ -5164,6 +5163,7 @@ func MVCCResolveWriteIntentRange(
if err != nil {
return 0, 0, nil, 0, err
}
defer engineIter.Close()
var mvccIter MVCCIterator
iterOpts := IterOptions{
KeyTypes: IterKeyTypePointsAndRanges,
Expand All @@ -5181,10 +5181,7 @@ func MVCCResolveWriteIntentRange(
mvccIter = newPebbleIteratorByCloning(engineIter.CloneContext(), iterOpts, StandardDurability)
}
iterAndBuf := GetBufUsingIter(mvccIter)
defer func() {
engineIter.Close()
iterAndBuf.Cleanup()
}()
defer iterAndBuf.Cleanup()
putBuf := iterAndBuf.buf
sepIter := &separatedIntentAndVersionIter{
engineIter: engineIter,
Expand Down