You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "nsivabalan (via GitHub)" <gi...@apache.org> on 2023/03/29 06:01:03 UTC

[GitHub] [hudi] nsivabalan commented on a diff in pull request #8304: [HUDI-5993] Connection leak for lock provider

nsivabalan commented on code in PR #8304:
URL: https://github.com/apache/hudi/pull/8304#discussion_r1151428902


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/LockManager.java:
##########
@@ -111,6 +111,7 @@ public void unlock() {
     if (writeConfig.getWriteConcurrencyMode().supportsOptimisticConcurrencyControl()) {
       getLockProvider().unlock();
       metrics.updateLockHeldTimerMetrics();
+      close();

Review Comment:
   @vinothchandar : yes you are right. for streaming ingestion, we keep re-using the same write client and hence. 



##########
hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/TestLockManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.hudi.client.transaction;
+
+import org.apache.hudi.client.transaction.lock.LockManager;
+import org.apache.hudi.client.transaction.lock.ZookeeperBasedLockProvider;
+import org.apache.hudi.common.model.HoodieFailedWritesCleaningPolicy;
+import org.apache.hudi.common.model.WriteConcurrencyMode;
+import org.apache.hudi.common.testutils.HoodieCommonTestHarness;
+import org.apache.hudi.config.HoodieCleanConfig;
+import org.apache.hudi.config.HoodieLockConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import org.apache.curator.test.TestingServer;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class TestLockManager extends HoodieCommonTestHarness {
+
+  private static final Logger LOG = LogManager.getLogger(TestLockManager.class);
+
+  private static TestingServer server;
+  private static String zk_basePath = "/hudi/test/lock";
+  private static String key = "table1";
+
+  HoodieWriteConfig writeConfig;
+  LockManager lockManager;
+
+  @BeforeAll
+  public static void setup() {
+    while (server == null) {
+      try {
+        server = new TestingServer();
+      } catch (Exception e) {
+        LOG.error("Getting bind exception - retrying to allocate server");
+        server = null;
+      }
+    }
+  }
+
+  @AfterAll
+  public static void tearDown() throws IOException {
+    if (server != null) {
+      server.close();
+    }
+  }
+
+  private HoodieWriteConfig getWriteConfig() {
+    return HoodieWriteConfig.newBuilder()
+        .withPath(basePath)
+        .withCleanConfig(HoodieCleanConfig.newBuilder()
+            .withFailedWritesCleaningPolicy(HoodieFailedWritesCleaningPolicy.LAZY)
+            .build())
+        .withWriteConcurrencyMode(WriteConcurrencyMode.OPTIMISTIC_CONCURRENCY_CONTROL)
+        .withLockConfig(HoodieLockConfig.newBuilder()
+            .withLockProvider(ZookeeperBasedLockProvider.class)
+            .withZkBasePath(zk_basePath)
+            .withZkLockKey(key)
+            .withZkQuorum(server.getConnectString())
+            .build())
+        .build();
+  }
+
+  @BeforeEach
+  private void init() throws IOException {
+    initPath();
+    initMetaClient();
+    this.writeConfig = getWriteConfig();
+    this.lockManager = new LockManager(this.writeConfig, this.metaClient.getFs());
+  }
+
+  @Test
+  public void testLockAndUnlock() throws NoSuchFieldException, IllegalAccessException{
+
+    Field lockProvider = lockManager.getClass().getDeclaredField("lockProvider");
+    lockProvider.setAccessible(true);
+
+    assertDoesNotThrow(() -> {
+      lockManager.lock();
+    });
+
+    assertNotNull(lockProvider.get(lockManager));
+
+    assertDoesNotThrow(() -> {
+      lockManager.unlock();

Review Comment:
   +1 



-- 
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: commits-unsubscribe@hudi.apache.org

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