Skip to content

Commit

Permalink
Preemptively close chunks before big messages to isolate them
Browse files Browse the repository at this point in the history
  • Loading branch information
mikael-s-persson committed Dec 12, 2024
1 parent 5db8c69 commit 9c256c8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cpp/mcap/include/mcap/writer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ Status McapWriter::write(const Message& message) {
++statistics_.channelCount;
}

// Before writing a large message (bigger than chunk size), close current chunk.
auto* chunkWriter = getChunkWriter();
if (chunkWriter != nullptr && /* Chunked? */
uncompressedSize_ != 0 && /* Current chunk is not empty/new? */
message.dataSize >= chunkSize_ /* Big message? */ ) {
auto& fileOutput = *output_;
writeChunk(fileOutput, *chunkWriter);
}

// For the chunk-local message index.
const uint64_t messageOffset = uncompressedSize_;

// Write the message
Expand All @@ -565,8 +575,7 @@ Status McapWriter::write(const Message& message) {
channelMessageCounts[message.channelId] += 1;
}

auto* chunkWriter = getChunkWriter();
if (chunkWriter) {
if (chunkWriter != nullptr) {
if (!options_.noMessageIndex) {
// Update the message index
auto& messageIndex = currentMessageIndex_[message.channelId];
Expand Down

0 comments on commit 9c256c8

Please sign in to comment.