Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

perf(zookeeper): optimize connection initialization

miracle0d57c39a78c2
diff --git a/agents/drivers/zookeeper/src/main/java/com/dbx/agent/zookeeper/ZooKeeperAgent.java b/agents/drivers/zookeeper/src/main/java/com/dbx/agent/zookeeper/ZooKeeperAgent.java
index 5cca0ccbd3..07a491afe7 100644
--- a/agents/drivers/zookeeper/src/main/java/com/dbx/agent/zookeeper/ZooKeeperAgent.java
+++ b/agents/drivers/zookeeper/src/main/java/com/dbx/agent/zookeeper/ZooKeeperAgent.java
@@ -11,6 +11,8 @@ import org.apache.zookeeper.data.Stat;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import java.net.InetSocketAddress;
+import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
@@ -23,15 +25,18 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
public final class ZooKeeperAgent {
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
private static final int DEFAULT_LIMIT = 100;
private static final int DEFAULT_SESSION_TIMEOUT_MS = 30000;
- private static final int DEFAULT_CONNECTION_TIMEOUT_MS = 15000;
- private static final int DEFAULT_BASE_SLEEP_TIME_MS = 1000;
- private static final int DEFAULT_MAX_RETRIES = 3;
+ private static final int DEFAULT_CONNECTION_TIMEOUT_MS = 5000;
+ private static final int DEFAULT_BASE_SLEEP_TIME_MS = 250;
+ private static final int DEFAULT_MAX_RETRIES = 2;
+ private static final int DEFAULT_PORT = 2181;
+ private static final int DEFAULT_PROBE_TIMEOUT_MS = 2000;
private static final String STAT_LOOKUP_CONCURRENCY_PROPERTY = "dbx.zookeeper.statLookupConcurrency";
private static final String STAT_LOOKUP_CONCURRENCY_ENV = "DBX_ZOOKEEPER_STAT_LOOKUP_CONCURRENCY";
private static final int DEFAULT_STAT_LOOKUP_CONCURRENCY = 16;
@@ -88,10 +93,15 @@ public final class ZooKeeperAgent {
int baseSleepTimeMs = intOrDefault(connection, "base_sleep_time_ms", DEFAULT_BASE_SLEEP_TIME_MS);
int maxRetries = intOrDefault(connection, "max_retries", DEFAULT_MAX_RETRIES);
+ int connectionTimeoutMs = intOrDefault(connection, "connection_timeout_ms", DEFAULT_CONNECTION_TIMEOUT_MS);
+ String connectString = reachableConnectString(
+ connectString(connection),
+ Math.min(DEFAULT_PROBE_TIMEOUT_MS, connectionTimeoutMs)
+ );
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
- .connectString(connectString(connection))
+ .connectString(connectString)
.sessionTimeoutMs(intOrDefault(connection, "session_timeout_ms", DEFAULT_SESSION_TIMEOUT_MS))
- .connectionTimeoutMs(intOrDefault(connection, "connection_timeout_ms", DEFAULT_CONNECTION_TIMEOUT_MS))
+ .connectionTimeoutMs(connectionTimeoutMs)
.retryPolicy(new ExponentialBackoffRetry(baseSleepTimeMs, maxRetries));
String namespace = trimSlashes(stringOrEmpty(connection, "namespace"));
@@ -118,7 +128,93 @@ public final class ZooKeeperAgent {
return configured;
}
return stringOrDefault(connection, "host", "127.0.0.1") + ":"
- + intOrDefault(connection, "port", 2181);
+ + intOrDefault(connection, "port", DEFAULT_PORT);
+ }
+
+ static String reachableConnectString(String connectString, int probeTimeoutMs) {
+ int slash = connectString.indexOf('/');
+ String hostsPart = slash >= 0 ? connectString.substring(0, slash) : connectString;
+ String chroot = slash >= 0 ? connectString.substring(slash) : "";
+
+ List<String> hosts = new ArrayList<>();
+ for (String item : hostsPart.split(",")) {
+ String trimmed = item.trim();
+ if (!trimmed.isEmpty()) {
+ hosts.add(trimmed);
+ }
+ }
+
+ List<String> reachable = probeReachableHosts(hosts, probeTimeoutMs);
+ if (reachable.isEmpty()) {
+ throw new IllegalStateException(
+ "No reachable ZooKeeper server within " + probeTimeoutMs + "ms: " + hostsPart
+ );
+ }
+ // Curator needs the complete ensemble to reconnect when nodes recover or fail over later.
+ return String.join(",", hosts) + chroot;
+ }
+
+ private static List<String> probeReachableHosts(List<String> hosts, int probeTimeoutMs) {
+ if (hosts.isEmpty()) {
+ return Collections.emptyList();
+ }
+ ExecutorService executor = Executors.newFixedThreadPool(
+ Math.min(hosts.size(), 8),
+ daemonThreadFactory("dbx-zookeeper-probe-")
+ );
+ try {
+ List<Future<Boolean>> probes = new ArrayList<>();
+ for (String host : hosts) {
+ probes.add(executor.submit(() -> isEndpointReachable(host, probeTimeoutMs)));
+ }
+ // Probes run in parallel; the deadline covers socket timeout plus DNS slack.
+ long deadline = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(probeTimeoutMs + 500L);
+ List<String> reachable = new ArrayList<>();
+ for (int i = 0; i < hosts.size(); i++) {
+ long remainingMs = Math.max(1, TimeUnit.NANOSECONDS.toMillis(deadline - System.nanoTime()));
+ try {
+ if (probes.get(i).get(remainingMs, TimeUnit.MILLISECONDS)) {
+ reachable.add(hosts.get(i));
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IllegalStateException("ZooKeeper reachability probe interrupted", e);
+ } catch (ExecutionException | TimeoutException e) {
+ // Treat probe failures as unreachable.
+ }
+ }
+ return reachable;
+ } finally {
+ executor.shutdownNow();
+ }
+ }
+
+ private static boolean isEndpointReachable(String endpoint, int probeTimeoutMs) {
+ try (Socket socket = new Socket()) {
+ socket.connect(parseEndpoint(endpoint), probeTimeoutMs);
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ static InetSocketAddress parseEndpoint(String endpoint) {
+ String host = endpoint;
+ int port = DEFAULT_PORT;
+ int bracketEnd = endpoint.indexOf(']');
+ if (endpoint.startsWith("[") && bracketEnd > 0) {
+ host = endpoint.substring(1, bracketEnd);
+ if (bracketEnd + 1 < endpoint.length() && endpoint.charAt(bracketEnd + 1) == ':') {
+ port = Integer.parseInt(endpoint.substring(bracketEnd + 2));
+ }
+ } else {
+ int colon = endpoint.lastIndexOf(':');
+ if (colon >= 0 && endpoint.indexOf(':') == colon) {
+ host = endpoint.substring(0, colon);
+ port = Integer.parseInt(endpoint.substring(colon + 1));
+ }
+ }
+ return new InetSocketAddress(host, port);
}
private static void startAndVerify(CuratorFramework active, JsonObject connection) throws Exception {
diff --git a/agents/drivers/zookeeper/src/test/java/com/dbx/agent/zookeeper/ZooKeeperAgentTest.java b/agents/drivers/zookeeper/src/test/java/com/dbx/agent/zookeeper/ZooKeeperAgentTest.java
index 0f11aa774f..479d7bba4f 100644
--- a/agents/drivers/zookeeper/src/test/java/com/dbx/agent/zookeeper/ZooKeeperAgentTest.java
+++ b/agents/drivers/zookeeper/src/test/java/com/dbx/agent/zookeeper/ZooKeeperAgentTest.java
@@ -137,6 +137,58 @@ final class ZooKeeperAgentTest {
}
}
+ @Test
+ void connectFailsFastWhenAllServersAreUnreachable() {
+ long startedAt = System.nanoTime();
+ JsonObject error = error(request(
+ 1,
+ "connect",
+ "{\"connection\":{\"connect_string\":\"127.0.0.1:1\",\"connection_timeout_ms\":15000}}"
+ ));
+ long elapsedMs = (System.nanoTime() - startedAt) / 1_000_000;
+
+ Assertions.assertTrue(
+ error.get("message").getAsString().contains("No reachable ZooKeeper server"),
+ "expected fast unreachable error, got: " + error.get("message").getAsString()
+ );
+ Assertions.assertTrue(elapsedMs < 4000, "expected fast failure, took " + elapsedMs + "ms");
+ }
+
+ @Test
+ void connectUsesReachableServerWithoutDroppingEnsembleMembers() throws Exception {
+ try (TestingServer server = new TestingServer()) {
+ JsonObject connect = result(request(
+ 1,
+ "connect",
+ "{\"connection\":{\"connect_string\":\"127.0.0.1:1," + server.getConnectString() + "\"}}"
+ ));
+ Assertions.assertTrue(connect.get("ok").getAsBoolean());
+
+ JsonObject get = result(request(2, "kv_get", "{\"key\":\"/\"}"));
+ Assertions.assertTrue(get.get("found").getAsBoolean());
+ }
+ }
+
+ @Test
+ void reachableConnectStringPreservesFullEnsembleAndChroot() throws Exception {
+ try (TestingServer server = new TestingServer()) {
+ String alive = server.getConnectString();
+ String ensemble = "127.0.0.1:1," + alive + "/app";
+
+ Assertions.assertEquals(
+ ensemble,
+ ZooKeeperAgent.reachableConnectString(ensemble, 1000)
+ );
+ Assertions.assertEquals(alive, ZooKeeperAgent.reachableConnectString(alive, 1000));
+
+ IllegalStateException error = Assertions.assertThrows(
+ IllegalStateException.class,
+ () -> ZooKeeperAgent.reachableConnectString("127.0.0.1:1/app", 1000)
+ );
+ Assertions.assertTrue(error.getMessage().contains("No reachable ZooKeeper server"));
+ }
+ }
+
@Test
void testConnectionDoesNotReplaceActiveClient() throws Exception {
try (TestingServer active = new TestingServer(); TestingServer probe = new TestingServer()) {
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index 82a2be0ca3..c9d7ef80b0 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -78,6 +78,7 @@ import { assessProductionSql } from "@/lib/database/productionSafety";
import { executeWithProductionSqlGuard } from "@/lib/database/productionExecutionGuard";
import { buildHistoryAiAnalysisPrompt } from "@/lib/history/historyAiAnalysis";
import { countAvailableAgentDriverUpdates, type AgentDriverUpdateBadgeState } from "@/lib/connection/agentDriverUpdateBadge";
+import type { DriverStoreFocus } from "@/lib/connection/agentDriverInstallHint";
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage";
import { apiUrl, webPath } from "@/lib/common/webPath";
import { APP_FONT_SANS_CSS_VAR, DEFAULT_UI_FONT_FAMILY } from "@/lib/app/appFonts";
@@ -318,8 +319,18 @@ function closeSettingsPage() {
driverStoreActive.value = false;
}
-function openDriverStorePage(tab?: "agent" | "jdbc" | "storage" | "runtime") {
- if (tab) driverStoreActiveTab.value = tab;
+const driverStoreFocus = ref<DriverStoreFocus | null>(null);
+
+function openDriverStorePage(target?: "agent" | "jdbc" | "storage" | "runtime" | DriverStoreFocus | null) {
+ if (typeof target === "string") {
+ driverStoreActiveTab.value = target;
+ driverStoreFocus.value = null;
+ } else if (target && target.target === "tab") {
+ driverStoreActiveTab.value = target.tab;
+ driverStoreFocus.value = null;
+ } else {
+ driverStoreFocus.value = target ?? null;
+ }
driverStoreTabOpen.value = true;
driverStoreActive.value = true;
settingsStore.settingsPageActive = false;
@@ -329,6 +340,7 @@ function closeDriverStorePage() {
driverStoreTabOpen.value = false;
driverStoreActive.value = false;
driverStoreActiveTab.value = "agent";
+ driverStoreFocus.value = null;
}
const toolbarAgentDriverUpdateCount = computed(() => (updateNotificationsEnabled.value ? agentDriverUpdateCount.value : 0));
const toolbarHasUpdateAvailable = computed(() => updateNotificationsEnabled.value && hasUpdateAvailable.value);
@@ -1739,8 +1751,8 @@ function handleContextMenu(e: MouseEvent) {
e.preventDefault();
}
-function openDriverStoreFromEvent() {
- openDriverStorePage();
+function openDriverStoreFromEvent(event: Event) {
+ openDriverStorePage(((event as CustomEvent).detail as DriverStoreFocus | undefined) ?? null);
}
function runUpdateNotificationChecks() {
@@ -1909,7 +1921,7 @@ onUnmounted(() => {
@discard-all-tab-close="handleDiscardAllPendingTabClose"
@cancel-tab-close="cancelPendingAppClose"
/>
- <DriverStorePage v-if="driverStoreTabOpen" v-show="driverStoreActive" v-model:active-tab="driverStoreActiveTab" class="flex-1 min-h-0" :update-notifications-enabled="updateNotificationsEnabled" @update-count-change="updateAgentDriverUpdateCount" />
+ <DriverStorePage v-if="driverStoreTabOpen" v-show="driverStoreActive" v-model:active-tab="driverStoreActiveTab" class="flex-1 min-h-0" :update-notifications-enabled="updateNotificationsEnabled" :focus-target="driverStoreFocus" @update-count-change="updateAgentDriverUpdateCount" />
<EditorSettingsPage
v-if="settingsPageTabOpen"
v-show="settingsStore.settingsPageActive"
diff --git a/apps/desktop/src/components/config/DriverStoreDialog.vue b/apps/desktop/src/components/config/DriverStoreDialog.vue
index 546661cf62..254aa8379a 100644
--- a/apps/desktop/src/components/config/DriverStoreDialog.vue
+++ b/apps/desktop/src/components/config/DriverStoreDialog.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { ref, onMounted, onUnmounted, computed, watch } from "vue";
+import { ref, onMounted, onUnmounted, computed, watch, nextTick } from "vue";
import { useI18n } from "vue-i18n";
import { Activity, ExternalLink, Cpu, FolderOpen, FolderSync, MemoryStick, Search, Square, Trash2, Download, RotateCcw, Loader2, RefreshCw, Check, Clock3, FileUp } from "@lucide/vue";
import { Button } from "@/components/ui/button";
@@ -20,6 +20,7 @@ import type { AgentDriverInfo, DriverRuntimeInfo, DriverRuntimeSummary, DriverSt
import { formatRuntimeBytes, formatRuntimeCpu, formatRuntimeUptime, runtimeHealthClass, runtimeStatusClass, runtimeStatusDotClass } from "@/lib/connection/driverRuntimePresentation";
import { addDriverInstallQueue, driverInstallProgressPercent, isDriverInstallProgressTarget, removeDriverInstallQueue, takeNextDriverInstallQueue, type DriverInstallProgress } from "@/lib/connection/driverInstallProgressUi";
import { PRESTOSQL_DRIVER_DB_TYPE, prestoSqlBuiltinDriverRow, prestoSqlMavenBundle } from "@/lib/database/prestoSqlBuiltinDriver";
+import type { DriverStoreFocus } from "@/lib/connection/agentDriverInstallHint";
const { t } = useI18n();
const { toast } = useToast();
@@ -29,10 +30,12 @@ const props = withDefaults(
defineProps<{
updateNotificationsEnabled?: boolean;
activeTab?: "agent" | "jdbc" | "storage" | "runtime";
+ focusTarget?: DriverStoreFocus | null;
}>(),
{
updateNotificationsEnabled: true,
activeTab: "agent",
+ focusTarget: null,
},
);
@@ -664,6 +667,35 @@ const filteredAgentDrivers = computed(() => {
return builtinDriverRows.value.filter((driver) => [driver.label, driver.db_type, driver.version, driver.installed_version, driverRequiresJavaRuntime(driver) ? driver.jre : ""].filter(Boolean).join(" ").toLowerCase().includes(query));
});
+const highlightedFocusKey = ref<string | null>(null);
+let focusHighlightTimer: ReturnType<typeof setTimeout> | undefined;
+
+function focusElementKey(focus: DriverStoreFocus): string {
+ return focus.target === "driver" ? `driver:${focus.driver ?? ""}` : "jre";
+}
+
+watch(
+ [() => props.focusTarget, builtinDriverRows],
+ async ([focus]) => {
+ if (!focus || focus.target === "tab") return;
+ driverStoreTab.value = "agent";
+ if (focus.target === "driver") {
+ // Wait until the requested driver row is loaded before scrolling to it.
+ if (!focus.driver || !builtinDriverRows.value.some((driver) => driver.db_type === focus.driver)) return;
+ agentDriverSearch.value = "";
+ }
+ const key = focusElementKey(focus);
+ highlightedFocusKey.value = key;
+ await nextTick();
+ document.querySelector(`[data-driver-store-focus="${CSS.escape(key)}"]`)?.scrollIntoView({ block: "center", behavior: "smooth" });
+ clearTimeout(focusHighlightTimer);
+ focusHighlightTimer = setTimeout(() => {
+ if (highlightedFocusKey.value === key) highlightedFocusKey.value = null;
+ }, 6000);
+ },
+ { immediate: true },
+);
+
const jdbcDriverListItems = computed<JdbcDriverListItem[]>(() => {
const localBundleItems = jdbcLocalBundles.value.map((bundle) => ({
kind: "local" as const,
@@ -1099,7 +1131,7 @@ watch(driverStoreTab, (tab) => {
<!-- Agent Tab -->
<TabsContent value="agent" class="driver-store-tab driver-store-agent-tab mt-5 space-y-5">
<!-- Java Runtime -->
- <div class="rounded-xl border bg-muted/20 p-4 space-y-3">
+ <div class="rounded-xl border bg-muted/20 p-4 space-y-3" data-driver-store-focus="jre" :class="{ 'driver-store-focus-highlight': highlightedFocusKey === 'jre' }">
<div class="flex flex-wrap items-center gap-2">
<Label class="shrink-0">{{ t("driverStore.javaRuntime") }}</Label>
<Select :model-value="javaRuntimeConfig.mode" @update:model-value="setJavaRuntimeMode">
@@ -1173,7 +1205,13 @@ watch(driverStoreTab, (tab) => {
{{ upgradingAll ? t("driverStore.upgradingProgress", { current: upgradingIndex, total: upgradingTotal }) : t("driverStore.upgradeAll") }}
</Button>
</div>
- <div v-for="driver in filteredAgentDrivers" :key="driver.db_type" class="driver-store-agent-row flex items-center gap-3 px-4 py-2 transition hover:bg-muted/30">
+ <div
+ v-for="driver in filteredAgentDrivers"
+ :key="driver.db_type"
+ :data-driver-store-focus="`driver:${driver.db_type}`"
+ class="driver-store-agent-row flex items-center gap-3 px-4 py-2 transition hover:bg-muted/30"
+ :class="{ 'driver-store-focus-highlight': highlightedFocusKey === `driver:${driver.db_type}` }"
+ >
<span class="flex h-8 w-8 items-center justify-center rounded-lg bg-muted/60 shrink-0">
<DatabaseIcon :db-type="driver.db_type" class="h-4 w-4" />
</span>
@@ -1541,6 +1579,12 @@ watch(driverStoreTab, (tab) => {
</template>
<style>
+.driver-store-focus-highlight {
+ background-color: hsl(var(--primary) / 0.08);
+ box-shadow: inset 0 0 0 1.5px hsl(var(--primary) / 0.45);
+ border-radius: 8px;
+}
+
.driver-store-view,
.driver-store-scroll {
overflow-x: hidden;
diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue
index 46208e298f..86526eb3fc 100644
--- a/apps/desktop/src/components/connection/ConnectionDialog.vue
+++ b/apps/desktop/src/components/connection/ConnectionDialog.vue
@@ -36,7 +36,7 @@ import { MQ_PINNED_VERSION_OPTIONS, pinnedVersionToSelection, selectionToPinnedV
import { mongodbAuthFailureHint, mongoUrlParam, mongoUrlParamIsTrue, normalizeMongoTlsFormState, setMongoUrlParam, setMongoUrlParamBoolean } from "@/lib/mongo/mongoConnectionOptions";
import { mysqlCleartextPasswordAuthEnabled, setMysqlCleartextPasswordAuthEnabled } from "@/lib/database/mysqlConnectionOptions";
import { copyToClipboard } from "@/lib/common/clipboard";
-import { agentDriverInstallKey, appendAgentDriverUpdateHint, hasAgentDriverUpdate, showAgentDriverInstallHint, type AgentDriverInstallState } from "@/lib/connection/agentDriverInstallHint";
+import { agentDriverInstallKey, appendAgentDriverUpdateHint, hasAgentDriverUpdate, showAgentDriverInstallHint, type AgentDriverInstallState, type DriverStoreFocus } from "@/lib/connection/agentDriverInstallHint";
import { prestoSqlBuiltinDriverPaths } from "@/lib/database/prestoSqlBuiltinDriver";
import { SQLITE_DATABASE_FILE_EXTENSIONS } from "@/lib/database/databaseFileDetection";
import { connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs } from "@/lib/connection/connectionAttemptTimeout";
@@ -117,7 +117,7 @@ const emit = defineEmits<{
connectStarted: [name: string];
connectSucceeded: [name: string];
connectFailed: [message: string];
- openDriverStore: [tab?: "jdbc"];
+ openDriverStore: [focus?: DriverStoreFocus];
openTunnelProfileSettings: [];
}>();
@@ -1958,6 +1958,7 @@ const zookeeperConnectString = computed({
const canUseTransportLayers = computed(() => form.value.db_type !== "sqlite" && form.value.db_type !== "access" && !isCloudflareD1Connection(form.value) && !isH2FileMode.value);
const shouldShowAgentDriverInstallHint = computed(() => showAgentDriverInstallHint(form.value.db_type, agentDrivers.value, form.value.driver_profile));
const h2DriverMissing = computed(() => form.value.db_type === "h2" && isH2FileMode.value && agentDrivers.value.find((d) => d.db_type === "h2")?.installed !== true);
+const agentDriverFocus = computed<DriverStoreFocus>(() => ({ target: "driver", driver: agentDriverInstallKey(form.value.db_type, form.value.driver_profile) }));
const canChooseVisibleDatabases = computed(() => connectionCanChooseVisibleDatabases(form.value));
const visibleFilterUsesSchemas = computed(() => connectionUsesVisibleSchemaFilter(form.value));
const hasVisibleDatabaseFilter = computed(() => Array.isArray(form.value.visible_databases));
@@ -4055,7 +4056,7 @@ function openExternalUrl(url: string) {
<div v-if="h2DriverMissing" class="grid grid-cols-4 items-center gap-4">
<span />
<p class="col-span-3 text-xs text-muted-foreground">
- {{ t("connection.driverInstallHintPrefix") }}<a class="underline cursor-pointer text-primary hover:text-primary/80" @click="emit('openDriverStore')">{{ t("toolbar.driverManager") }}</a
+ {{ t("connection.driverInstallHintPrefix") }}<a class="underline cursor-pointer text-primary hover:text-primary/80" @click="emit('openDriverStore', agentDriverFocus)">{{ t("toolbar.driverManager") }}</a
>{{ t("connection.driverInstallHintSuffix") }}
</p>
</div>
@@ -4135,7 +4136,7 @@ function openExternalUrl(url: string) {
{{ t("connection.jdbcPluginHint") }}
</p>
<div class="flex flex-wrap gap-2">
- <Button type="button" variant="outline" size="sm" @click="emit('openDriverStore', 'jdbc')">
+ <Button type="button" variant="outline" size="sm" @click="emit('openDriverStore', { target: 'tab', tab: 'jdbc' })">
<FolderOpen class="h-3.5 w-3.5" />
{{ t("toolbar.driverManager") }}
</Button>
@@ -4971,7 +4972,7 @@ function openExternalUrl(url: string) {
<div v-if="shouldShowAgentDriverInstallHint" class="grid grid-cols-4 items-center gap-4">
<span />
<p class="col-span-3 text-xs text-muted-foreground">
- {{ t("connection.driverInstallHintPrefix") }}<a class="underline cursor-pointer text-primary hover:text-primary/80" @click="emit('openDriverStore')">{{ t("toolbar.driverManager") }}</a
+ {{ t("connection.driverInstallHintPrefix") }}<a class="underline cursor-pointer text-primary hover:text-primary/80" @click="emit('openDriverStore', agentDriverFocus)">{{ t("toolbar.driverManager") }}</a
>{{ t("connection.driverInstallHintSuffix") }}
</p>
</div>
@@ -5060,7 +5061,7 @@ function openExternalUrl(url: string) {
{{ t("connection.jdbcPluginHint") }}
</p>
<div class="flex flex-wrap gap-2">
- <Button type="button" variant="outline" size="sm" @click="emit('openDriverStore', 'jdbc')">
+ <Button type="button" variant="outline" size="sm" @click="emit('openDriverStore', { target: 'tab', tab: 'jdbc' })">
<FolderOpen class="h-3.5 w-3.5" />
{{ t("toolbar.driverManager") }}
</Button>
diff --git a/apps/desktop/src/components/layout/AppDialogs.vue b/apps/desktop/src/components/layout/AppDialogs.vue
index 53a558f595..a050483823 100644
--- a/apps/desktop/src/components/layout/AppDialogs.vue
+++ b/apps/desktop/src/components/layout/AppDialogs.vue
@@ -21,6 +21,7 @@ import { useConnectionStore } from "@/stores/connectionStore";
import { useProductionSafetyStore } from "@/stores/productionSafetyStore";
import { useDialogSources } from "@/composables/useDialogSources";
import type { ConnectionDeepLinkDraft } from "@/lib/connection/connectionDeepLink";
+import type { DriverStoreFocus } from "@/lib/connection/agentDriverInstallHint";
import type { SqlParameterDescriptor, SqlParameterSyntax } from "@/lib/sql/sqlParameters";
import type { ConfigTab } from "@/components/connection/ConnectionDialog.vue";
import type { DatabaseType } from "@/types/database";
@@ -49,7 +50,7 @@ const emit = defineEmits<{
connectStarted: [name: string];
connectSucceeded: [name: string];
connectFailed: [message: string];
- openDriverStore: [tab?: "jdbc"];
+ openDriverStore: [focus?: DriverStoreFocus];
openTunnelProfileSettings: [];
openLineageTarget: [
target: {
diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vue
index d22df9bd40..c5858fbb5e 100644
--- a/apps/desktop/src/components/sidebar/TreeItem.vue
+++ b/apps/desktop/src/components/sidebar/TreeItem.vue
@@ -78,6 +78,7 @@ import { canTreeNodePin, canTreeNodeShowExpander, treeItemPaddingLeft, treeLabel
import { buildTableSelectSql } from "@/lib/table/tableSelectSql";
import { buildTableDeleteTemplate, buildTableInsertTemplate, buildTableSelectTemplate, buildTableUpdateTemplate } from "@/lib/table/tableSqlTemplates";
import { connectionFilePath, defaultSqliteBackupFileName, isMemorySqlitePath, sqliteBackupSourcePath } from "@/lib/connection/connectionFile";
+import { driverStoreFocusForInstallError } from "@/lib/connection/agentDriverInstallHint";
import { revealPathInFileManager } from "@/lib/backend/tauri";
import { clearActiveTableReferencePayload, createTableReferencePayload, createTableReferenceDropEvent, setActiveTableReferencePayload, type QueryEditorTableReferencePayload } from "@/lib/editor/queryEditorTableDrop";
import { usesSyntheticRowIdKey } from "@/lib/table/tableEditing";
@@ -813,9 +814,7 @@ async function toggle() {
const errMsg = e?.message || String(e);
if (errMsg.includes(CONNECTION_ATTEMPT_CANCELLED_MESSAGE)) return;
toast(t("connection.connectFailed", { message: translateBackendError(t, errMsg) }), 5000);
- if (errMsg.includes("driver is not installed") || errMsg.includes("is not installed")) {
- window.dispatchEvent(new Event("dbx-open-driver-store"));
- }
+ openDriverStoreForInstallError(errMsg);
}
}
@@ -854,6 +853,12 @@ function refreshActiveKvBrowserAfterOpen(mode: "etcd" | "zookeeper", connectionI
});
}
+function openDriverStoreForInstallError(errMsg: string) {
+ const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;
+ const focus = driverStoreFocusForInstallError(errMsg, config?.db_type, config?.driver_profile);
+ if (focus) window.dispatchEvent(new CustomEvent("dbx-open-driver-store", { detail: focus }));
+}
+
async function loadMoreObjectGroupChildren() {
try {
await connectionStore.loadMoreObjectGroupChildren(props.node);
@@ -1247,9 +1252,7 @@ async function openObjectBrowser() {
}
} catch (e: any) {
toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);
- if (e?.message?.includes("driver is not installed") || (e?.message?.includes("JRE") && e?.message?.includes("not installed"))) {
- window.dispatchEvent(new Event("dbx-open-driver-store"));
- }
+ openDriverStoreForInstallError(e?.message || String(e));
}
}
@@ -1611,9 +1614,7 @@ async function newQuery() {
queryStore.createTab(node.connectionId, resolveDefaultDatabase(connection, options), undefined, "query");
} catch (e: any) {
toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);
- if (e?.message?.includes("driver is not installed") || (e?.message?.includes("JRE") && e?.message?.includes("not installed"))) {
- window.dispatchEvent(new Event("dbx-open-driver-store"));
- }
+ openDriverStoreForInstallError(e?.message || String(e));
}
}
@@ -1787,9 +1788,7 @@ async function refresh() {
await connectionStore.refreshTreeNode(props.node);
} catch (e: any) {
toast(t("connection.connectFailed", { message: translateBackendError(t, e?.message || String(e)) }), 5000);
- if (e?.message?.includes("driver is not installed") || (e?.message?.includes("JRE") && e?.message?.includes("not installed"))) {
- window.dispatchEvent(new Event("dbx-open-driver-store"));
- }
+ openDriverStoreForInstallError(e?.message || String(e));
}
}
diff --git a/apps/desktop/src/lib/connection/__tests__/agentDriverInstallHint.spec.ts b/apps/desktop/src/lib/connection/__tests__/agentDriverInstallHint.spec.ts
new file mode 100644
index 0000000000..b9eb5c8352
--- /dev/null
+++ b/apps/desktop/src/lib/connection/__tests__/agentDriverInstallHint.spec.ts
@@ -0,0 +1,36 @@
+import { describe, expect, it } from "vitest";
+import { driverStoreFocusForInstallError } from "@/lib/connection/agentDriverInstallHint";
+
+describe("driverStoreFocusForInstallError", () => {
+ it("focuses the missing agent driver for driver-not-installed errors", () => {
+ expect(driverStoreFocusForInstallError("zookeeper driver is not installed. Please install it from the Driver Manager.", "zookeeper", undefined)).toEqual({
+ target: "driver",
+ driver: "zookeeper",
+ });
+ });
+
+ it("resolves the driver key from the driver profile", () => {
+ expect(driverStoreFocusForInstallError("kafka driver is not installed. Please install it from the Driver Manager.", "mq", "kafka")).toEqual({
+ target: "driver",
+ driver: "kafka",
+ });
+ });
+
+ it("focuses the JRE section for missing JRE errors", () => {
+ expect(driverStoreFocusForInstallError("JRE 21 runtime is not installed. Please install it from the Driver Manager.", "zookeeper", undefined)).toEqual({
+ target: "jre",
+ });
+ });
+
+ it("focuses the agent driver for corrupt-jar reinstall errors", () => {
+ expect(driverStoreFocusForInstallError("zookeeper driver jar is invalid or corrupt. Please reinstall it from the Driver Manager.", "zookeeper", undefined)).toEqual({
+ target: "driver",
+ driver: "zookeeper",
+ });
+ });
+
+ it("returns null for unrelated connection errors", () => {
+ expect(driverStoreFocusForInstallError("Connection timed out", "zookeeper", undefined)).toBeNull();
+ expect(driverStoreFocusForInstallError("No reachable ZooKeeper server within 2000ms: zk:2181", "zookeeper", undefined)).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/lib/connection/agentDriverInstallHint.ts b/apps/desktop/src/lib/connection/agentDriverInstallHint.ts
index 53c7ddd4c4..5e2de1e5fc 100644
--- a/apps/desktop/src/lib/connection/agentDriverInstallHint.ts
+++ b/apps/desktop/src/lib/connection/agentDriverInstallHint.ts
@@ -34,3 +34,14 @@ export function appendAgentDriverUpdateHint(message: string, hint: string): stri
if (message.includes(hint)) return message;
return `${message}\n\n${hint}`;
}
+
+export type DriverStoreTab = "agent" | "jdbc" | "storage" | "runtime";
+
+export type DriverStoreFocus = { target: "driver"; driver?: string } | { target: "jre" } | { target: "tab"; tab: DriverStoreTab };
+
+/** Maps a backend connect error to the Driver Store item that can fix it. */
+export function driverStoreFocusForInstallError(message: string, dbType?: DatabaseType, driverProfile?: string): DriverStoreFocus | null {
+ if (message.includes("JRE") && message.includes("not installed")) return { target: "jre" };
+ if (!message.includes("is not installed") && !message.includes("reinstall it from the Driver Manager")) return null;
+ return { target: "driver", driver: agentDriverInstallKey(dbType, driverProfile) };
+}
diff --git a/packages/app-tests/jdbcConnectionEntry.test.ts b/packages/app-tests/jdbcConnectionEntry.test.ts
index 85d82f066d..f687de5d18 100644
--- a/packages/app-tests/jdbcConnectionEntry.test.ts
+++ b/packages/app-tests/jdbcConnectionEntry.test.ts
@@ -28,7 +28,7 @@ test("opens driver management on the JDBC tab from JDBC connection settings", ()
const app = source("apps/desktop/src/App.vue");
const driverStore = source("apps/desktop/src/components/config/DriverStoreDialog.vue");
- assert.equal(connectionDialog.match(/emit\('openDriverStore', 'jdbc'\)/g)?.length, 2);
+ assert.equal(connectionDialog.match(/emit\('openDriverStore', \{ target: 'tab', tab: 'jdbc' \}\)/g)?.length, 2);
assert.match(appDialogs, /@open-driver-store="emit\('openDriverStore', \$event\)"/);
assert.match(app, /openDriverStorePage\(\$event\)/);
assert.match(app, /v-model:active-tab="driverStoreActiveTab"/);