-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][meta] Fix deadlock causes session notification not to work #19754
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
Changes from all commits
542cc5a
7adf86f
1e4d638
a098e17
0c53166
a395003
a377e6f
80d0613
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| package org.apache.pulsar.metadata.coordination.impl; | ||
|
|
||
| import com.fasterxml.jackson.databind.type.TypeFactory; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import java.util.EnumSet; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
@@ -111,13 +112,13 @@ private synchronized CompletableFuture<LeaderElectionState> elect() { | |
| } else { | ||
| return tryToBecomeLeader(); | ||
| } | ||
| }).thenComposeAsync(leaderElectionState -> { | ||
| }).thenCompose(leaderElectionState -> { | ||
| // make sure that the cache contains the current leader | ||
| // so that getLeaderValueIfPresent works on all brokers | ||
| cache.refresh(path); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the logic. This method looks changed and no blocking call anymore. /cc @lhotari |
||
| return cache.get(path) | ||
| .thenApply(__ -> leaderElectionState); | ||
| }, executor); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use this single thread executor here because session notification method ( |
||
| }); | ||
| } | ||
|
|
||
| private synchronized CompletableFuture<LeaderElectionState> handleExistingLeaderValue(GetResult res) { | ||
|
|
@@ -336,4 +337,9 @@ private void handlePathNotification(Notification notification) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| protected ScheduledExecutorService getSchedulerExecutor() { | ||
| return executor; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.pulsar.metadata.coordination.impl; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.function.Supplier; | ||
| import lombok.Cleanup; | ||
| import org.apache.pulsar.metadata.BaseMetadataStoreTest; | ||
| import org.apache.pulsar.metadata.api.MetadataStoreConfig; | ||
| import org.apache.pulsar.metadata.api.coordination.CoordinationService; | ||
| import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| public class LeaderElectionImplTest extends BaseMetadataStoreTest { | ||
|
mattisonchao marked this conversation as resolved.
|
||
|
|
||
| @Test(dataProvider = "impl", timeOut = 10000) | ||
| public void validateDeadLock(String provider, Supplier<String> urlSupplier) | ||
| throws Exception { | ||
| if (provider.equals("Memory") || provider.equals("RocksDB")) { | ||
| // There are no multiple sessions for the local memory provider | ||
| return; | ||
| } | ||
|
|
||
| @Cleanup | ||
| MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(), | ||
| MetadataStoreConfig.builder().build()); | ||
|
|
||
| String path = newKey(); | ||
|
|
||
| @Cleanup | ||
| CoordinationService cs = new CoordinationServiceImpl(store); | ||
|
|
||
| @Cleanup | ||
| LeaderElectionImpl<String> le = (LeaderElectionImpl<String>) cs.getLeaderElection(String.class, | ||
| path, __ -> { | ||
| }); | ||
| final CompletableFuture<Void> blockFuture = new CompletableFuture<>(); | ||
| // simulate handleSessionNotification method logic | ||
| le.getSchedulerExecutor().execute(() -> { | ||
| try { | ||
| le.elect("test-2").join(); | ||
| blockFuture.complete(null); | ||
| } catch (Throwable ex) { | ||
| blockFuture.completeExceptionally(ex); | ||
| } | ||
| }); | ||
| blockFuture.join(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.