xiangfu0 commented on code in PR #20263:
URL: https://github.com/apache/pinot/pull/20263#discussion_r4729487602
##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/memory/PinotDataBuffer.java:
##########
@@ -318,6 +318,40 @@ public static List<String> getBufferInfo() {
return bufferInfo;
}
+ /// Flushes each buffer's dirty pages to durable storage before closing it.
Without this, a write can sit
+ /// unconfirmed in the page cache, and a fault before the OS's own lazy
writeback runs can leave bad bytes on
+ /// disk with no error. Every buffer is attempted even if an earlier one
fails to flush or close. A buffer
+ /// always attempts release after a flush failure, and later buffers are
still attempted.
+ ///
+ /// @param buffers one or more writable buffers to flush and close
+ /// @throws IOException the first exception encountered while flushing or
closing, with the rest suppressed
+ public static void flushAndClose(PinotDataBuffer... buffers)
Review Comment:
Small naming point, since this is a new public method on an SPI class. It
doesn't flush anything itself: it calls `close()` on each buffer and aggregates
the failures, and `close()` already flushed before this PR. Something like
`closeAll`, with a Javadoc that says exactly that, would be less surprising
than a name and description that promise a flush of writable buffers.
Related: `FilePerIndexDirectory.close()` still has the plain loop that
`SingleFileIndexDirectory.close()` had. Now that a failed flush throws, it
stops at the first bad buffer and leaves the rest mapped, so it could use this
helper too.
##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/io/writer/impl/BaseChunkForwardIndexWriter.java:
##########
@@ -98,16 +99,20 @@ protected BaseChunkForwardIndexWriter(File file,
ChunkCompressionType compressio
public void close()
throws IOException {
- // Write the chunk if it is non-empty.
- if (_chunkBuffer.position() > 0) {
- writeChunk();
+ try {
+ // Write the chunk if it is non-empty.
+ if (_chunkBuffer.position() > 0) {
+ writeChunk();
+ }
+
+ // Write the header and make the file durable. Only sync on success; a
failed write is not worth syncing.
+ _header.flip();
+ _dataFile.write(_header, 0);
+ _dataFile.force(true);
Review Comment:
On Option B, I'd lean towards option 2. This fsync, and the equivalent ones
in the other writers, runs for every caller of the segment creation driver with
no way to turn it off, and for most of them it doesn't make anything that
survives more durable.
With the default v3 format, `SegmentV1V2ToV3FormatConverter` copies this
file into `columns.psf` and `deleteV2Files` removes it right after, which
matches your strace finding that every new fsync landed on a tmp file. Index
builds during reload go the same way: `LoaderUtils.writeIndexToV3Format` copies
the file into the segment and deletes it. Minion tasks,
`SegmentProcessorFramework` and the batch ingestion runners also use these
writers and then tar and upload the output, so their local copy never needs to
survive a crash.
The case where the per-writer sync does protect persisted bytes is a v1
segment, where these files are the final artifact. So I'd pass a flag down from
the creator (for example through `IndexCreationContext`) saying whether the
output is final, sync here only when it is, and do one sync of the final v3
files and directory at the end of the build. That keeps a 2 GB segment from
paying 5+ seconds on the realtime commit path for files that are about to be
deleted, and it closes the `index_map` / `metadata.properties` gap you called
out. The per-resize msync in `BitmapInvertedIndexWriter` could follow the same
flag.
On the stale-read case you raised (writeback fails and the pages are evicted
before the v3 copy reads them): it's real, but the window is the few seconds
between the writer closing and the copy, and I don't think it justifies paying
the sync on every build.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]