You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/04/02 02:01:47 UTC
[GitHub] [pulsar] mattisonchao commented on a change in pull request #14992: [improve][transaction] Use ``Caffeine`` to instead of ``Guava`` cache
mattisonchao commented on a change in pull request #14992:
URL: https://github.com/apache/pulsar/pull/14992#discussion_r840991840
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TransactionBufferHandlerImpl.java
##########
@@ -150,34 +134,30 @@ private boolean checkRequestCredits(OpRequestSend op) {
}
public void endTxn(OpRequestSend op) {
- op.cnx.whenComplete((clientCnx, throwable) -> {
- if (throwable == null) {
- if (clientCnx.ctx().channel().isActive()) {
- clientCnx.registerTransactionBufferHandler(TransactionBufferHandlerImpl.this);
- outstandingRequests.put(op.requestId, op);
- timer.newTimeout(timeout -> {
- OpRequestSend peek = outstandingRequests.remove(op.requestId);
- if (peek != null && !peek.cb.isDone() && !peek.cb.isCompletedExceptionally()) {
- peek.cb.completeExceptionally(new TransactionBufferClientException
- .RequestTimeoutException());
- onResponse(peek);
- }
- }, operationTimeoutInMills, TimeUnit.MILLISECONDS);
- op.cmd.retain();
- clientCnx.ctx().writeAndFlush(op.cmd, clientCnx.ctx().voidPromise());
- } else {
- invalidateLookupCache(op);
- op.cb.completeExceptionally(
- new PulsarClientException.LookupException(op.topic + " endTxn channel is not active"));
- onResponse(op);
- }
- } else {
- log.error("endTxn error topic: [{}]", op.topic, throwable);
- invalidateLookupCache(op);
- op.cb.completeExceptionally(
- new PulsarClientException.LookupException(throwable.getMessage()));
- onResponse(op);
+ op.cnx.thenAccept(clientCnx -> {
Review comment:
This change can reduce duplicated code.
```java
else {
invalidateLookupCache(op);
op.cb.completeExceptionally(
new PulsarClientException.LookupException(op.topic + " endTxn channel is not active"));
onResponse(op);
}
}
```
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TransactionBufferHandlerImpl.java
##########
@@ -288,12 +260,16 @@ private void checkPendingRequests() {
}
private void invalidateLookupCache(OpRequestSend op) {
+ if (lookupCache.get(op.topic) == op.cnx) {
+ safeInvalidateCache(op.topic);
+ }
+ }
+
+ private void safeInvalidateCache(String topicName) {
try {
- if (lookupCache.get(op.topic) == op.cnx) {
- lookupCache.invalidate(op.topic);
- }
- } catch (ExecutionException e) {
- lookupCache.invalidate(op.topic);
+ lookupCache.synchronous().invalidate(topicName);
+ } catch (NullPointerException ignore) {
+ // no-op
Review comment:
ah... It's a mistake, fixed.
thanks for your review.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org