Skip to content

Commit 7d67000

Browse files
committed
logstore: rm MaybeInlineSideloadedRaftCommand alloc
Epic: none Release note: none
1 parent 0e5ba7d commit 7d67000

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

pkg/kv/kvserver/logstore/logstore.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -740,20 +740,14 @@ func LoadEntries(
740740
}
741741
expectedIndex++
742742

743-
typ, _, err := raftlog.EncodingOf(ent)
744-
if err != nil {
743+
if typ, _, err := raftlog.EncodingOf(ent); err != nil {
745744
return err
746-
}
747-
if typ.IsSideloaded() {
748-
newEnt, err := MaybeInlineSideloadedRaftCommand(
745+
} else if typ.IsSideloaded() {
746+
if ent, err = MaybeInlineSideloadedRaftCommand(
749747
ctx, rangeID, ent, sideloaded, eCache,
750-
)
751-
if err != nil {
748+
); err != nil {
752749
return err
753750
}
754-
if newEnt != nil {
755-
ent = *newEnt
756-
}
757751
}
758752

759753
if sh.add(uint64(ent.Size())) {

pkg/kv/kvserver/logstore/sideload.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ func MaybeSideloadEntries(
149149

150150
// MaybeInlineSideloadedRaftCommand takes an entry and inspects it. If its
151151
// command encoding version indicates a sideloaded entry, it uses the entryCache
152-
// or SideloadStorage to inline the payload, returning a new entry (which must
153-
// be treated as immutable by the caller) or nil (if inlining does not apply)
152+
// or SideloadStorage to inline the payload, and returns a new entry (which must
153+
// be treated as immutable by the caller).
154154
//
155155
// If a payload is missing, returns an error whose Cause() is
156156
// errSideloadedFileNotFound.
@@ -160,31 +160,24 @@ func MaybeInlineSideloadedRaftCommand(
160160
ent raftpb.Entry,
161161
sideloaded SideloadStorage,
162162
entryCache *raftentry.Cache,
163-
) (*raftpb.Entry, error) {
163+
) (raftpb.Entry, error) {
164164
typ, pri, err := raftlog.EncodingOf(ent)
165-
if err != nil {
166-
return nil, err
167-
}
168-
if !typ.IsSideloaded() {
169-
return nil, nil
165+
if err != nil || !typ.IsSideloaded() {
166+
return ent, err
170167
}
171168
log.Event(ctx, "inlining sideloaded SSTable")
172169
// We could unmarshal this yet again, but if it's committed we are very likely
173170
// to have appended it recently, in which case we can save work.
174171
if entry, hit := entryCache.Get(rangeID, kvpb.RaftIndex(ent.Index)); hit {
175172
log.Event(ctx, "using cache hit")
176-
return &entry, nil
173+
return entry, nil
177174
}
178175

179-
// Make a shallow copy.
180-
entCpy := ent
181-
ent = entCpy
182-
183176
log.Event(ctx, "inlined entry not cached")
184177
// (Bad) luck, for whatever reason the inlined proposal isn't in the cache.
185178
e, err := raftlog.NewEntry(ent)
186179
if err != nil {
187-
return nil, err
180+
return ent, err
188181
}
189182

190183
if len(e.Cmd.ReplicatedEvalResult.AddSSTable.Data) > 0 {
@@ -196,12 +189,12 @@ func MaybeInlineSideloadedRaftCommand(
196189
// be as a result of log entries that are very old, written
197190
// when sending the log with snapshots was still possible).
198191
log.Event(ctx, "entry already inlined")
199-
return &ent, nil
192+
return ent, nil
200193
}
201194

202195
sideloadedData, err := sideloaded.Get(ctx, kvpb.RaftIndex(ent.Index), kvpb.RaftTerm(ent.Term))
203196
if err != nil {
204-
return nil, errors.Wrap(err, "loading sideloaded data")
197+
return ent, errors.Wrap(err, "loading sideloaded data")
205198
}
206199
e.Cmd.ReplicatedEvalResult.AddSSTable.Data = sideloadedData
207200
// TODO(tbg): there should be a helper that properly encodes a command, given
@@ -211,11 +204,11 @@ func MaybeInlineSideloadedRaftCommand(
211204
raftlog.EncodeRaftCommandPrefix(data[:raftlog.RaftCommandPrefixLen], typ, e.ID, pri)
212205
_, err := protoutil.MarshalToSizedBuffer(&e.Cmd, data[raftlog.RaftCommandPrefixLen:])
213206
if err != nil {
214-
return nil, err
207+
return ent, err
215208
}
216209
ent.Data = data
217210
}
218-
return &ent, nil
211+
return ent, nil
219212
}
220213

221214
// AssertSideloadedRaftCommandInlined asserts that if the provided entry is a

pkg/kv/kvserver/logstore/sideload_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,7 @@ func TestRaftSSTableSideloadingInline(t *testing.T) {
451451
} else {
452452
mustEntryEq(t, thinCopy, test.thin)
453453
}
454-
455-
if newEnt == nil {
456-
newEnt = &thinCopy
457-
}
458-
mustEntryEq(t, *newEnt, test.fat)
454+
mustEntryEq(t, newEnt, test.fat)
459455

460456
if dump := getRecAndFinish().String(); test.expTrace != "" {
461457
if ok, err := regexp.MatchString(test.expTrace, dump); err != nil {

0 commit comments

Comments
 (0)