BewareMyPower commented on code in PR #23786:
URL: https://github.com/apache/pulsar/pull/23786#discussion_r1897927614
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java:
##########
@@ -267,37 +268,38 @@ public CompletableFuture<Optional<TopicPolicies>>
getTopicPoliciesAsync(TopicNam
return CompletableFuture.completedFuture(Optional.empty());
}
final CompletableFuture<Boolean> preparedFuture =
prepareInitPoliciesCacheAsync(topicName.getNamespaceObject());
- final var resultFuture = new
CompletableFuture<Optional<TopicPolicies>>();
- preparedFuture.thenAccept(inserted ->
policyCacheInitMap.compute(namespace, (___, existingFuture) -> {
- if (!inserted || existingFuture != null) {
- final var partitionedTopicName =
TopicName.get(topicName.getPartitionedTopicName());
- final var policies = Optional.ofNullable(switch (type) {
- case DEFAULT ->
Optional.ofNullable(policiesCache.get(partitionedTopicName))
- .orElseGet(() ->
globalPoliciesCache.get(partitionedTopicName));
- case GLOBAL_ONLY ->
globalPoliciesCache.get(partitionedTopicName);
- case LOCAL_ONLY -> policiesCache.get(partitionedTopicName);
- });
- resultFuture.complete(policies);
- } else {
- CompletableFuture.runAsync(() -> {
- log.info("The future of {} has been removed from cache,
retry getTopicPolicies again", namespace);
- // Call it in another thread to avoid recursive update
because getTopicPoliciesAsync() could call
- // policyCacheInitMap.computeIfAbsent()
- getTopicPoliciesAsync(topicName,
type).whenComplete((result, e) -> {
- if (e == null) {
- resultFuture.complete(result);
- } else {
- resultFuture.completeExceptionally(e);
- }
- });
- });
+ // switch thread to avoid potential metadata thread cost and recursive
deadlock
+ return preparedFuture.thenComposeAsync(inserted -> {
+ @Data
+ class PoliciesFutureHolder {
Review Comment:
You can use `Mutable<T>` instead.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]