niket-goel commented on a change in pull request #10899: URL: https://github.com/apache/kafka/pull/10899#discussion_r655512248
########## File path: raft/src/main/java/org/apache/kafka/raft/internals/BatchAccumulator.java ########## @@ -233,6 +235,68 @@ public void appendLeaderChangeMessage(LeaderChangeMessage leaderChangeMessage, l } } + + public void appendSnapshotHeaderMessage(MetadataSnapshotHeaderRecord snapshotHeaderRecord) { + appendLock.lock(); + try { + // Ideally there should be nothing in the batch here. + // TODO verify this + long currentTimeMs = time.milliseconds(); + ByteBuffer buffer = memoryPool.tryAllocate(256); + if (buffer != null) { + MemoryRecords data = MemoryRecords.withSnapshotHeaderRecord( + this.nextOffset, + currentTimeMs, + this.epoch, + buffer, + snapshotHeaderRecord + ); + completed.add(new CompletedBatch<>( + nextOffset, + 1, + data, + memoryPool, + buffer + )); + nextOffset += 1; + } else { + throw new IllegalStateException("Could not allocate buffer for the metadata snapshot header record."); + } + } finally { + appendLock.unlock(); + } + } + + public void appendSnapshotFooterMessage(MetadataSnapshotFooterRecord snapshotFooterRecord) { + appendLock.lock(); + try { + forceDrain(); + long currentTimeMs = time.milliseconds(); + ByteBuffer buffer = memoryPool.tryAllocate(256); + if (buffer != null) { + MemoryRecords data = MemoryRecords.withSnapshotFooterRecord( + this.nextOffset, + currentTimeMs, + this.epoch, + buffer, + snapshotFooterRecord + ); + completed.add(new CompletedBatch<>( + nextOffset, + 1, + data, + memoryPool, + buffer + )); + nextOffset += 1; + } else { + throw new IllegalStateException("Could not allocate buffer for the metadata snapshot footer record."); + } + } finally { + appendLock.unlock(); + } + } Review comment: I agree. Let me fix that. -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org