UBERF-9521: Refactor session manager (#8560)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2025-04-16 20:50:58 +07:00
committed by GitHub
parent 93f40761b0
commit 0c9c985ab8
30 changed files with 897 additions and 750 deletions
+2 -2
View File
@@ -81,7 +81,7 @@ export function initStatisticsContext (
logFile?: string
logConsole?: boolean
factory?: () => MeasureMetricsContext
getUsers?: () => WorkspaceStatistics[]
getStats?: () => WorkspaceStatistics[]
statsUrl?: string
serviceName?: () => string
}
@@ -144,7 +144,7 @@ export function initStatisticsContext (
cpu: getCPUInfo(),
memory: getMemoryInfo(),
stats: metricsContext.metrics,
workspaces: ops?.getUsers?.()
workspaces: ops?.getStats?.()
}
const statData = JSON.stringify(data)
+12 -52
View File
@@ -46,12 +46,12 @@ import {
type SearchQuery,
type SearchResult,
type SessionData,
type SocialId,
type Space,
type Timestamp,
type Tx,
type TxFactory,
type TxResult,
type WorkspaceDataId,
type WorkspaceIds,
type WorkspaceUuid
} from '@hcengineering/core'
@@ -62,7 +62,7 @@ import type { Token } from '@hcengineering/server-token'
import { type Readable } from 'stream'
import type { DbAdapter, DomainHelper } from './adapter'
import type { StatisticsElement } from './stats'
import type { StatisticsElement, WorkspaceStatistics } from './stats'
import { type StorageAdapter } from './storage'
import { type PlatformQueue } from './queue'
@@ -239,7 +239,6 @@ export interface Pipeline {
export type PipelineFactory = (
ctx: MeasureContext,
ws: WorkspaceIds,
upgrade: boolean,
broadcast: BroadcastFunc,
branding: Branding | null,
communicationApi: CommunicationApi | null
@@ -559,7 +558,7 @@ export interface ClientSessionCtx {
* @public
*/
export interface Session {
workspace: Workspace
workspace: WorkspaceIds
createTime: number
// Session restore information
@@ -587,8 +586,11 @@ export interface Session {
// Client methods
ping: (ctx: ClientSessionCtx) => Promise<void>
getUser: () => AccountUuid
getUserSocialIds: () => PersonId[]
getSocialIds: () => SocialId[]
loadModel: (ctx: ClientSessionCtx, lastModelTx: Timestamp, hash?: string) => Promise<void>
loadModelRaw: (ctx: ClientSessionCtx, lastModelTx: Timestamp, hash?: string) => Promise<LoadModelResponse | Tx[]>
getRawAccount: () => Account
@@ -663,61 +665,25 @@ export function disableLogging (): void {
LOGGING_ENABLED = false
}
interface TickHandler {
ticks: number
operation: () => void
}
/**
* @public
*/
export interface Workspace {
context: MeasureContext
id: string
token: string // Account workspace update token.
pipeline: Promise<Pipeline> | Pipeline
communicationApi: Promise<CommunicationApi> | CommunicationApi
tickHash: number
tickHandlers: Map<string, TickHandler>
sessions: Map<string, { session: Session, socket: ConnectionSocket, tickHash: number }>
upgrade: boolean
closing?: Promise<void>
softShutdown: number
workspaceInitCompleted: boolean
workspaceName: string
workspaceUuid: WorkspaceUuid
workspaceUrl: string
workspaceDataId?: WorkspaceDataId
branding: Branding | null
}
export interface AddSessionActive {
session: Session
context: MeasureContext
workspaceId: WorkspaceUuid
}
export type AddSessionResponse =
| AddSessionActive
export type GetWorkspaceResponse =
| { upgrade: true, progress?: number }
| { error: any, terminate?: boolean, specialError?: 'archived' | 'migration' }
export type SessionFactory = (token: Token, workspace: Workspace, account: Account) => Session
export type AddSessionResponse = AddSessionActive | GetWorkspaceResponse
/**
* @public
*/
export interface SessionManager {
workspaces: Map<WorkspaceUuid, Workspace>
// workspaces: Map<WorkspaceUuid, Workspace>
sessions: Map<string, { session: Session, socket: ConnectionSocket }>
createSession: SessionFactory
addSession: (
ctx: MeasureContext,
ws: ConnectionSocket,
@@ -726,18 +692,10 @@ export interface SessionManager {
sessionId: string | undefined
) => Promise<AddSessionResponse>
broadcastAll: (workspace: Workspace, tx: Tx[], targets?: string[]) => void
broadcastAll: (workspace: WorkspaceUuid, tx: Tx[], targets?: string[]) => void
close: (ctx: MeasureContext, ws: ConnectionSocket, workspaceId: WorkspaceUuid) => Promise<void>
closeAll: (
wsId: WorkspaceUuid,
workspace: Workspace,
code: number,
reason: 'upgrade' | 'shutdown',
ignoreSocket?: ConnectionSocket
) => Promise<void>
forceClose: (wsId: WorkspaceUuid, ignoreSocket?: ConnectionSocket) => Promise<void>
closeWorkspaces: (ctx: MeasureContext) => Promise<void>
@@ -773,6 +731,8 @@ export interface SessionManager {
service: Session,
ws: ConnectionSocket
) => ClientSessionCtx
getStatistics: () => WorkspaceStatistics[]
}
export const pingConst = 'ping'
-3
View File
@@ -7,7 +7,6 @@ import core, {
type Account,
type AccountUuid,
type BackupClient,
type Branding,
type BrandingMap,
type BulkUpdateEvent,
type Class,
@@ -166,7 +165,6 @@ export class SessionDataImpl implements SessionData {
readonly admin: boolean | undefined,
_broadcast: SessionData['broadcast'] | undefined,
readonly workspace: WorkspaceIds,
readonly branding: Branding | null,
readonly isAsyncContext: boolean,
_removedMap: Map<Ref<Doc>, Doc> | undefined,
_contextCache: Map<string, any> | undefined,
@@ -244,7 +242,6 @@ export function wrapPipeline (
true,
{ targets: {}, txes: [] },
wsIds,
null,
true,
undefined,
undefined,