This is an automated email from the ASF dual-hosted git repository.
danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 38d5ba73cf8 [HUDI-7308] LockManager::unlock should not call
updateLockHeldTimerMetrics if lockDurationTimer has not been started (#10523)
38d5ba73cf8 is described below
commit 38d5ba73cf81b01cb501879ba2c67fcbb249d2a5
Author: Krishen <[email protected]>
AuthorDate: Fri Jan 26 19:01:05 2024 -0800
[HUDI-7308] LockManager::unlock should not call updateLockHeldTimerMetrics
if lockDurationTimer has not been started (#10523)
---
.../hudi/client/transaction/lock/LockManager.java | 7 +++-
.../InProcessLockProviderWithRuntimeError.java | 43 ++++++++++++++++++++++
.../client/transaction/TestTransactionManager.java | 27 ++++++++++++--
3 files changed, 72 insertions(+), 5 deletions(-)
diff --git
a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/LockManager.java
b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/LockManager.java
index 1010f8006f4..f1fd05bc02b 100644
---
a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/LockManager.java
+++
b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/LockManager.java
@@ -27,6 +27,7 @@ import org.apache.hudi.common.util.ReflectionUtils;
import org.apache.hudi.common.util.RetryHelper;
import org.apache.hudi.config.HoodieLockConfig;
import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.exception.HoodieLockException;
import org.apache.hadoop.fs.FileSystem;
@@ -95,7 +96,11 @@ public class LockManager implements Serializable,
AutoCloseable {
*/
public void unlock() {
getLockProvider().unlock();
- metrics.updateLockHeldTimerMetrics();
+ try {
+ metrics.updateLockHeldTimerMetrics();
+ } catch (HoodieException e) {
+ LOG.error(String.format("Exception encountered when updating lock
metrics: %s", e));
+ }
close();
}
diff --git
a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/InProcessLockProviderWithRuntimeError.java
b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/InProcessLockProviderWithRuntimeError.java
new file mode 100644
index 00000000000..f825012f131
--- /dev/null
+++
b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/InProcessLockProviderWithRuntimeError.java
@@ -0,0 +1,43 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hudi.client.transaction.lock.InProcessLockProvider;
+import org.apache.hudi.common.config.LockConfiguration;
+
+public class InProcessLockProviderWithRuntimeError extends
InProcessLockProvider {
+
+ public InProcessLockProviderWithRuntimeError(
+ LockConfiguration lockConfiguration,
+ Configuration conf) {
+ super(lockConfiguration, conf);
+ }
+
+ @Override
+ public boolean tryLock(long time, TimeUnit unit) {
+ throw new RuntimeException();
+ }
+
+ @Override
+ public void unlock() {
+ return;
+ }
+}
diff --git
a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/TestTransactionManager.java
b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/TestTransactionManager.java
index 4222754a194..c0fb8de8691 100644
---
a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/TestTransactionManager.java
+++
b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/TestTransactionManager.java
@@ -29,15 +29,19 @@ import org.apache.hudi.common.util.Option;
import org.apache.hudi.config.HoodieCleanConfig;
import org.apache.hudi.config.HoodieLockConfig;
import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.config.metrics.HoodieMetricsConfig;
import org.apache.hudi.exception.HoodieLockException;
+import org.apache.hudi.metrics.MetricsReporterType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.junit.jupiter.api.TestInfo;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -47,14 +51,14 @@ public class TestTransactionManager extends
HoodieCommonTestHarness {
TransactionManager transactionManager;
@BeforeEach
- private void init() throws IOException {
+ private void init(TestInfo testInfo) throws IOException {
initPath();
initMetaClient();
- this.writeConfig = getWriteConfig();
+ this.writeConfig =
getWriteConfig(testInfo.getTags().contains("useLockProviderWithRuntimeError"));
this.transactionManager = new TransactionManager(this.writeConfig,
this.metaClient.getFs());
}
- private HoodieWriteConfig getWriteConfig() {
+ private HoodieWriteConfig getWriteConfig(boolean
useLockProviderWithRuntimeError) {
return HoodieWriteConfig.newBuilder()
.withPath(basePath)
.withCleanConfig(HoodieCleanConfig.newBuilder()
@@ -62,13 +66,15 @@ public class TestTransactionManager extends
HoodieCommonTestHarness {
.build())
.withWriteConcurrencyMode(WriteConcurrencyMode.OPTIMISTIC_CONCURRENCY_CONTROL)
.withLockConfig(HoodieLockConfig.newBuilder()
- .withLockProvider(InProcessLockProvider.class)
+ .withLockProvider(useLockProviderWithRuntimeError ?
InProcessLockProviderWithRuntimeError.class : InProcessLockProvider.class)
.withLockWaitTimeInMillis(50L)
.withNumRetries(2)
.withRetryWaitTimeInMillis(10L)
.withClientNumRetries(2)
.withClientRetryWaitTimeInMillis(10L)
.build())
+ .forTable("testtable")
+
.withMetricsConfig(HoodieMetricsConfig.newBuilder().withReporterType(MetricsReporterType.INMEMORY.toString()).withLockingMetrics(true).on(true).build())
.build();
}
@@ -245,6 +251,19 @@ public class TestTransactionManager extends
HoodieCommonTestHarness {
Assertions.assertFalse(transactionManager.getLastCompletedTransactionOwner().isPresent());
}
+ @Test
+ @Tag("useLockProviderWithRuntimeError")
+ public void testTransactionsWithUncheckedLockProviderRuntimeException() {
+ assertThrows(RuntimeException.class, () -> {
+ try {
+ transactionManager.beginTransaction(Option.empty(), Option.empty());
+ } finally {
+ transactionManager.endTransaction(Option.empty());
+ }
+ });
+
+ }
+
private Option<HoodieInstant> getInstant(String timestamp) {
return Option.of(new HoodieInstant(HoodieInstant.State.REQUESTED,
HoodieTimeline.COMMIT_ACTION, timestamp));
}