-
Notifications
You must be signed in to change notification settings - Fork 14.7k
KAFKA-12999: Make RecordHeader reads thread-safe #20751
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
base: trunk
Are you sure you want to change the base?
KAFKA-12999: Make RecordHeader reads thread-safe #20751
Conversation
clients/src/test/java/org/apache/kafka/common/header/internals/RecordHeadersTest.java
Outdated
Show resolved
Hide resolved
|
@mingyen066 please update the |
clients/src/test/java/org/apache/kafka/common/header/internals/RecordHeadersTest.java
Outdated
Show resolved
Hide resolved
| ByteBuffer.wrap("value".getBytes(StandardCharsets.UTF_8)) | ||
| ); | ||
|
|
||
| ExecutorService pool = Executors.newFixedThreadPool(threads); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could leverage CompletableFuture
CountDownLatch startLatch = new CountDownLatch(1);
var fs = IntStream.range(0, threads).mapToObj(__ -> CompletableFuture.supplyAsync(() -> {
try {
startLatch.await();
header.key();
header.value();
return null;
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
})).collect(Collectors.toUnmodifiableList());
startLatch.countDown();
fs.forEach(CompletableFuture::join);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more thing: could you please add similar unit test for null value?
This patch implements
KIP-1205
to address concurrency issues (NPE) related to the lazy initialization
of
RecordHeaderfields.The added test verified that concurrent access to
RecordHeader.key()and
RecordHeader.value()no longer throwsNullPointerException