Skip to content

Commit

Permalink
Fix Backup info size display
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <[email protected]>
  • Loading branch information
haiodo committed Dec 24, 2024
1 parent b5166df commit 71c7f5b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface DocChunk {
idx: number
// _id => hash mapping
docs: DocInfo[]

size?: number // Estimated size of the chunk data
finished: boolean
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import type { WorkspaceIdWithUrl } from './utils'
export interface DocInfo {
id: string
hash: string

size?: number
}
/**
* @public
Expand Down
12 changes: 9 additions & 3 deletions plugins/login-resources/src/components/AdminWorkspaces.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { groupByArray, type BaseWorkspaceInfo } from '@hcengineering/core'
import { groupByArray, isActiveMode, type BaseWorkspaceInfo } from '@hcengineering/core'
import { getEmbeddedLabel } from '@hcengineering/platform'
import { isAdminUser } from '@hcengineering/presentation'
import {
Expand Down Expand Up @@ -84,6 +84,9 @@
{#if isAdmin}
<div class="anticrm-panel flex-row flex-grow p-5">
<div class="fs-title p-3">Workspaces administration panel</div>
<div class="fs-title p-3">
Workspaces: {workspaces.length} active: {workspaces.filter((it) => isActiveMode(it.mode)).length}
</div>
<div class="fs-title p-3 flex-no-shrink">
<SearchEdit bind:value={search} width={'100%'} />
</div>
Expand Down Expand Up @@ -174,7 +177,7 @@
</span>

<span class="label overflow-label" style:width={'10rem'}>
{workspace.mode}
{workspace.mode ?? '-'}
</span>

<span class="label overflow-label" style:width={'2rem'}>
Expand All @@ -191,7 +194,10 @@
</span>
<span class="flex flex-between" style:width={'5rem'}>
{#if workspace.backupInfo != null}
{@const sz = workspace.backupInfo.dataSize + workspace.backupInfo.blobsSize}
{@const sz = Math.max(
workspace.backupInfo.backupSize,
workspace.backupInfo.dataSize + workspace.backupInfo.blobsSize
)}
{@const szGb = Math.round((sz * 100) / 1024) / 100}
{#if szGb > 0}
{Math.round((sz * 100) / 1024) / 100}Gb
Expand Down
1 change: 1 addition & 0 deletions plugins/login-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function getWorkspaceSize (it: Pick<Workspace, 'backupInfo'>): number {
let sz = 0
sz += it.backupInfo?.dataSize ?? 0
sz += it.backupInfo?.blobsSize ?? 0
sz += it.backupInfo?.backupSize ?? 0
return sz
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@
{#if isAdmin && ws.lastVisit != null && ws.lastVisit !== 0}
<div class="text-sm">
{#if ws.backupInfo != null}
{@const sz = ws.backupInfo.dataSize + ws.backupInfo.blobsSize}
{@const sz = Math.max(
ws.backupInfo.backupSize,
ws.backupInfo.dataSize + ws.backupInfo.blobsSize
)}
{@const szGb = Math.round((sz * 100) / 1024) / 100}
{#if szGb > 0}
{Math.round((sz * 100) / 1024) / 100}Gb -
Expand Down
21 changes: 14 additions & 7 deletions server/backup/src/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,12 @@ export async function backup (
while (true) {
try {
const currentChunk = await ctx.with('loadChunk', {}, () => connection.loadChunk(domain, idx))
if (domain === DOMAIN_BLOB) {
result.blobsSize += currentChunk.size ?? 0
} else {
result.dataSize += currentChunk.size ?? 0
}

idx = currentChunk.idx
ops++

Expand Down Expand Up @@ -1152,12 +1158,6 @@ export async function backup (
break
}

if (domain === DOMAIN_BLOB) {
result.blobsSize += (d as Blob).size
} else {
result.dataSize += JSON.stringify(d).length
}

function processChanges (d: Doc, error: boolean = false): void {
processed++
// Move processed document to processedChanges
Expand Down Expand Up @@ -1777,13 +1777,15 @@ export async function restore (
let loaded = 0
let el = 0
let chunks = 0
let dataSize = 0
try {
while (true) {
if (opt.progress !== undefined) {
await opt.progress?.(domainProgress)
}
const st = Date.now()
const it = await connection.loadChunk(c, idx)
dataSize += it.size ?? 0
chunks++

idx = it.idx
Expand All @@ -1808,7 +1810,12 @@ export async function restore (
await connection.closeChunk(idx)
}
}
ctx.info('loaded', { loaded, workspace: workspaceId.name })
ctx.info('loaded', {
domain: c,
loaded,
workspace: workspaceId.name,
dataSize: Math.round((dataSize / (1024 * 1024)) * 100) / 100
})
ctx.info('\tcompare documents', {
size: changeset.size,
serverSize: serverChangeset.size,
Expand Down
7 changes: 6 additions & 1 deletion server/core/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class BackupClientOps {
return ctx.with('load-chunk', {}, async (ctx) => {
idx = idx ?? this.idIndex++
let chunk: ChunkInfo | undefined = this.chunkInfo.get(idx)
let size = 0
if (chunk !== undefined) {
chunk.index++
if (chunk.finished === undefined || chunk.finished) {
Expand All @@ -74,12 +75,16 @@ export class BackupClientOps {
break
}
docs.push(..._docs)
for (const d of _docs) {
size += d.size ?? 0
}
}

return {
idx,
docs,
finished: chunk.finished
finished: chunk.finished,
size
}
})
}
Expand Down

0 comments on commit 71c7f5b

Please sign in to comment.