Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Use 30s timeout for syncing schema and fetching migration history since it may take a while

天舟a507add087e8
diff --git a/frontend/src/components/DatabaseMigrationHistoryPanel.vue b/frontend/src/components/DatabaseMigrationHistoryPanel.vue
index 9f89af151e..501f72bbd6 100644
--- a/frontend/src/components/DatabaseMigrationHistoryPanel.vue
+++ b/frontend/src/components/DatabaseMigrationHistoryPanel.vue
@@ -1,6 +1,16 @@
<template>
<div class="flex flex-col space-y-4">
- <div class="text-lg leading-6 font-medium text-main">
+ <div
+ class="
+ flex flex-row
+ items-center
+ text-lg
+ leading-6
+ font-medium
+ text-main
+ space-x-2
+ "
+ >
Migration History
<button
v-if="allowEdit"
@@ -11,6 +21,9 @@
>
Establish new baseline
</button>
+ <div>
+ <BBSpin v-if="state.loading" :title="'Refreshing history ...'" />
+ </div>
</div>
<MigrationHistoryTable
v-if="state.migrationSetupStatus == 'OK'"
@@ -61,6 +74,7 @@ import { templateForType } from "../plugins";
interface LocalState {
migrationSetupStatus: MigrationSchemaStatus;
showBaselineModal: boolean;
+ loading: boolean;
}
export default {
@@ -83,21 +97,33 @@ export default {
const state = reactive<LocalState>({
migrationSetupStatus: "OK",
showBaselineModal: false,
+ loading: false,
});
const currentUser = computed(() => store.getters["auth/currentUser"]());
const prepareMigrationHistoryList = () => {
+ state.loading = true;
store
.dispatch("instance/checkMigrationSetup", props.database.instance.id)
.then((migration: InstanceMigration) => {
state.migrationSetupStatus = migration.status;
if (state.migrationSetupStatus == "OK") {
- store.dispatch("instance/fetchMigrationHistory", {
- instanceId: props.database.instance.id,
- databaseName: props.database.name,
- });
+ store
+ .dispatch("instance/fetchMigrationHistory", {
+ instanceId: props.database.instance.id,
+ databaseName: props.database.name,
+ })
+ .then(() => {
+ state.loading = false;
+ })
+ .catch(() => {
+ state.loading = false;
+ });
}
+ })
+ .catch(() => {
+ state.loading = false;
});
};
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index cafdfdf9d0..a934070f7f 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -11,6 +11,7 @@ import {
InstanceMigration,
InstancePatch,
InstanceState,
+ INSTANCE_OPERATION_TIMEOUT,
MigrationHistory,
MigrationHistoryId,
ResourceIdentifier,
@@ -21,9 +22,6 @@ import {
} from "../../types";
import { InstanceUser } from "../../types/InstanceUser";
-// Create migration schema might take a while (e.g TiDB)
-const CREATE_MIGRATION_SCHEMA_TIMEOUT = 30000;
-
function convert(
instance: ResourceObject,
includedList: ResourceObject[],
@@ -242,7 +240,7 @@ const actions = {
},
},
{
- timeout: CREATE_MIGRATION_SCHEMA_TIMEOUT,
+ timeout: INSTANCE_OPERATION_TIMEOUT,
}
)
).data;
@@ -276,7 +274,7 @@ const actions = {
},
},
{
- timeout: CREATE_MIGRATION_SCHEMA_TIMEOUT,
+ timeout: INSTANCE_OPERATION_TIMEOUT,
}
)
).data;
@@ -320,7 +318,9 @@ const actions = {
instanceId: InstanceId
): Promise<InstanceMigration> {
const data = (
- await axios.get(`/api/instance/${instanceId}/migration/status`)
+ await axios.get(`/api/instance/${instanceId}/migration/status`, {
+ timeout: INSTANCE_OPERATION_TIMEOUT,
+ })
).data.data;
return {
@@ -335,7 +335,7 @@ const actions = {
): Promise<SqlResultSet> {
const data = (
await axios.post(`/api/instance/${instanceId}/migration`, undefined, {
- timeout: CREATE_MIGRATION_SCHEMA_TIMEOUT,
+ timeout: INSTANCE_OPERATION_TIMEOUT,
})
).data.data;
@@ -354,7 +354,10 @@ const actions = {
) {
const data = (
await axios.get(
- `/api/instance/${instanceId}/migration/history/${migrationHistoryId}`
+ `/api/instance/${instanceId}/migration/history/${migrationHistoryId}`,
+ {
+ timeout: INSTANCE_OPERATION_TIMEOUT,
+ }
)
).data;
const migrationHistory = convertMigrationHistory(data.data);
@@ -380,7 +383,10 @@ const actions = {
) {
const data = (
await axios.get(
- `/api/instance/${instanceId}/migration/history?database=${databaseName}&version=${version}`
+ `/api/instance/${instanceId}/migration/history?database=${databaseName}&version=${version}`,
+ {
+ timeout: INSTANCE_OPERATION_TIMEOUT,
+ }
)
).data.data;
const historyList = data.map((history: ResourceObject) => {
@@ -415,7 +421,11 @@ const actions = {
if (limit) {
url += `&limit=${limit}`;
}
- const data = (await axios.get(url)).data.data;
+ const data = (
+ await axios.get(url, {
+ timeout: INSTANCE_OPERATION_TIMEOUT,
+ })
+ ).data.data;
const historyList = data.map((history: ResourceObject) => {
return convertMigrationHistory(history);
});
diff --git a/frontend/src/store/modules/sql.ts b/frontend/src/store/modules/sql.ts
index 447ed51c79..0ee0bf89e8 100644
--- a/frontend/src/store/modules/sql.ts
+++ b/frontend/src/store/modules/sql.ts
@@ -2,6 +2,7 @@ import axios from "axios";
import {
ConnectionInfo,
InstanceId,
+ INSTANCE_OPERATION_TIMEOUT,
ResourceObject,
SqlResultSet,
} from "../../types";
@@ -35,14 +36,20 @@ const actions = {
},
async syncSchema({ dispatch }: any, instanceId: InstanceId) {
const data = (
- await axios.post(`/api/sql/syncschema`, {
- data: {
- type: "sqlSyncSchema",
- attributes: {
- instanceId,
+ await axios.post(
+ `/api/sql/syncschema`,
+ {
+ data: {
+ type: "sqlSyncSchema",
+ attributes: {
+ instanceId,
+ },
},
},
- })
+ {
+ timeout: INSTANCE_OPERATION_TIMEOUT,
+ }
+ )
).data.data;
const resultSet = convert(data);
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 0964e0a982..9981d4f7ec 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -41,6 +41,12 @@ export const POST_CHANGE_POLL_INTERVAL = 1000;
// Add jitter to avoid timer from different clients converging to the same polling frequency.
export const POLL_JITTER = 5000;
+// It may take a while to perform instance related operations since we are
+// connecting the remote instance. And certain operations just take longer for
+// a particular database type due to its unique property (e.g. create migration schema
+// is a heavier operation in TiDB than traditional RDBMS).
+export const INSTANCE_OPERATION_TIMEOUT = 30000;
+
// RowStatus
export type RowStatus = "NORMAL" | "ARCHIVED";
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index 62b6c701ee..dfabe33033 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -28,7 +28,10 @@
}
"
/>
- <div class="flex space-x-4">
+ <div class="flex items-center space-x-4">
+ <div>
+ <BBSpin v-if="state.syncingSchema" :title="'Syncing ...'" />
+ </div>
<button
v-if="allowEdit"
type="button"
@@ -142,6 +145,7 @@ interface LocalState {
showCreateMigrationSchemaModal: boolean;
creatingMigrationSchema: boolean;
showCreateDatabaseModal: boolean;
+ syncingSchema: boolean;
}
export default {
@@ -171,6 +175,7 @@ export default {
showCreateMigrationSchemaModal: false,
creatingMigrationSchema: false,
showCreateDatabaseModal: false,
+ syncingSchema: false,
});
const instance = computed((): Instance => {
@@ -342,9 +347,11 @@ export default {
};
const syncSchema = () => {
+ state.syncingSchema = true;
store
.dispatch("sql/syncSchema", instance.value.id)
.then((resultSet: SqlResultSet) => {
+ state.syncingSchema = false;
if (resultSet.error) {
store.dispatch("notification/pushNotification", {
module: "bytebase",
@@ -360,6 +367,9 @@ export default {
description: resultSet.error,
});
}
+ })
+ .catch(() => {
+ state.syncingSchema = false;
});
};