You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by vh...@apache.org on 2026/07/20 15:23:10 UTC
(hudi) branch master updated: test(client): add unit coverage for client utilities and services (#19222)
This is an automated email from the ASF dual-hosted git repository.
voonhous 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 f558c0039457 test(client): add unit coverage for client utilities and services (#19222)
f558c0039457 is described below
commit f558c0039457de30bcf4fd6d8ecf1972dd3bc4af
Author: Y Ethan Guo <et...@gmail.com>
AuthorDate: Mon Jul 20 08:22:45 2026 -0700
test(client): add unit coverage for client utilities and services (#19222)
* test(client): add unit coverage for client utilities and services
* fix(client): fix TSM client default config and lock owner info; address review findings
- Fix two compile errors in TestHoodieTableServiceManagerClient: import
HoodieTableType from common.model, and declare the checked
UnsupportedEncodingException from URLDecoder.decode via throws
IOException.
- TABLE_SERVICE_MANAGER_DEPLOY_EXTRA_PARAMS now defaults to the empty
string: its getter uses getStringOrDefault, which throws for no-default
properties, so every compact/clean/cluster call through
HoodieTableServiceManagerClient failed with HoodieException unless
hoodie.table.service.manager.deploy.extra.params was explicitly set.
- FileSystemBasedLockProvider.acquireLock writes the owner lock info
unconditionally after the atomic create: the previous
'if (!storage.exists(lockFile))' guard ran right after create() and was
always false, so lock files were empty and lock-conflict messages from
LockManager and TimeGeneratorBase carried no owner info.
- Consolidate filesystem lock provider tests in hudi-client-common: move
the default-lock-path and non-reentrancy cases from hudi-spark-client's
TestFileBasedLockProvider (which used no Spark) into
TestFileSystemBasedLockProvider and delete the old file.
- Test nits: drop an inert retry-wait property, import TypedProperties
instead of inline qualification, use assertEquals over
assertTrue(equals).
---------
Co-authored-by: voon <vo...@gmail.com>
---
.../lock/FileSystemBasedLockProvider.java | 6 +-
.../TestHoodieTableServiceManagerClient.java | 215 +++++++++++++++++++
.../lock/TestFileSystemBasedLockProvider.java | 228 +++++++++++++++++++++
.../hudi/client/TestFileBasedLockProvider.java | 114 -----------
.../config/HoodieTableServiceManagerConfig.java | 2 +-
5 files changed, 446 insertions(+), 119 deletions(-)
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/FileSystemBasedLockProvider.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/FileSystemBasedLockProvider.java
index aae756cfca95..f89ce7b61803 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/FileSystemBasedLockProvider.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/transaction/lock/FileSystemBasedLockProvider.java
@@ -175,10 +175,8 @@ public class FileSystemBasedLockProvider implements LockProvider<String>, Serial
private void acquireLock() {
try (OutputStream os = storage.create(this.lockFile, false)) {
- if (!storage.exists(this.lockFile)) {
- initLockInfo();
- os.write(StringUtils.getUTF8Bytes(lockInfo.toString()));
- }
+ initLockInfo();
+ os.write(StringUtils.getUTF8Bytes(lockInfo.toString()));
} catch (IOException e) {
throw new HoodieIOException(generateLogStatement(LockState.FAILED_TO_ACQUIRE), e);
}
diff --git a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/TestHoodieTableServiceManagerClient.java b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/TestHoodieTableServiceManagerClient.java
new file mode 100644
index 000000000000..6fb8b29ed782
--- /dev/null
+++ b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/TestHoodieTableServiceManagerClient.java
@@ -0,0 +1,215 @@
+/*
+ * 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;
+
+import org.apache.hudi.common.config.HoodieTableServiceManagerConfig;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.testutils.HoodieTestUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.exception.HoodieRemoteException;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests {@link HoodieTableServiceManagerClient} with the HTTP transport mocked by a
+ * local in-process {@link HttpServer}. Assertions cover the request path, the query
+ * parameters sent to the service, and retry/error handling.
+ */
+public class TestHoodieTableServiceManagerClient {
+
+ private static final String DB_NAME = "test_db";
+ private static final String TABLE_NAME = "test_table";
+
+ @TempDir
+ Path tempDir;
+
+ private HttpServer server;
+
+ @AfterEach
+ public void tearDown() {
+ if (server != null) {
+ server.stop(0);
+ server = null;
+ }
+ }
+
+ private HoodieTableMetaClient initMetaClient() throws IOException {
+ Properties props = new Properties();
+ props.setProperty(HoodieTableConfig.NAME.key(), TABLE_NAME);
+ props.setProperty(HoodieTableConfig.DATABASE_NAME.key(), DB_NAME);
+ return HoodieTestUtils.init(
+ HoodieTestUtils.getDefaultStorageConf(),
+ tempDir.resolve("table").toString(),
+ HoodieTableType.COPY_ON_WRITE,
+ props);
+ }
+
+ private HoodieTableServiceManagerConfig configFor(String uri) {
+ Properties props = new Properties();
+ // Keep retry cheap so the error-path test stays fast.
+ props.setProperty(HoodieTableServiceManagerConfig.TABLE_SERVICE_MANAGER_RETRIES.key(), "2");
+ props.setProperty(HoodieTableServiceManagerConfig.TABLE_SERVICE_MANAGER_RETRY_DELAY_SEC.key(), "1");
+ props.setProperty(HoodieTableServiceManagerConfig.TABLE_SERVICE_MANAGER_TIMEOUT_SEC.key(), "5");
+ return HoodieTableServiceManagerConfig.newBuilder().fromProperties(props).setURIs(uri).build();
+ }
+
+ /**
+ * Parses a raw query string of the form {@code a=1&b=2} into a decoded map.
+ */
+ private static Map<String, String> parseQuery(String rawQuery) throws IOException {
+ Map<String, String> params = new HashMap<>();
+ if (rawQuery == null || rawQuery.isEmpty()) {
+ return params;
+ }
+ for (String pair : rawQuery.split("&")) {
+ int idx = pair.indexOf('=');
+ String key = idx >= 0 ? pair.substring(0, idx) : pair;
+ String value = idx >= 0 ? pair.substring(idx + 1) : "";
+ params.put(
+ URLDecoder.decode(key, StandardCharsets.UTF_8.name()),
+ URLDecoder.decode(value, StandardCharsets.UTF_8.name()));
+ }
+ return params;
+ }
+
+ /**
+ * Starts a local HTTP server that records the request path and query params of the last
+ * request and replies 200. Returns the base URI (scheme + host + port).
+ */
+ private String startRecordingServer(Map<String, Object> captured) throws IOException {
+ server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
+ server.createContext("/", new HttpHandler() {
+ @Override
+ public void handle(HttpExchange exchange) throws IOException {
+ captured.put("path", exchange.getRequestURI().getPath());
+ captured.put("query", parseQuery(exchange.getRequestURI().getRawQuery()));
+ byte[] body = "ok".getBytes(StandardCharsets.UTF_8);
+ exchange.sendResponseHeaders(200, body.length);
+ try (OutputStream os = exchange.getResponseBody()) {
+ os.write(body);
+ }
+ }
+ });
+ server.start();
+ return "http://127.0.0.1:" + server.getAddress().getPort();
+ }
+
+ @Test
+ public void testExecuteCompactionSendsExpectedRequest() throws IOException {
+ Map<String, Object> captured = new HashMap<>();
+ String uri = startRecordingServer(captured);
+ HoodieTableServiceManagerClient client =
+ new HoodieTableServiceManagerClient(initMetaClient(), configFor(uri));
+
+ Option<String> result = client.executeCompaction();
+
+ // With no pending compaction the instant range is empty, but the request is still sent.
+ assertTrue(result.isPresent());
+ assertEquals("", result.get());
+ assertEquals(HoodieTableServiceManagerClient.EXECUTE_COMPACTION, captured.get("path"));
+
+ @SuppressWarnings("unchecked")
+ Map<String, String> query = (Map<String, String>) captured.get("query");
+ assertEquals(HoodieTableServiceManagerClient.Action.REQUEST.name(),
+ query.get(HoodieTableServiceManagerClient.ACTION));
+ assertEquals(DB_NAME, query.get(HoodieTableServiceManagerClient.DATABASE_NAME_PARAM));
+ assertEquals(TABLE_NAME, query.get(HoodieTableServiceManagerClient.TABLE_NAME_PARAM));
+ assertTrue(query.containsKey(HoodieTableServiceManagerClient.BASEPATH_PARAM));
+ assertTrue(query.containsKey(HoodieTableServiceManagerClient.INSTANT_PARAM));
+ assertTrue(query.containsKey(HoodieTableServiceManagerClient.EXECUTION_ENGINE));
+ assertTrue(query.containsKey(HoodieTableServiceManagerClient.PARALLELISM));
+ }
+
+ @Test
+ public void testExecuteCleanTargetsCleanEndpoint() throws IOException {
+ Map<String, Object> captured = new HashMap<>();
+ String uri = startRecordingServer(captured);
+ HoodieTableServiceManagerClient client =
+ new HoodieTableServiceManagerClient(initMetaClient(), configFor(uri));
+
+ client.executeClean();
+ assertEquals(HoodieTableServiceManagerClient.EXECUTE_CLEAN, captured.get("path"));
+ }
+
+ @Test
+ public void testExecuteClusteringTargetsClusterEndpoint() throws IOException {
+ Map<String, Object> captured = new HashMap<>();
+ String uri = startRecordingServer(captured);
+ HoodieTableServiceManagerClient client =
+ new HoodieTableServiceManagerClient(initMetaClient(), configFor(uri));
+
+ client.executeClustering();
+ assertEquals(HoodieTableServiceManagerClient.EXECUTE_CLUSTERING, captured.get("path"));
+ }
+
+ @Test
+ public void testServerErrorRetriesAndSurfacesRemoteException() throws IOException {
+ AtomicInteger requestCount = new AtomicInteger(0);
+ server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
+ server.createContext("/", exchange -> {
+ requestCount.incrementAndGet();
+ // Always fail so the retry limit is exhausted and an exception propagates.
+ byte[] body = "boom".getBytes(StandardCharsets.UTF_8);
+ exchange.sendResponseHeaders(500, body.length);
+ try (OutputStream os = exchange.getResponseBody()) {
+ os.write(body);
+ }
+ });
+ server.start();
+ String uri = "http://127.0.0.1:" + server.getAddress().getPort();
+
+ HoodieTableServiceManagerClient client =
+ new HoodieTableServiceManagerClient(initMetaClient(), configFor(uri));
+
+ assertThrows(HoodieRemoteException.class, client::executeCompaction);
+ // Two retries configured means the request is attempted more than once.
+ assertTrue(requestCount.get() >= 2,
+ "expected at least 2 attempts, got " + requestCount.get());
+ }
+
+ @Test
+ public void testUnreachableServerSurfacesRemoteException() throws IOException {
+ // Port 1 is a privileged, unbound port: the connection will be refused.
+ HoodieTableServiceManagerClient client =
+ new HoodieTableServiceManagerClient(initMetaClient(), configFor("http://127.0.0.1:1"));
+ assertThrows(HoodieRemoteException.class, client::executeCompaction);
+ }
+}
diff --git a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/lock/TestFileSystemBasedLockProvider.java b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/lock/TestFileSystemBasedLockProvider.java
new file mode 100644
index 000000000000..fccbae2ecfa0
--- /dev/null
+++ b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/client/transaction/lock/TestFileSystemBasedLockProvider.java
@@ -0,0 +1,228 @@
+/*
+ * 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.lock;
+
+import org.apache.hudi.common.config.LockConfiguration;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.testutils.HoodieTestUtils;
+import org.apache.hudi.common.util.HoodieStorageUtils;
+import org.apache.hudi.config.HoodieLockConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StorageConfiguration;
+import org.apache.hudi.storage.StoragePath;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.hudi.common.config.LockConfiguration.FILESYSTEM_LOCK_EXPIRE_PROP_KEY;
+import static org.apache.hudi.common.config.LockConfiguration.FILESYSTEM_LOCK_PATH_PROP_KEY;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests {@link FileSystemBasedLockProvider} against a local temp directory.
+ */
+public class TestFileSystemBasedLockProvider {
+
+ @TempDir
+ Path tempDir;
+
+ private LockConfiguration lockConfiguration(String lockPath, int expireMinutes) {
+ Properties props = new Properties();
+ props.setProperty(FILESYSTEM_LOCK_PATH_PROP_KEY, lockPath);
+ props.setProperty(FILESYSTEM_LOCK_EXPIRE_PROP_KEY, String.valueOf(expireMinutes));
+ return new LockConfiguration(props);
+ }
+
+ private String lockDir(String name) {
+ return tempDir.resolve(name).toString();
+ }
+
+ @Test
+ public void testAcquireAndReleaseLock() {
+ StorageConfiguration<?> storageConf = HoodieTestUtils.getDefaultStorageConf();
+ FileSystemBasedLockProvider provider =
+ new FileSystemBasedLockProvider(lockConfiguration(lockDir("acquire"), 0), storageConf);
+ try {
+ assertTrue(provider.tryLock(1, TimeUnit.SECONDS), "first acquisition should succeed");
+ // getLock exposes the fully-qualified lock file path used on the backing storage.
+ assertTrue(provider.getLock().endsWith("/lock"));
+ provider.unlock();
+ // After unlock the file is gone, so the lock is acquirable again.
+ assertTrue(provider.tryLock(1, TimeUnit.SECONDS), "re-acquisition after unlock should succeed");
+ } finally {
+ provider.unlock();
+ provider.close();
+ }
+ }
+
+ @Test
+ public void testConcurrentProvidersCannotBothHoldLock() {
+ StorageConfiguration<?> storageConf = HoodieTestUtils.getDefaultStorageConf();
+ LockConfiguration config = lockConfiguration(lockDir("contended"), 0);
+ FileSystemBasedLockProvider holder = new FileSystemBasedLockProvider(config, storageConf);
+ FileSystemBasedLockProvider contender = new FileSystemBasedLockProvider(config, storageConf);
+ try {
+ assertTrue(holder.tryLock(1, TimeUnit.SECONDS));
+ // A non-expired lock owned by another provider blocks acquisition.
+ assertFalse(contender.tryLock(1, TimeUnit.SECONDS), "second provider must not acquire a held lock");
+ // The contender is able to read the current owner's lock info.
+ assertTrue(contender.getCurrentOwnerLockInfo() != null && !contender.getCurrentOwnerLockInfo().isEmpty());
+ holder.unlock();
+ assertTrue(contender.tryLock(1, TimeUnit.SECONDS), "contender acquires after holder releases");
+ } finally {
+ holder.unlock();
+ contender.unlock();
+ holder.close();
+ }
+ }
+
+ @Test
+ public void testExpiredLockIsReclaimed() throws Exception {
+ StorageConfiguration<?> storageConf = HoodieTestUtils.getDefaultStorageConf();
+ String path = lockDir("expiry");
+ // Expiry of 1 minute; we age the lock file deterministically rather than sleeping.
+ LockConfiguration config = lockConfiguration(path, 1);
+ FileSystemBasedLockProvider holder = new FileSystemBasedLockProvider(config, storageConf);
+ FileSystemBasedLockProvider contender = new FileSystemBasedLockProvider(config, storageConf);
+ try {
+ assertTrue(holder.tryLock(1, TimeUnit.SECONDS));
+ // Not yet expired: contender is blocked.
+ assertFalse(contender.tryLock(1, TimeUnit.SECONDS));
+
+ // Age the lock file well beyond the 1-minute expiry window.
+ StoragePath lockFile = new StoragePath(path + StoragePath.SEPARATOR + "lock");
+ HoodieStorage storage = HoodieStorageUtils.getStorage(lockFile.toString(), storageConf);
+ storage.setModificationTime(lockFile, System.currentTimeMillis() - (5 * 60 * 1000L));
+
+ // The expired lock file is deleted and the contender acquires it.
+ assertTrue(contender.tryLock(1, TimeUnit.SECONDS), "expired lock should be reclaimable");
+ } finally {
+ holder.unlock();
+ contender.unlock();
+ contender.close();
+ }
+ }
+
+ @Test
+ public void testZeroExpiryNeverReclaims() throws Exception {
+ StorageConfiguration<?> storageConf = HoodieTestUtils.getDefaultStorageConf();
+ String path = lockDir("noexpiry");
+ // Expiry of 0 disables reclamation entirely.
+ LockConfiguration config = lockConfiguration(path, 0);
+ FileSystemBasedLockProvider holder = new FileSystemBasedLockProvider(config, storageConf);
+ FileSystemBasedLockProvider contender = new FileSystemBasedLockProvider(config, storageConf);
+ try {
+ assertTrue(holder.tryLock(1, TimeUnit.SECONDS));
+
+ // Even a very old lock file must not be reclaimed when expiry is disabled.
+ StoragePath lockFile = new StoragePath(path + StoragePath.SEPARATOR + "lock");
+ HoodieStorage storage = HoodieStorageUtils.getStorage(lockFile.toString(), storageConf);
+ storage.setModificationTime(lockFile, System.currentTimeMillis() - (60 * 60 * 1000L));
+
+ assertFalse(contender.tryLock(1, TimeUnit.SECONDS), "zero expiry must never reclaim a lock");
+ } finally {
+ holder.unlock();
+ contender.unlock();
+ holder.close();
+ }
+ }
+
+ @Test
+ public void testUnlockWithoutLockIsNoOp() {
+ StorageConfiguration<?> storageConf = HoodieTestUtils.getDefaultStorageConf();
+ FileSystemBasedLockProvider provider =
+ new FileSystemBasedLockProvider(lockConfiguration(lockDir("idempotent"), 0), storageConf);
+ // Releasing when no lock is held must not raise.
+ assertDoesNotThrow(provider::unlock);
+ provider.close();
+ }
+
+ @Test
+ public void testConstructorRejectsNegativeExpiry() {
+ StorageConfiguration<?> storageConf = HoodieTestUtils.getDefaultStorageConf();
+ LockConfiguration config = lockConfiguration(lockDir("bad"), -1);
+ assertThrows(IllegalArgumentException.class,
+ () -> new FileSystemBasedLockProvider(config, storageConf));
+ }
+
+ @Test
+ public void testGetLockConfigProducesUsableProperties() {
+ String tablePath = tempDir.resolve("table").toString();
+ TypedProperties props = FileSystemBasedLockProvider.getLockConfig(tablePath);
+ // The generated config points the lock provider at the table's auxiliary folder.
+ assertTrue(props.getString(HoodieLockConfig.FILESYSTEM_LOCK_PATH.key()).startsWith(tablePath));
+ assertEquals(FileSystemBasedLockProvider.class.getName(),
+ props.getString(HoodieLockConfig.LOCK_PROVIDER_CLASS_NAME.key()));
+
+ StorageConfiguration<?> storageConf = HoodieTestUtils.getDefaultStorageConf();
+ FileSystemBasedLockProvider provider =
+ new FileSystemBasedLockProvider(new LockConfiguration(props), storageConf);
+ try {
+ assertTrue(provider.tryLock(1, TimeUnit.SECONDS));
+ } finally {
+ provider.unlock();
+ provider.close();
+ }
+ }
+
+ @Test
+ public void testLockPathDefaultsToMetafolderFromBasePath() {
+ StorageConfiguration<?> storageConf = HoodieTestUtils.getDefaultStorageConf();
+ Properties props = new Properties();
+ props.setProperty(HoodieWriteConfig.BASE_PATH.key(), lockDir("defaultpath"));
+ props.setProperty(FILESYSTEM_LOCK_EXPIRE_PROP_KEY, "0");
+ FileSystemBasedLockProvider provider =
+ new FileSystemBasedLockProvider(new LockConfiguration(props), storageConf);
+ try {
+ assertTrue(provider.tryLock(1, TimeUnit.SECONDS),
+ "lock acquisition must work without an explicit lock path");
+ // Without an explicit lock path the provider locks under the table metafolder.
+ assertTrue(provider.getLock().endsWith(
+ HoodieTableMetaClient.METAFOLDER_NAME + StoragePath.SEPARATOR + "lock"));
+ } finally {
+ provider.unlock();
+ provider.close();
+ }
+ }
+
+ @Test
+ public void testSameProviderSecondTryLockFails() {
+ StorageConfiguration<?> storageConf = HoodieTestUtils.getDefaultStorageConf();
+ FileSystemBasedLockProvider provider =
+ new FileSystemBasedLockProvider(lockConfiguration(lockDir("nonreentrant"), 0), storageConf);
+ try {
+ assertTrue(provider.tryLock(1, TimeUnit.SECONDS));
+ // The file lock is not reentrant: a second tryLock by the same provider fails.
+ assertFalse(provider.tryLock(1, TimeUnit.SECONDS));
+ } finally {
+ provider.unlock();
+ provider.close();
+ }
+ }
+}
diff --git a/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/TestFileBasedLockProvider.java b/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/TestFileBasedLockProvider.java
deleted file mode 100644
index 0fcc9dadea18..000000000000
--- a/hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/TestFileBasedLockProvider.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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;
-
-import org.apache.hudi.client.transaction.lock.FileSystemBasedLockProvider;
-import org.apache.hudi.common.config.LockConfiguration;
-import org.apache.hudi.config.HoodieWriteConfig;
-import org.apache.hudi.storage.StorageConfiguration;
-
-import org.apache.hadoop.conf.Configuration;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
-
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.hudi.common.config.LockConfiguration.FILESYSTEM_LOCK_EXPIRE_PROP_KEY;
-import static org.apache.hudi.common.config.LockConfiguration.FILESYSTEM_LOCK_PATH_PROP_KEY;
-import static org.apache.hudi.common.config.LockConfiguration.LOCK_ACQUIRE_NUM_RETRIES_PROP_KEY;
-import static org.apache.hudi.common.config.LockConfiguration.LOCK_ACQUIRE_RETRY_WAIT_TIME_IN_MILLIS_PROP_KEY;
-import static org.apache.hudi.common.config.LockConfiguration.LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY;
-import static org.apache.hudi.common.testutils.HoodieTestUtils.getDefaultStorageConf;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-public class TestFileBasedLockProvider {
-
- @TempDir
- Path tempDir;
- String basePath;
- LockConfiguration lockConfiguration;
- StorageConfiguration<Configuration> storageConf;
-
- @BeforeEach
- public void setUp() throws IOException {
- basePath = tempDir.toUri().getPath();
- Properties properties = new Properties();
- properties.setProperty(FILESYSTEM_LOCK_PATH_PROP_KEY, basePath);
- properties.setProperty(FILESYSTEM_LOCK_EXPIRE_PROP_KEY, "1");
- properties.setProperty(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY, "1000");
- properties.setProperty(LOCK_ACQUIRE_RETRY_WAIT_TIME_IN_MILLIS_PROP_KEY, "1000");
- properties.setProperty(LOCK_ACQUIRE_NUM_RETRIES_PROP_KEY, "3");
- lockConfiguration = new LockConfiguration(properties);
- storageConf = getDefaultStorageConf();
- }
-
- @Test
- public void testAcquireLock() {
- FileSystemBasedLockProvider fileBasedLockProvider = new FileSystemBasedLockProvider(lockConfiguration, storageConf);
- assertTrue(fileBasedLockProvider.tryLock(lockConfiguration.getConfig()
- .getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY), TimeUnit.MILLISECONDS));
- fileBasedLockProvider.unlock();
- }
-
- @Test
- public void testAcquireLockWithDefaultPath() {
- lockConfiguration.getConfig().remove(FILESYSTEM_LOCK_PATH_PROP_KEY);
- lockConfiguration.getConfig().setProperty(HoodieWriteConfig.BASE_PATH.key(), basePath);
- FileSystemBasedLockProvider fileBasedLockProvider = new FileSystemBasedLockProvider(lockConfiguration, storageConf);
- assertTrue(fileBasedLockProvider.tryLock(lockConfiguration.getConfig()
- .getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY), TimeUnit.MILLISECONDS));
- fileBasedLockProvider.unlock();
- lockConfiguration.getConfig().setProperty(FILESYSTEM_LOCK_PATH_PROP_KEY, basePath);
- }
-
- @Test
- public void testUnLock() {
- FileSystemBasedLockProvider fileBasedLockProvider = new FileSystemBasedLockProvider(lockConfiguration, storageConf);
- assertTrue(fileBasedLockProvider.tryLock(lockConfiguration.getConfig()
- .getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY), TimeUnit.MILLISECONDS));
- fileBasedLockProvider.unlock();
- assertTrue(fileBasedLockProvider.tryLock(lockConfiguration.getConfig()
- .getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY), TimeUnit.MILLISECONDS));
- }
-
- @Test
- public void testReentrantLock() {
- FileSystemBasedLockProvider fileBasedLockProvider = new FileSystemBasedLockProvider(lockConfiguration, storageConf);
- assertTrue(fileBasedLockProvider.tryLock(lockConfiguration.getConfig()
- .getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY), TimeUnit.MILLISECONDS));
- assertFalse(fileBasedLockProvider.tryLock(lockConfiguration.getConfig()
- .getLong(LOCK_ACQUIRE_WAIT_TIMEOUT_MS_PROP_KEY), TimeUnit.MILLISECONDS));
- fileBasedLockProvider.unlock();
- }
-
- @Test
- public void testUnlockWithoutLock() {
- assertDoesNotThrow(() -> {
- FileSystemBasedLockProvider fileBasedLockProvider = new FileSystemBasedLockProvider(lockConfiguration, storageConf);
- fileBasedLockProvider.unlock();
- });
- }
-}
diff --git a/hudi-common/src/main/java/org/apache/hudi/common/config/HoodieTableServiceManagerConfig.java b/hudi-common/src/main/java/org/apache/hudi/common/config/HoodieTableServiceManagerConfig.java
index a2cef4558e1b..7ffa5ef6099f 100644
--- a/hudi-common/src/main/java/org/apache/hudi/common/config/HoodieTableServiceManagerConfig.java
+++ b/hudi-common/src/main/java/org/apache/hudi/common/config/HoodieTableServiceManagerConfig.java
@@ -95,7 +95,7 @@ public class HoodieTableServiceManagerConfig extends HoodieConfig {
public static final ConfigProperty<String> TABLE_SERVICE_MANAGER_DEPLOY_EXTRA_PARAMS = ConfigProperty
.key(TABLE_SERVICE_MANAGER_PREFIX + ".deploy.extra.params")
- .noDefaultValue()
+ .defaultValue("")
.markAdvanced()
.sinceVersion("0.13.0")
.withDocumentation("The extra params to deploy for table service of this table, split by ';'");