Skip to content
File

Blob: src/worker/do/repo/debug/types.ts

typescript76 lines
1import type { Head, RepoLease } from "../repoState";
2import type { PackCatalogRow } from "../db/schema";
3 
4export type DebugPackState = {
5 key: string;
6 kind: PackCatalogRow["kind"];
7 state: PackCatalogRow["state"];
8 tier: number;
9 seqLo: number;
10 seqHi: number;
11 objectCount: number;
12 packSize: number;
13 indexSize: number;
14 hasIndex: boolean;
15 createdAt: number;
16 supersededBy: string | null;
17};
18 
19export type DebugCompactionState = {
20 running: boolean;
21 queued: boolean;
22 startedAt?: number;
23 wantedAt?: number;
24 lease?: RepoLease;
25};
26 
27export type DebugStateSnapshot = {
28 meta: { doId: string; prefix: string };
29 head?: Head;
30 refsCount: number;
31 refs: { name: string; oid: string }[];
32 packStats?: DebugPackState[];
33 activePacks: DebugPackState[];
34 supersededPacks: DebugPackState[];
35 packCatalogVersion: number;
36 receiveLease?: RepoLease;
37 compaction: DebugCompactionState;
38 looseSample: string[];
39 dbSizeBytes?: number;
40 looseR2SampleBytes?: number;
41 looseR2SampleCount?: number;
42 looseR2Truncated?: boolean;
43};
44 
45export type DebugCommitCheck = {
46 commit: { oid: string; parents: string[]; tree?: string };
47 presence: { hasLooseCommit: boolean; hasLooseTree: boolean; hasR2LooseTree: boolean };
48 membership: Record<string, { hasCommit: boolean; hasTree: boolean }>;
49};
50 
51export type DebugOidCheck = {
52 oid: string;
53 presence: {
54 hasLoose: boolean;
55 hasR2Loose: boolean;
56 };
57 inPacks: string[];
58};
59 
60export function toDebugPackState(row: PackCatalogRow): DebugPackState {
61 return {
62 key: row.packKey,
63 kind: row.kind,
64 state: row.state,
65 tier: row.tier,
66 seqLo: row.seqLo,
67 seqHi: row.seqHi,
68 objectCount: row.objectCount,
69 packSize: row.packBytes,
70 indexSize: row.idxBytes,
71 hasIndex: row.idxBytes > 0,
72 createdAt: row.createdAt,
73 supersededBy: row.supersededBy,
74 };
75}