From 10ed931ea942b3cda293ea88caae9da9ef1442e1 Mon Sep 17 00:00:00 2001 From: limbo <43649186+HUAHUAI23@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:52:41 +0800 Subject: [PATCH] chore(web&server): database repair, rollback on dependency restart... (#2017) * fix(web): adjust transparency of the overlay for application startup logs * chore(web): Optimize log display logic * chore(web): fix bouns display * chore(web&server): database repair, rollback on dependency restart... --------- Co-authored-by: HUAHUAI23 Co-authored-by: GH Action - Upstream Sync --- .../dedicated-database.service.ts | 3 ++- server/src/dependency/dependency.service.ts | 21 ++++++++----------- .../initializer/deploy-manifest/database.yaml | 2 +- server/src/instance/instance-task.service.ts | 6 +++--- .../SysSetting/DatabaseMonitor/index.tsx | 2 ++ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/server/src/database/dedicated-database/dedicated-database.service.ts b/server/src/database/dedicated-database/dedicated-database.service.ts index 2379fda632..9dd903bf40 100644 --- a/server/src/database/dedicated-database/dedicated-database.service.ts +++ b/server/src/database/dedicated-database/dedicated-database.service.ts @@ -137,7 +137,7 @@ export class DedicatedDatabaseService { limitMemory, requestCPU, requestMemory, - capacity, + capacity: capacity / 1024, replicas, }) @@ -200,6 +200,7 @@ export class DedicatedDatabaseService { options: { authSource: 'admin', replicaSet: `${name}-mongodb`, + readPreference: 'secondaryPreferred', w: 'majority', }, scheme: 'mongodb', diff --git a/server/src/dependency/dependency.service.ts b/server/src/dependency/dependency.service.ts index 1083548f95..4419f03d22 100644 --- a/server/src/dependency/dependency.service.ts +++ b/server/src/dependency/dependency.service.ts @@ -55,14 +55,13 @@ export class DependencyService { const new_deps = dto.map((dep) => `${dep.name}@${dep.spec}`) const deps = extras.concat(new_deps) - const res = await this.db + await this.db .collection('ApplicationConfiguration') - .findOneAndUpdate( + .updateOne( { appid }, { $set: { dependencies: deps, updatedAt: new Date() } }, - { returnDocument: 'after' }, ) - await this.confService.publish(res.value) + return true } @@ -87,14 +86,13 @@ export class DependencyService { const deps = filtered.concat(new_deps) - const res = await this.db + await this.db .collection('ApplicationConfiguration') - .findOneAndUpdate( + .updateOne( { appid }, { $set: { dependencies: deps, updatedAt: new Date() } }, - { returnDocument: 'after' }, ) - await this.confService.publish(res.value) + return true } @@ -107,14 +105,13 @@ export class DependencyService { if (filtered.length === deps.length) return false - const res = await this.db + await this.db .collection('ApplicationConfiguration') - .findOneAndUpdate( + .updateOne( { appid }, { $set: { dependencies: filtered, updatedAt: new Date() } }, - { returnDocument: 'after' }, ) - await this.confService.publish(res.value) + return true } diff --git a/server/src/initializer/deploy-manifest/database.yaml b/server/src/initializer/deploy-manifest/database.yaml index 90a20d2645..8c668cd33b 100644 --- a/server/src/initializer/deploy-manifest/database.yaml +++ b/server/src/initializer/deploy-manifest/database.yaml @@ -38,6 +38,6 @@ spec: - ReadWriteOnce resources: requests: - storage: <%- capacity %>Mi + storage: <%- capacity %>Gi terminationPolicy: Delete tolerations: [] diff --git a/server/src/instance/instance-task.service.ts b/server/src/instance/instance-task.service.ts index 8903796f9e..e5ec0d317b 100644 --- a/server/src/instance/instance-task.service.ts +++ b/server/src/instance/instance-task.service.ts @@ -130,9 +130,6 @@ export class InstanceTaskService { return } - // create instance - await this.instanceService.create(app.appid) - const appid = app.appid const ddb = await this.dedicatedDatabaseService.findOne(appid) @@ -152,6 +149,9 @@ export class InstanceTaskService { } } + // create instance + await this.instanceService.create(app.appid) + const instance = await this.instanceService.get(appid) const unavailable = instance.deployment?.status?.unavailableReplicas || false diff --git a/web/src/pages/app/setting/SysSetting/DatabaseMonitor/index.tsx b/web/src/pages/app/setting/SysSetting/DatabaseMonitor/index.tsx index d6be22e590..6f689ec78d 100644 --- a/web/src/pages/app/setting/SysSetting/DatabaseMonitor/index.tsx +++ b/web/src/pages/app/setting/SysSetting/DatabaseMonitor/index.tsx @@ -66,7 +66,9 @@ export default function DatabaseMonitor() { metric: Record; values: Array<[number, string]>; }[] = resourceData?.data?.memory; + const podList = useMemo(() => { + if (!cpuData || !memoryData) return []; const cpuPods = cpuData.map((item) => item.metric.pod); const memoryPods = memoryData.map((item) => item.metric.pod);