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

KAFKA-19090: Move DelayedFuture and DelayedFuturePurgatory to server module #19390

Merged
merged 6 commits into from
Apr 9, 2025

Conversation

FrankYang0529
Copy link
Member

@FrankYang0529 FrankYang0529 commented Apr 6, 2025

Rewrite these classes in Java and move them to the server module

Reviewers: Mickael Maison mickael.maison@gmail.com

…module

Signed-off-by: PoAn Yang <payang@apache.org>
@github-actions github-actions bot added the core Kafka Broker label Apr 6, 2025
@FrankYang0529 FrankYang0529 requested a review from chia7712 April 6, 2025 13:30
@FrankYang0529
Copy link
Member Author

FrankYang0529 commented Apr 6, 2025

Failed test OffloadAndTxnConsumeFromLeaderTest#executeTieredStorageTest in CI is not related to this PR.

https://issues.apache.org/jira/browse/KAFKA-17998

@mimaison
Copy link
Member

mimaison commented Apr 7, 2025

Should these classes go to the server module instead? They only seem to be used by AclApis.

Copy link
Member

@mimaison mimaison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I left a few suggestions.

import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertThrows, assertTrue}
import org.junit.jupiter.api.Test

import java.util.concurrent.{CompletableFuture, ExecutionException}
import java.util.concurrent.atomic.AtomicInteger
import scala.jdk.CollectionConverters.CollectionHasAsScala
import scala.jdk.CollectionConverters._
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the explicit import?

@@ -16,22 +16,22 @@
*/
package integration.kafka.server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also convert and move this file to server

*/
@Override
public void onComplete() {
List<CompletableFuture<T>> pendingFutures = futures.stream().filter(future -> !future.isDone()).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use toList() instead of collect(Collectors.toList())

log.trace("All futures have been completed or have errors, completing the delayed operation");
return forceComplete();
} else {
log.trace(pending + " future still pending, not completing the delayed operation");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use templating {} instead of concatenation in Logger methods.

0,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(),
new ThreadFactory() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a lambda to make the anonymous class a bit less verbose

return new KafkaThread("DelayedExecutor-" + purgatoryName, r, true);
}
});
this.purgatoryKey = new DelayedOperationKey() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

DelayedFuture<T> delayedFuture = new DelayedFuture<>(timeoutMs, futures, responseCallback);
boolean done = purgatory.tryCompleteElseWatch(delayedFuture, List.of(purgatoryKey));
if (!done) {
BiConsumer<Void, Throwable> callbackAction = new BiConsumer<>() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Signed-off-by: PoAn Yang <payang@apache.org>
Signed-off-by: PoAn Yang <payang@apache.org>
@FrankYang0529
Copy link
Member Author

@mimaison Thanks for the review. I address all comments.

@FrankYang0529 FrankYang0529 requested a review from mimaison April 9, 2025 02:03
Copy link
Member

@mimaison mimaison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mimaison mimaison changed the title KAFKA-19090: Move DelayedFuture and DelayedFuturePurgatory to server-common module KAFKA-19090: Move DelayedFuture and DelayedFuturePurgatory to server module Apr 9, 2025
@mimaison mimaison merged commit 56591d2 into apache:trunk Apr 9, 2025
25 checks passed
@FrankYang0529 FrankYang0529 deleted the KAFKA-19090 branch April 9, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Kafka Broker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants