Name DuckDB workers to avoid Spark profile misattribution

This commit is contained in:
Intelli committed 2026-10-02 13:17:27 -06:00
1 parent 7582ab4d8e
commit 6e9c8302fa
2 files changed
+20 -2

No files matched your search

@@ -46,7 +46,7 @@ final class DuckDBDatabase {
properties.setProperty("allow_community_extensions", "false");
properties.setProperty("autoload_known_extensions", "false");
properties.setProperty("autoinstall_known_extensions", "false");
rootConnection = (DuckDBConnection) java.sql.DriverManager.getConnection("jdbc:duckdb:" + databaseFile.getAbsolutePath(), properties);
rootConnection = DuckDBNativeSupport.openDatabase(() -> (DuckDBConnection) java.sql.DriverManager.getConnection("jdbc:duckdb:" + databaseFile.getAbsolutePath(), properties));
}
static synchronized Connection getConnection() throws Exception {
@@ -3,6 +3,7 @@ package net.coreprotect.database;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public final class DuckDBNativeSupport {
@@ -14,13 +15,30 @@ public final class DuckDBNativeSupport {
public static void verifyAvailable() throws Exception {
Class.forName("org.duckdb.DuckDBDriver");
try (Connection connection = DriverManager.getConnection("jdbc:duckdb:")) {
try (Connection connection = openDatabase(() -> DriverManager.getConnection("jdbc:duckdb:"))) {
if (connection == null) {
throw new IllegalStateException("DuckDB JDBC driver did not create an in-memory connection");
}
}
}
public static <T> T openDatabase(DatabaseOpener<T> opener) throws SQLException {
Thread thread = Thread.currentThread();
String originalName = thread.getName();
thread.setName("CoreProtect-DuckDB");
try {
return opener.open();
}
finally {
thread.setName(originalName);
}
}
@FunctionalInterface
public interface DatabaseOpener<T> {
T open() throws SQLException;
}
public static boolean isNativeUnavailable(Throwable failure) {
for (Throwable cause = failure; cause != null; cause = cause.getCause()) {
if (cause instanceof UnsatisfiedLinkError) {