You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2021/10/04 15:14:15 UTC

[GitHub] [flink] tillrohrmann commented on a change in pull request #17409: [FLINK-24437][HA]Remove unhandled exception handler from CuratorFrame…

tillrohrmann commented on a change in pull request #17409:
URL: https://github.com/apache/flink/pull/17409#discussion_r721435775



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/zookeeper/InternalCuratorResource.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.flink.runtime.highavailability.zookeeper;
+
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.curator4.org.apache.curator.framework.CuratorFramework;
+import org.apache.flink.shaded.curator4.org.apache.curator.framework.api.UnhandledErrorListener;
+
+import java.io.Closeable;
+
+/** A wrapper for curator resource, which should be release together upon shutting down. */
+public class InternalCuratorResource implements Closeable {
+
+    private final CuratorFramework client;
+
+    private final UnhandledErrorListener listener;
+
+    public InternalCuratorResource(CuratorFramework client, UnhandledErrorListener listener) {
+        Preconditions.checkNotNull(client);
+        Preconditions.checkNotNull(listener);
+        this.client = client;
+        this.listener = listener;
+    }
+
+    @Override
+    public void close() {
+        client.getUnhandledErrorListenable().removeListener(listener);
+        client.close();
+    }
+
+    public CuratorFramework getClient() {

Review comment:
       maybe
   
   ```suggestion
       public CuratorFramework asCuratorFramework() {
   ```

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/zookeeper/InternalCuratorResource.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.flink.runtime.highavailability.zookeeper;
+
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.curator4.org.apache.curator.framework.CuratorFramework;
+import org.apache.flink.shaded.curator4.org.apache.curator.framework.api.UnhandledErrorListener;
+
+import java.io.Closeable;
+
+/** A wrapper for curator resource, which should be release together upon shutting down. */
+public class InternalCuratorResource implements Closeable {

Review comment:
       Maybe we could call it `CuratorFrameworkWithUnhandledErrorListener`.

##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/ZooKeeperLeaderElectionTest.java
##########
@@ -434,27 +446,29 @@ public void testExceptionForwarding() throws Exception {
         final TestingLeaderElectionEventHandler electionEventHandler =
                 new TestingLeaderElectionEventHandler(TEST_LEADER);
 
-        CuratorFramework client = null;
+        InternalCuratorResource curatorResource = null;
         final CreateBuilder mockCreateBuilder =
                 mock(CreateBuilder.class, Mockito.RETURNS_DEEP_STUBS);
         final String exMsg = "Test exception";
         final Exception testException = new Exception(exMsg);
 
         try {
-            client =
+            curatorResource =
                     spy(
                             ZooKeeperUtils.startCuratorFramework(
                                     configuration, NoOpFatalErrorHandler.INSTANCE));
 
-            doAnswer(invocation -> mockCreateBuilder).when(client).create();
+            doAnswer(invocation -> mockCreateBuilder).when(curatorResource.getClient()).create();

Review comment:
       I think this is causing `ZooKeeperLeaderElectionTest.testExceptionForwarding:461 UnfinishedStubbing`.

##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/ZooKeeperLeaderElectionTest.java
##########
@@ -434,27 +446,29 @@ public void testExceptionForwarding() throws Exception {
         final TestingLeaderElectionEventHandler electionEventHandler =
                 new TestingLeaderElectionEventHandler(TEST_LEADER);
 
-        CuratorFramework client = null;
+        InternalCuratorResource curatorResource = null;
         final CreateBuilder mockCreateBuilder =
                 mock(CreateBuilder.class, Mockito.RETURNS_DEEP_STUBS);
         final String exMsg = "Test exception";
         final Exception testException = new Exception(exMsg);
 
         try {
-            client =
+            curatorResource =
                     spy(
                             ZooKeeperUtils.startCuratorFramework(
                                     configuration, NoOpFatalErrorHandler.INSTANCE));
 
-            doAnswer(invocation -> mockCreateBuilder).when(client).create();
+            doAnswer(invocation -> mockCreateBuilder).when(curatorResource.getClient()).create();

Review comment:
       What this test effectively does is that it ensures that exception that are thrown in the `ZooKeeperLeaderElectionDriver.writeLeaderInformation()` will be forwarded to the fatal error handler.
   
   Maybe we could actually get rid of the mocking by introducing a `CuratorFrameworkFacade` that we can configure to fail on the `create()` call or some other call, for example.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/zookeeper/InternalCuratorResource.java
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.flink.runtime.highavailability.zookeeper;
+
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.curator4.org.apache.curator.framework.CuratorFramework;
+import org.apache.flink.shaded.curator4.org.apache.curator.framework.api.UnhandledErrorListener;
+
+import java.io.Closeable;
+
+/** A wrapper for curator resource, which should be release together upon shutting down. */
+public class InternalCuratorResource implements Closeable {
+
+    private final CuratorFramework client;
+
+    private final UnhandledErrorListener listener;
+
+    public InternalCuratorResource(CuratorFramework client, UnhandledErrorListener listener) {
+        Preconditions.checkNotNull(client);
+        Preconditions.checkNotNull(listener);
+        this.client = client;

Review comment:
       nit: 
   ```suggestion
           this.client = Preconditions.checkNotNull(client);
   ```




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org