Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dc15896

Browse files
committedMar 14, 2025
[apache#6562] improvement(catalogs): Optimize the code path in createFileset and optimize path
make thread pool static remove shutdown logic in finally block.
1 parent 8958d52 commit dc15896

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed
 

‎catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/HadoopCatalogOperations.java

+10-24
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@ public class HadoopCatalogOperations extends ManagedSchemaOperations
8484
implements CatalogOperations, FilesetCatalog {
8585
private static final String SCHEMA_DOES_NOT_EXIST_MSG = "Schema %s does not exist";
8686
private static final String FILESET_DOES_NOT_EXIST_MSG = "Fileset %s does not exist";
87+
private static final ExecutorService FILE_SYSTEM_EXECUTOR =
88+
Executors.newFixedThreadPool(
89+
Math.max(2, Runtime.getRuntime().availableProcessors() / 2),
90+
r -> {
91+
Thread thread = new Thread(r, "FileSystem-Get-Thread");
92+
thread.setDaemon(true);
93+
return thread;
94+
});
8795
private static final String SLASH = "/";
8896
private static final Logger LOG = LoggerFactory.getLogger(HadoopCatalogOperations.class);
89-
private static final int TERMINATION_AWAIT_TIMEOUT_SECONDS = 5;
90-
9197
private final EntityStore store;
9298

9399
private HasPropertyMetadata propertiesMetadata;
@@ -769,19 +775,11 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
769775
.getOrDefault(
770776
config, HadoopCatalogPropertiesMetadata.FILESYSTEM_CONNECTION_TIMEOUT_SECONDS);
771777

772-
ExecutorService executor =
773-
Executors.newSingleThreadExecutor(
774-
r -> {
775-
Thread thread = new Thread(r, "FileSystem-Get-Thread");
776-
thread.setDaemon(true);
777-
return thread;
778-
});
779-
780778
Future<FileSystem> future = null;
781779

782780
try {
783781
future =
784-
executor.submit(
782+
FILE_SYSTEM_EXECUTOR.submit(
785783
() -> {
786784
try {
787785
return provider.getFileSystem(path, config);
@@ -832,19 +830,7 @@ FileSystem getFileSystem(Path path, Map<String, String> config) throws IOExcepti
832830
if (future != null && !future.isDone()) {
833831
future.cancel(true);
834832
}
835-
836-
executor.shutdown();
837-
try {
838-
if (!executor.awaitTermination(TERMINATION_AWAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
839-
executor.shutdownNow();
840-
if (!executor.awaitTermination(TERMINATION_AWAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
841-
LOG.error("ExecutorService did not terminate");
842-
}
843-
}
844-
} catch (InterruptedException ie) {
845-
executor.shutdownNow();
846-
Thread.currentThread().interrupt();
847-
}
833+
LOG.debug("FileSystem getting task completed");
848834
}
849835
}
850836
}

0 commit comments

Comments
 (0)