Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dekaf: Swap to lz4_flex from lz4 #1653

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 7 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ flate2 = "1.0"
futures = "0.3"
futures-core = "0.3"
futures-util = "0.3"
fxhash = "0.2" # Used in `json` crate. Replace with xxhash.
fxhash = "0.2" # Used in `json` crate. Replace with xxhash.
hex = "0.4.3"
hexdump = "0.1"
humantime = "2.1"
Expand All @@ -72,14 +72,17 @@ jemalloc-ctl = "0.3"
json-patch = "0.3"
jsonwebtoken = { version = "9", default-features = false }
js-sys = "0.3.60"
kafka-protocol = "0.11.0"
# TODO(jshearer): Swap back after 0.13.0 is released, which includes
# https://github.com/tychedelia/kafka-protocol-rs/pull/81
kafka-protocol = { git = "https://github.com/tychedelia/kafka-protocol-rs.git", rev = "cabe835" }
lazy_static = "1.4"
libc = "0.2"
librocksdb-sys = { version = "0.16.0", default-features = false, features = [
"snappy",
"rtti",
] }
lz4 = "1.24.0"
lz4_flex = "0.11.0"
mime = "0.3"
memchr = "2.5"
metrics = "0.23.0"
Expand Down
1 change: 1 addition & 0 deletions crates/dekaf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ hex = { workspace = true }
hexdump = { workspace = true }
itertools = { workspace = true }
kafka-protocol = { workspace = true }
lz4_flex = { workspace = true }
md5 = { workspace = true }
metrics = { workspace = true }
metrics-prometheus = { workspace = true }
Expand Down
31 changes: 29 additions & 2 deletions crates/dekaf/src/read.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use super::{Collection, Partition};
use anyhow::bail;
use bytes::BufMut;
use bytes::{Buf, BufMut, BytesMut};
use doc::AsNode;
use futures::StreamExt;
use gazette::journal::{ReadJsonLine, ReadJsonLines};
use gazette::{broker, journal, uuid};
use kafka_protocol::records::Compression;
use lz4_flex::frame::BlockMode;
use std::time::Duration;

pub struct Read {
Expand Down Expand Up @@ -255,7 +257,7 @@ impl Read {
compression: Compression::None,
version: 2,
};
RecordBatchEncoder::encode(&mut buf, records.iter(), &opts)
RecordBatchEncoder::encode(&mut buf, records.iter(), &opts, Some(compressor))
.expect("record encoding cannot fail");

tracing::debug!(
Expand All @@ -276,3 +278,28 @@ impl Read {
Ok((self, buf.freeze()))
}
}

fn compressor<Output: BufMut>(
input: &mut BytesMut,
output: &mut Output,
c: Compression,
) -> anyhow::Result<()> {
match c {
Compression::None => output.put(input),
Compression::Lz4 => {
let mut frame_info = lz4_flex::frame::FrameInfo::default();
// This breaks Go lz4 decoding
// frame_info.block_checksums = true;
frame_info.block_mode = BlockMode::Independent;

let mut encoder =
lz4_flex::frame::FrameEncoder::with_frame_info(frame_info, output.writer());

std::io::copy(&mut input.reader(), &mut encoder)?;

encoder.finish()?;
}
unsupported @ _ => bail!("Unsupported compression type {unsupported:?}"),
};
Ok(())
}
Loading