Skip to content

[fix][broker] Fix intermittent issue where leader broker information is lost and causes lookup issues - #17254

Closed
lhotari wants to merge 5 commits into
apache:masterfrom
lhotari:lh-fix-leaderbroker-missing-issue
Closed

[fix][broker] Fix intermittent issue where leader broker information is lost and causes lookup issues#17254
lhotari wants to merge 5 commits into
apache:masterfrom
lhotari:lh-fix-leaderbroker-missing-issue

Conversation

@lhotari

@lhotari lhotari commented Aug 24, 2022

Copy link
Copy Markdown
Member

Motivation

  • Fixes issue where leader broker information isn't available and this warning gets logged:
    WARN org.apache.pulsar.broker.namespace.NamespaceService - The information about the current leader broker wasn't available. Handling load manager decisions in a decentralized way.

Modifications

  • use LeaderElectionService's readCurrentLeader method instead of getCurrentLeader method. This ensures that the leader broker information is refreshed if it happens to be missing.
  • refactor existing code so that the asynchronous readCurrentLeader method can be used.

@lhotari lhotari added type/bug The PR fixed a bug or issue reported a bug area/broker doc-not-needed Your PR changes do not impact docs labels Aug 24, 2022
@lhotari lhotari self-assigned this Aug 24, 2022

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we adding load on the metadata service ?
With this patch during a restart of the whole cluster we are going to perform ad additional read from zk for every topic lookup in order to find the leader broker. is this correct ?

@lhotari

lhotari commented Aug 24, 2022

Copy link
Copy Markdown
Member Author

Are we adding load on the metadata service ? With this patch during a restart of the whole cluster we are going to perform ad additional read from zk for every topic lookup in order to find the leader broker. is this correct ?

no. LeaderElectionService caches lookups. There won't be any additional load.

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

this is a very long standing issue

@lhotari

lhotari commented Aug 24, 2022

Copy link
Copy Markdown
Member Author

LGTM

this is a very long standing issue

I think I'll need to add some tests to ensure that the logic works. I did notice from the implementation that readCurrentLeader isn't a sufficient solution for resolving this issue. I added another commit to retry looking up the leader broker if there's no leader at the moment. I'll evolve this solution based on review feedback.

@lhotari
lhotari marked this pull request as draft August 24, 2022 08:53
@lhotari

lhotari commented Aug 24, 2022

Copy link
Copy Markdown
Member Author

I marked this as draft since the tests are still missing

.handle((leaderBroker, t) -> {
CompletableFuture<Optional<LeaderBroker>> retval;
if ((t != null || !leaderBroker.isPresent()) && retries.getAndIncrement() < 3) {
// retry after a delay of 5 seconds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tracking this delay with a debugger or with a jstack dump is very hard.
maybe we should log something at INFO level
otherwise lookup operations will hang without any observable sign

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll add some logging

// retry after a delay of 5 seconds
retval =
CompletableFuture.supplyAsync(() -> null,
CompletableFuture.delayedExecutor(5, SECONDS))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

which thread pool will run this execution ? (I guess it would be the system common pool)
should we use a well-known thread pool ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it's not really a problem to use the system's pool for delayed executor. However, delayed executor isn't available in Java 8 and using this will make backporting harder. I'll use Pulsar's existing scheduler for this purpose so that backporting will be easier.

}
return retval;
})
.thenCompose(Function.identity());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we need this step ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

when using .handle that returns a CompletableFuture, it's necessary to "flatten" it with .thenCompose(Function.identity()).
This is a known gap in CompletableFuture API that there is no handleCompose method directly. (an stackoverflow answer explaining details, contains links to other answers) . Java 12+ contains .exceptionallyCompose, but no .handleCompose which is unfortunate.

…is lost and causes lookup issues

- Fixes issue where leader broker information isn't available and this warning gets logged:
  "WARN  org.apache.pulsar.broker.namespace.NamespaceService - The information about the current leader broker wasn't available. Handling load manager decisions in a decentralized way."
@lhotari
lhotari force-pushed the lh-fix-leaderbroker-missing-issue branch from 878c09b to b771d96 Compare August 25, 2022 11:20
@KannarFr

Copy link
Copy Markdown
Contributor

To be sure, could this issue result in 502 during topic creation? I just had this problem.

I had these logs on brokers:

Aug 31 07:30:40 test-pulsar-c2-n1 pulsar-broker[1956320]: 07:30:40.055 [pulsar-web-34-3] INFO org.eclipse.jetty.server.RequestLog - 192.168.11.6 - - [31/Aug/2022:07:30:40 +0000] "PUT /admin/v2/persistent/customtenant/customns/customtopic?authoritative=false HTTP/1.1" 307 0 "-" "Jetty/9.4.44.v20210927" 5
Aug 31 07:30:40 test-pulsar-c2-n1 pulsar-broker[1956320]: 07:30:40.066 [pulsar-2-4] WARN org.apache.pulsar.broker.namespace.NamespaceService - The information about the current leader broker wasn't available. Handling load manager decisions in a decentralized way. NamespaceBundle[customtenant/customns/0xc0000000_0xffffffff]
Aug 31 07:30:40 test-pulsar-c2-n1 pulsar-broker[1956320]: 07:30:40.068 [pulsar-web-34-9] INFO org.eclipse.jetty.server.RequestLog - 192.168.11.6 - - [31/Aug/2022:07:30:40 +0000] "PUT /admin/v2/persistent/customtenant/customns/customtopic?authoritative=false HTTP/1.1" 307 0 "-" "Jetty/9.4.44.v20210927" 4
Aug 31 07:30:40 test-pulsar-c2-n1 pulsar-broker[1956320]: 07:30:40.079 [pulsar-2-5] WARN org.apache.pulsar.broker.namespace.NamespaceService - The information about the current leader broker wasn't available. Handling load manager decisions in a decentralized way. NamespaceBundle[customtenant/customns/0xc0000000_0xffffffff]
Aug 31 07:30:40 test-pulsar-c2-n1 pulsar-broker[1956320]: 07:30:40.080 [pulsar-web-34-3] INFO org.eclipse.jetty.server.RequestLog - 192.168.11.6 - - [31/Aug/2022:07:30:40 +0000] "PUT /admin/v2/persistent/customtenant/customns/customtopic?authoritative=false HTTP/1.1" 307 0 "-" "Jetty/9.4.44.v20210927" 4
Aug 31 07:30:40 test-pulsar-c2-n1 pulsar-broker[1956320]: 07:30:40.090 [pulsar-2-13] WARN org.apache.pulsar.broker.namespace.NamespaceService - The information about the current leader broker wasn't available. Handling load manager decisions in a decentralized way. NamespaceBundle[customtenant/customns/0xc0000000_0xffffffff]
Aug 31 07:30:40 test-pulsar-c2-n1 pulsar-broker[1956320]: 07:30:40.092 [pulsar-web-34-9] INFO org.eclipse.jetty.server.RequestLog - 192.168.11.6 - - [31/Aug/2022:07:30:40 +0000] "PUT /admin/v2/persistent/customtenant/customns/customtopic?authoritative=false HTTP/1.1" 307 0 "-" "Jetty/9.4.44.v20210927" 4

Then nothing related to this customtopic even on another broker. And the response was HTTP 502.

@lhotari

lhotari commented Sep 5, 2022

Copy link
Copy Markdown
Member Author

closing this in favour of #17401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/broker doc-not-needed Your PR changes do not impact docs type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants