UBERF-9025: Fix backup service (#7557)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-12-26 15:33:09 +07:00 committed by GitHub
parent d0af7a37cc
commit fb5df1681d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 72 additions and 54 deletions

View File

@ -62,9 +62,9 @@ import {
createBackupPipeline, createBackupPipeline,
getConfig, getConfig,
getWorkspaceDestroyAdapter, getWorkspaceDestroyAdapter,
registerAdapterFactry, registerAdapterFactory,
registerDestroyFactry, registerDestroyFactory,
registerTxAdapterFactry registerTxAdapterFactory
} from '@hcengineering/server-pipeline' } from '@hcengineering/server-pipeline'
import serverToken, { decodeToken, generateToken } from '@hcengineering/server-token' import serverToken, { decodeToken, generateToken } from '@hcengineering/server-token'
import { FileModelLogger } from '@hcengineering/server-tool' import { FileModelLogger } from '@hcengineering/server-tool'
@ -173,13 +173,13 @@ export function devTool (
): void { ): void {
const toolCtx = new MeasureMetricsContext('tool', {}) const toolCtx = new MeasureMetricsContext('tool', {})
registerTxAdapterFactry('mongodb', createMongoTxAdapter) registerTxAdapterFactory('mongodb', createMongoTxAdapter)
registerAdapterFactry('mongodb', createMongoAdapter) registerAdapterFactory('mongodb', createMongoAdapter)
registerDestroyFactry('mongodb', createMongoDestroyAdapter) registerDestroyFactory('mongodb', createMongoDestroyAdapter)
registerTxAdapterFactry('postgresql', createPostgresTxAdapter, true) registerTxAdapterFactory('postgresql', createPostgresTxAdapter, true)
registerAdapterFactry('postgresql', createPostgresAdapter, true) registerAdapterFactory('postgresql', createPostgresAdapter, true)
registerDestroyFactry('postgresql', createPostgreeDestroyAdapter, true) registerDestroyFactory('postgresql', createPostgreeDestroyAdapter, true)
const serverSecret = process.env.SERVER_SECRET const serverSecret = process.env.SERVER_SECRET
if (serverSecret === undefined) { if (serverSecret === undefined) {

View File

@ -81,7 +81,7 @@ export const storePromise = writable<Promise<void>>(new Promise((resolve) => {})
function fillStores (): void { function fillStores (): void {
const client = getClient() const client = getClient()
if (client !== undefined) { if (client !== undefined || getCurrentAccount() != null) {
const query = createQuery(true) const query = createQuery(true)
const roomPromise = new Promise<void>((resolve) => const roomPromise = new Promise<void>((resolve) =>
query.query(love.class.Room, {}, (res) => { query.query(love.class.Room, {}, (res) => {

View File

@ -60,6 +60,8 @@
"dotenv": "~16.0.0", "dotenv": "~16.0.0",
"@hcengineering/backup-service": "^0.6.0", "@hcengineering/backup-service": "^0.6.0",
"@hcengineering/analytics": "^0.6.0", "@hcengineering/analytics": "^0.6.0",
"@hcengineering/analytics-service": "^0.6.0" "@hcengineering/analytics-service": "^0.6.0",
"@hcengineering/mongo": "^0.6.1",
"@hcengineering/postgres": "^0.6.0"
} }
} }

View File

@ -18,10 +18,18 @@ import { configureAnalytics, SplitLogger } from '@hcengineering/analytics-servic
import { startBackup } from '@hcengineering/backup-service' import { startBackup } from '@hcengineering/backup-service'
import { MeasureMetricsContext, newMetrics, type Tx } from '@hcengineering/core' import { MeasureMetricsContext, newMetrics, type Tx } from '@hcengineering/core'
import { initStatisticsContext, type PipelineFactory } from '@hcengineering/server-core' import { initStatisticsContext, type PipelineFactory } from '@hcengineering/server-core'
import { createBackupPipeline, getConfig } from '@hcengineering/server-pipeline' import {
createBackupPipeline,
getConfig,
registerAdapterFactory,
registerDestroyFactory,
registerTxAdapterFactory
} from '@hcengineering/server-pipeline'
import { join } from 'path' import { join } from 'path'
import { readFileSync } from 'node:fs' import { readFileSync } from 'node:fs'
import { createMongoTxAdapter, createMongoAdapter, createMongoDestroyAdapter } from '@hcengineering/mongo'
import { createPostgresTxAdapter, createPostgresAdapter, createPostgreeDestroyAdapter } from '@hcengineering/postgres'
const model = JSON.parse(readFileSync(process.env.MODEL_JSON ?? 'model.json').toString()) as Tx[] const model = JSON.parse(readFileSync(process.env.MODEL_JSON ?? 'model.json').toString()) as Tx[]
const metricsContext = initStatisticsContext('backup', { const metricsContext = initStatisticsContext('backup', {
@ -43,6 +51,14 @@ const sentryDSN = process.env.SENTRY_DSN
configureAnalytics(sentryDSN, {}) configureAnalytics(sentryDSN, {})
Analytics.setTag('application', 'backup-service') Analytics.setTag('application', 'backup-service')
registerTxAdapterFactory('mongodb', createMongoTxAdapter)
registerAdapterFactory('mongodb', createMongoAdapter)
registerDestroyFactory('mongodb', createMongoDestroyAdapter)
registerTxAdapterFactory('postgresql', createPostgresTxAdapter, true)
registerAdapterFactory('postgresql', createPostgresAdapter, true)
registerDestroyFactory('postgresql', createPostgreeDestroyAdapter, true)
startBackup( startBackup(
metricsContext, metricsContext,
(mongoUrl, storageAdapter) => { (mongoUrl, storageAdapter) => {

View File

@ -47,11 +47,11 @@ import serverCore, {
import { FullTextIndexPipeline, searchFulltext, type FulltextDBConfiguration } from '@hcengineering/server-indexer' import { FullTextIndexPipeline, searchFulltext, type FulltextDBConfiguration } from '@hcengineering/server-indexer'
import { import {
getConfig, getConfig,
registerAdapterFactry, registerAdapterFactory,
registerDestroyFactry, registerDestroyFactory,
registerServerPlugins, registerServerPlugins,
registerStringLoaders, registerStringLoaders,
registerTxAdapterFactry registerTxAdapterFactory
} from '@hcengineering/server-pipeline' } from '@hcengineering/server-pipeline'
import serverToken, { decodeToken, generateToken, type Token } from '@hcengineering/server-token' import serverToken, { decodeToken, generateToken, type Token } from '@hcengineering/server-token'
import cors from '@koa/cors' import cors from '@koa/cors'
@ -207,13 +207,13 @@ export async function startIndexer (
setMetadata(serverCore.metadata.ElasticIndexName, opt.elasticIndexName) setMetadata(serverCore.metadata.ElasticIndexName, opt.elasticIndexName)
setMetadata(serverClientPlugin.metadata.Endpoint, opt.accountsUrl) setMetadata(serverClientPlugin.metadata.Endpoint, opt.accountsUrl)
registerTxAdapterFactry('mongodb', createMongoTxAdapter) registerTxAdapterFactory('mongodb', createMongoTxAdapter)
registerAdapterFactry('mongodb', createMongoAdapter) registerAdapterFactory('mongodb', createMongoAdapter)
registerDestroyFactry('mongodb', createMongoDestroyAdapter) registerDestroyFactory('mongodb', createMongoDestroyAdapter)
registerTxAdapterFactry('postgresql', createPostgresTxAdapter, true) registerTxAdapterFactory('postgresql', createPostgresTxAdapter, true)
registerAdapterFactry('postgresql', createPostgresAdapter, true) registerAdapterFactory('postgresql', createPostgresAdapter, true)
registerDestroyFactry('postgresql', createPostgreeDestroyAdapter, true) registerDestroyFactory('postgresql', createPostgreeDestroyAdapter, true)
registerServerPlugins() registerServerPlugins()
registerStringLoaders() registerStringLoaders()

View File

@ -35,11 +35,11 @@ import { type Token } from '@hcengineering/server-token'
import { import {
createServerPipeline, createServerPipeline,
registerAdapterFactry, registerAdapterFactory,
registerDestroyFactry, registerDestroyFactory,
registerServerPlugins, registerServerPlugins,
registerStringLoaders, registerStringLoaders,
registerTxAdapterFactry registerTxAdapterFactory
} from '@hcengineering/server-pipeline' } from '@hcengineering/server-pipeline'
import { readFileSync } from 'node:fs' import { readFileSync } from 'node:fs'
@ -74,13 +74,13 @@ export function start (
mongoUrl?: string mongoUrl?: string
} }
): { shutdown: () => Promise<void>, sessionManager: SessionManager } { ): { shutdown: () => Promise<void>, sessionManager: SessionManager } {
registerTxAdapterFactry('mongodb', createMongoTxAdapter) registerTxAdapterFactory('mongodb', createMongoTxAdapter)
registerAdapterFactry('mongodb', createMongoAdapter) registerAdapterFactory('mongodb', createMongoAdapter)
registerDestroyFactry('mongodb', createMongoDestroyAdapter) registerDestroyFactory('mongodb', createMongoDestroyAdapter)
registerTxAdapterFactry('postgresql', createPostgresTxAdapter, true) registerTxAdapterFactory('postgresql', createPostgresTxAdapter, true)
registerAdapterFactry('postgresql', createPostgresAdapter, true) registerAdapterFactory('postgresql', createPostgresAdapter, true)
registerDestroyFactry('postgresql', createPostgreeDestroyAdapter, true) registerDestroyFactory('postgresql', createPostgreeDestroyAdapter, true)
registerServerPlugins() registerServerPlugins()

View File

@ -210,21 +210,21 @@ const txAdapterFactories: Record<string, DbAdapterFactory> = {}
const adapterFactories: Record<string, DbAdapterFactory> = {} const adapterFactories: Record<string, DbAdapterFactory> = {}
const destroyFactories: Record<string, (url: string) => WorkspaceDestroyAdapter> = {} const destroyFactories: Record<string, (url: string) => WorkspaceDestroyAdapter> = {}
export function registerTxAdapterFactry (name: string, factory: DbAdapterFactory, useAsDefault: boolean = true): void { export function registerTxAdapterFactory (name: string, factory: DbAdapterFactory, useAsDefault: boolean = true): void {
txAdapterFactories[name] = factory txAdapterFactories[name] = factory
if (useAsDefault) { if (useAsDefault) {
txAdapterFactories[''] = factory txAdapterFactories[''] = factory
} }
} }
export function registerAdapterFactry (name: string, factory: DbAdapterFactory, useAsDefault: boolean = true): void { export function registerAdapterFactory (name: string, factory: DbAdapterFactory, useAsDefault: boolean = true): void {
adapterFactories[name] = factory adapterFactories[name] = factory
if (useAsDefault) { if (useAsDefault) {
adapterFactories[''] = factory adapterFactories[''] = factory
} }
} }
export function registerDestroyFactry ( export function registerDestroyFactory (
name: string, name: string,
factory: (url: string) => WorkspaceDestroyAdapter, factory: (url: string) => WorkspaceDestroyAdapter,
useAsDefault: boolean = true useAsDefault: boolean = true

View File

@ -21,11 +21,11 @@ import { SessionDataImpl, wrapPipeline, type Pipeline, type StorageAdapter } fro
import { import {
getServerPipeline, getServerPipeline,
getTxAdapterFactory, getTxAdapterFactory,
registerAdapterFactry, registerAdapterFactory,
registerDestroyFactry, registerDestroyFactory,
registerServerPlugins, registerServerPlugins,
registerStringLoaders, registerStringLoaders,
registerTxAdapterFactry registerTxAdapterFactory
} from '@hcengineering/server-pipeline' } from '@hcengineering/server-pipeline'
import { buildStorageFromConfig, storageConfigFromEnv } from '@hcengineering/server-storage' import { buildStorageFromConfig, storageConfigFromEnv } from '@hcengineering/server-storage'
import { generateToken } from '@hcengineering/server-token' import { generateToken } from '@hcengineering/server-token'
@ -82,13 +82,13 @@ export async function createWorkspace (
const hierarchy = new Hierarchy() const hierarchy = new Hierarchy()
const modelDb = new ModelDb(hierarchy) const modelDb = new ModelDb(hierarchy)
registerTxAdapterFactry('mongodb', createMongoTxAdapter) registerTxAdapterFactory('mongodb', createMongoTxAdapter)
registerAdapterFactry('mongodb', createMongoAdapter) registerAdapterFactory('mongodb', createMongoAdapter)
registerDestroyFactry('mongodb', createMongoDestroyAdapter) registerDestroyFactory('mongodb', createMongoDestroyAdapter)
registerTxAdapterFactry('postgresql', createPostgresTxAdapter, true) registerTxAdapterFactory('postgresql', createPostgresTxAdapter, true)
registerAdapterFactry('postgresql', createPostgresAdapter, true) registerAdapterFactory('postgresql', createPostgresAdapter, true)
registerDestroyFactry('postgresql', createPostgreeDestroyAdapter, true) registerDestroyFactory('postgresql', createPostgreeDestroyAdapter, true)
registerServerPlugins() registerServerPlugins()
registerStringLoaders() registerStringLoaders()
@ -173,13 +173,13 @@ export async function upgradeWorkspace (
): Promise<void> { ): Promise<void> {
const { dbUrl } = prepareTools([]) const { dbUrl } = prepareTools([])
let pipeline: Pipeline | undefined let pipeline: Pipeline | undefined
registerTxAdapterFactry('mongodb', createMongoTxAdapter) registerTxAdapterFactory('mongodb', createMongoTxAdapter)
registerAdapterFactry('mongodb', createMongoAdapter) registerAdapterFactory('mongodb', createMongoAdapter)
registerDestroyFactry('mongodb', createMongoDestroyAdapter) registerDestroyFactory('mongodb', createMongoDestroyAdapter)
registerTxAdapterFactry('postgresql', createPostgresTxAdapter, true) registerTxAdapterFactory('postgresql', createPostgresTxAdapter, true)
registerAdapterFactry('postgresql', createPostgresAdapter, true) registerAdapterFactory('postgresql', createPostgresAdapter, true)
registerDestroyFactry('postgresql', createPostgreeDestroyAdapter, true) registerDestroyFactory('postgresql', createPostgreeDestroyAdapter, true)
registerServerPlugins() registerServerPlugins()
registerStringLoaders() registerStringLoaders()

View File

@ -38,11 +38,11 @@ import { gzip } from 'zlib'
import { createPostgreeDestroyAdapter, createPostgresAdapter, createPostgresTxAdapter } from '@hcengineering/postgres' import { createPostgreeDestroyAdapter, createPostgresAdapter, createPostgresTxAdapter } from '@hcengineering/postgres'
import { import {
createServerPipeline, createServerPipeline,
registerAdapterFactry, registerAdapterFactory,
registerDestroyFactry, registerDestroyFactory,
registerServerPlugins, registerServerPlugins,
registerStringLoaders, registerStringLoaders,
registerTxAdapterFactry registerTxAdapterFactory
} from '@hcengineering/server-pipeline' } from '@hcengineering/server-pipeline'
import model from './model.json' import model from './model.json'
@ -65,9 +65,9 @@ export class Transactor extends DurableObject<Env> {
constructor (ctx: DurableObjectState, env: Env) { constructor (ctx: DurableObjectState, env: Env) {
super(ctx, env) super(ctx, env)
registerTxAdapterFactry('postgresql', createPostgresTxAdapter, true) registerTxAdapterFactory('postgresql', createPostgresTxAdapter, true)
registerAdapterFactry('postgresql', createPostgresAdapter, true) registerAdapterFactory('postgresql', createPostgresAdapter, true)
registerDestroyFactry('postgresql', createPostgreeDestroyAdapter, true) registerDestroyFactory('postgresql', createPostgreeDestroyAdapter, true)
registerStringLoaders() registerStringLoaders()
registerServerPlugins() registerServerPlugins()