Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! refactor(storage): Pipeline gRPC writes.
  • Loading branch information
cjc25 committed Jul 9, 2025
commit 3e467598fb298ff0f0a4f1bbc00c67fd0b3f7511
13 changes: 9 additions & 4 deletions storage/grpc_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ func (w *gRPCWriter) writeLoop(ctx context.Context) error {
return w.streamSender.err()
}
w.bufUnsentIdx = int(sentOffset - w.bufBaseOffset)
// We may have observed a completion that is after all of w.buf if we also
// have a write command in w.currentCommand which sent a flush, but failed
// before the completion could be delivered.
if w.bufUnsentIdx < 0 {
w.bufUnsentIdx = 0
}
return nil
}); err != nil {
return err
Expand Down Expand Up @@ -459,7 +465,6 @@ func (w *gRPCWriter) writeLoop(ctx context.Context) error {
flush: true,
finishWrite: true,
}
w.bufUnsentIdx = len(w.buf)
if err := w.withCommandRetryDeadline(func() error {
if !chcs.deliverRequestUnlessCompleted(req, w.handleCompletion) {
return w.streamSender.err()
Expand Down Expand Up @@ -591,7 +596,6 @@ func (c *gRPCWriterCommandWrite) handle(w *gRPCWriter, cs gRPCWriterCommandHandl
if !ok {
return false
}
w.bufUnsentIdx = int(sentOffset - w.bufBaseOffset)

// ...then send the prefix of c.p which could fill w.buf
cmdBaseOffset := w.bufBaseOffset + int64(len(w.buf))
Expand Down Expand Up @@ -638,7 +642,7 @@ func (c *gRPCWriterCommandWrite) handle(w *gRPCWriter, cs gRPCWriterCommandHandl
return false
}
// Finally, we need the sender to ack to let us know c.p can be released.
if !cs.deliverRequestUnlessCompleted(gRPCBidiWriteRequest{requestAck: true}, w.handleCompletion) {
if !cs.deliverRequestUnlessCompleted(gRPCBidiWriteRequest{requestAck: true}, trimCommandBuf) {
return false
}
ackOutstanding := true
Expand All @@ -656,7 +660,7 @@ func (c *gRPCWriterCommandWrite) handle(w *gRPCWriter, cs gRPCWriterCommandHandl
toCopyIn := cmdBuf[int(w.bufBaseOffset-offset):]
w.buf = w.buf[:len(toCopyIn)]
copy(w.buf, toCopyIn)
w.bufUnsentIdx = int(sentOffset - offset)
w.bufUnsentIdx = int(sentOffset - w.bufBaseOffset)
close(c.done)
return true
}
Expand Down Expand Up @@ -688,6 +692,7 @@ func (c *gRPCWriterCommandFlush) handle(w *gRPCWriter, cs gRPCWriterCommandHandl
}
w.handleCompletion(c)
}
// handleCompletion has cleared w.buf and updated w.bufUnsentIdx by now.
c.done <- flushTarget
return true
}
Expand Down
⌂ 换网址