You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ma...@apache.org on 2023/02/02 11:00:50 UTC

[flink] branch release-1.15 updated: [FLINK-30878][runtime] Revert "[FLINK-30474][runtime] Propagates leader information change only if the leadership is still acquired"

This is an automated email from the ASF dual-hosted git repository.

mapohl pushed a commit to branch release-1.15
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/release-1.15 by this push:
     new 8ee1ceb2f53 [FLINK-30878][runtime] Revert "[FLINK-30474][runtime] Propagates leader information change only if the leadership is still acquired"
8ee1ceb2f53 is described below

commit 8ee1ceb2f532f06d3cceefefc204772fb9b83594
Author: Matthias Pohl <ma...@aiven.io>
AuthorDate: Thu Feb 2 11:35:35 2023 +0100

    [FLINK-30878][runtime] Revert "[FLINK-30474][runtime] Propagates leader information change only if the leadership is still acquired"
    
    This reverts commit ce38381c15ee83fad782677d51b10941c843b82e.
---
 ...aultMultipleComponentLeaderElectionService.java |   8 +-
 ...MultipleComponentLeaderElectionServiceTest.java | 104 ---------------------
 2 files changed, 1 insertion(+), 111 deletions(-)

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionService.java b/flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionService.java
index cab5e6ec5bd..1348c5b0593 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionService.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionService.java
@@ -248,13 +248,7 @@ public class DefaultMultipleComponentLeaderElectionService
             LeaderElectionEventHandler leaderElectionEventHandler,
             LeaderInformation leaderInformation) {
         leadershipOperationExecutor.execute(
-                () -> {
-                    synchronized (lock) {
-                        if (running && multipleComponentLeaderElectionDriver.hasLeadership()) {
-                            leaderElectionEventHandler.onLeaderInformationChange(leaderInformation);
-                        }
-                    }
-                });
+                () -> leaderElectionEventHandler.onLeaderInformationChange(leaderInformation));
     }
 
     @Override
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionServiceTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionServiceTest.java
index f5001723f2b..cb2da45cf6c 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionServiceTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionServiceTest.java
@@ -33,9 +33,7 @@ import javax.annotation.Nullable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.UUID;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -123,108 +121,6 @@ class DefaultMultipleComponentLeaderElectionServiceTest {
         }
     }
 
-    @Test
-    public void testLeaderInformationChangeOnlyCalledOnLeaderForSingleComponent() throws Exception {
-        final TestingMultipleComponentLeaderElectionDriver leaderElectionDriver =
-                TestingMultipleComponentLeaderElectionDriver.newBuilder().build();
-
-        final DefaultMultipleComponentLeaderElectionService leaderElectionService =
-                createDefaultMultiplexingLeaderElectionService(leaderElectionDriver);
-
-        try {
-            final SimpleTestingLeaderElectionEventListener leaderElectionEventHandler =
-                    new SimpleTestingLeaderElectionEventListener();
-            final String componentId = "test-component";
-            leaderElectionService.registerLeaderElectionEventHandler(
-                    componentId, leaderElectionEventHandler);
-
-            final LeaderInformation leaderInformation =
-                    LeaderInformation.known(UUID.randomUUID(), "leader-address");
-            leaderElectionService.notifyLeaderInformationChange(componentId, leaderInformation);
-
-            assertThat(leaderElectionEventHandler.getLeaderInformation())
-                    .as(
-                            "The leader information should not be updated because the leadership was not acquired, yet.")
-                    .isNull();
-
-            leaderElectionDriver.grantLeadership();
-
-            assertThat(leaderElectionEventHandler.getLeaderInformation())
-                    .as(
-                            "The leader information should not be updated because no change event was triggered after the leadership was granted.")
-                    .isNull();
-
-            leaderElectionService.notifyLeaderInformationChange(componentId, leaderInformation);
-
-            assertThat(leaderElectionEventHandler.getLeaderInformation())
-                    .isEqualTo(leaderInformation);
-        } finally {
-            leaderElectionService.close();
-        }
-    }
-
-    @Test
-    public void testLeaderInformationChangeOnlyCalledOnLeaderForAllKnownComponents()
-            throws Exception {
-        final TestingMultipleComponentLeaderElectionDriver leaderElectionDriver =
-                TestingMultipleComponentLeaderElectionDriver.newBuilder().build();
-
-        final DefaultMultipleComponentLeaderElectionService leaderElectionService =
-                createDefaultMultiplexingLeaderElectionService(leaderElectionDriver);
-
-        try {
-            final String componentWithChangeId = "component-with-change";
-            final SimpleTestingLeaderElectionEventListener componentWithChangeListener =
-                    new SimpleTestingLeaderElectionEventListener();
-            final String componentWithoutChangeId = "component-without-change";
-            final SimpleTestingLeaderElectionEventListener componentWithoutChangeListener =
-                    new SimpleTestingLeaderElectionEventListener();
-
-            final Map<String, SimpleTestingLeaderElectionEventListener> listeners = new HashMap<>();
-            listeners.put(componentWithChangeId, componentWithChangeListener);
-            listeners.put(componentWithoutChangeId, componentWithoutChangeListener);
-
-            listeners.forEach(leaderElectionService::registerLeaderElectionEventHandler);
-
-            final LeaderInformation leaderInformation =
-                    LeaderInformation.known(UUID.randomUUID(), "leader-address");
-            final Collection<LeaderInformationWithComponentId> componentsWithChange =
-                    Collections.singleton(
-                            LeaderInformationWithComponentId.create(
-                                    componentWithChangeId, leaderInformation));
-            leaderElectionService.notifyAllKnownLeaderInformation(componentsWithChange);
-
-            assertThat(listeners)
-                    .allSatisfy(
-                            (componentId, listener) ->
-                                    assertThat(listener.getLeaderInformation())
-                                            .as(
-                                                    "The leader information should not be updated for %s because the leadership was not acquired, yet.",
-                                                    componentId)
-                                            .isNull());
-
-            leaderElectionDriver.grantLeadership();
-
-            assertThat(listeners)
-                    .allSatisfy(
-                            (componentId, listener) ->
-                                    assertThat(listener.getLeaderInformation())
-                                            .as(
-                                                    "The leader information should not be updated for %s because no change event was triggered after the leadership was granted.",
-                                                    componentId)
-                                            .isNull());
-
-            leaderElectionService.notifyAllKnownLeaderInformation(componentsWithChange);
-
-            assertThat(componentWithChangeListener.getLeaderInformation())
-                    .isEqualTo(leaderInformation);
-            assertThat(componentWithoutChangeListener.getLeaderInformation())
-                    .isEqualTo(LeaderInformation.empty());
-        } finally {
-            leaderElectionService.close();
-        }
-    }
-
     @Test
     public void unregisteredEventHandlersAreNotNotified() throws Exception {
         final TestingMultipleComponentLeaderElectionDriver leaderElectionDriver =